| 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 | class PackageSource implements \Vaimo\ComposerPatches\Interfaces\PatchSourceListInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var array |
||
| 15 | */ |
||
| 16 | private $packages; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var \Vaimo\ComposerPatches\Utils\FilterUtils |
||
| 20 | */ |
||
| 21 | private $filterUtils; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param array $packages |
||
| 25 | */ |
||
| 26 | public function __construct( |
||
| 27 | array $packages = array() |
||
| 28 | ) { |
||
| 29 | $this->packages = $packages; |
||
| 30 | |||
| 31 | $this->filterUtils = new \Vaimo\ComposerPatches\Utils\FilterUtils(); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function getItems(WritableRepositoryInterface $repository) |
||
| 35 | { |
||
| 36 | $packages = $repository->getPackages(); |
||
| 37 | |||
| 38 | if (empty($this->packages)) { |
||
| 39 | return $packages; |
||
|
0 ignored issues
–
show
|
|||
| 40 | } |
||
| 41 | |||
| 42 | $filter = $this->filterUtils->composeRegex($this->packages, '/'); |
||
| 43 | |||
| 44 | return array_filter( |
||
| 45 | $packages, |
||
| 46 | function (PackageInterface $package) use ($filter) { |
||
| 47 | return preg_match($filter, $package->getName()); |
||
| 48 | } |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: