| Total Complexity | 8 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | trait ProductsAwareTrait |
||
| 12 | { |
||
| 13 | /** @var Collection|BrandAwareInterface[]|ProductInterface[] */ |
||
| 14 | protected $products; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * {@inheritdoc} |
||
| 18 | */ |
||
| 19 | public function initializeProductsCollection(): void |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritdoc} |
||
| 26 | */ |
||
| 27 | public function hasProducts(): bool |
||
| 28 | { |
||
| 29 | return $this->products->count() > 0; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | public function getProducts(): Collection |
||
| 36 | { |
||
| 37 | return $this->products; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | public function hasProduct(BrandAwareInterface $product): bool |
||
| 44 | { |
||
| 45 | return $this->products->contains($product); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function addProduct(BrandAwareInterface $product): void |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | public function removeProduct(BrandAwareInterface $product): void |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: