| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright © Vaimo Group. All rights reserved. |
||
| 4 | * See LICENSE_VAIMO.txt for license details. |
||
| 5 | */ |
||
| 6 | namespace Vaimo\ComposerPatches\Sources; |
||
| 7 | |||
| 8 | use Composer\Repository\WritableRepositoryInterface; |
||
| 9 | use Composer\Package\PackageInterface; |
||
| 10 | |||
| 11 | use Vaimo\ComposerPatches\Composer\Constants as ComposerConstants; |
||
| 12 | |||
| 13 | class VendorSource implements \Vaimo\ComposerPatches\Interfaces\PatchSourceListInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | private $vendors; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param array $vendors |
||
| 22 | */ |
||
| 23 | public function __construct( |
||
| 24 | array $vendors = array() |
||
| 25 | ) { |
||
| 26 | $this->vendors = $vendors; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getItems(WritableRepositoryInterface $repository) |
||
| 30 | { |
||
| 31 | $packages = $repository->getPackages(); |
||
| 32 | |||
| 33 | if (empty($this->vendors)) { |
||
| 34 | return $packages; |
||
|
0 ignored issues
–
show
|
|||
| 35 | } |
||
| 36 | |||
| 37 | $allowedVendors = array_fill_keys($this->vendors, true); |
||
| 38 | return array_filter( |
||
| 39 | $packages, |
||
| 40 | function (PackageInterface $package) use ($allowedVendors) { |
||
| 41 | $vendorName = strtok($package->getName(), ComposerConstants::PACKAGE_SEPARATOR); |
||
| 42 | |||
| 43 | return isset($allowedVendors[$vendorName]); |
||
| 44 | } |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: