コード例 #1
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function equals(ItemInterface $item)
 {
     // It is exactly the same item.
     if ($this === $item) {
         return true;
     }
     // The actions are not equal.
     if ($this->getAction() !== $item->getAction()) {
         return false;
     }
     // One has a parent ID, the other not.
     if ($this->getParentId() && !$item->getParentId() || !$this->getParentId() && $item->getParentId()) {
         return false;
     }
     // The parent IDs are not equal.
     if ($this->getParentId() && !$this->getParentId()->equals($item->getParentId())) {
         return false;
     }
     // One has a model ID, the other not.
     if ($this->getModelId() && !$item->getModelId() || !$this->getModelId() && $item->getModelId()) {
         return false;
     }
     // Both have no model id and the data provider is different.
     if (!($this->getModelId() || $item->getModelId())) {
         return $this->getDataProviderName() === $item->getDataProviderName();
     }
     // The model IDs are not equal
     return $this->getModelId()->equals($item->getModelId());
 }