1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright MediaCT. All rights reserved. |
4
|
|
|
* https://www.mediact.nl |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Mediact\DependencyGuard\Violation\Filter; |
8
|
|
|
|
9
|
|
|
use Composer\Package\PackageInterface; |
10
|
|
|
use Composer\Repository\CompositeRepository; |
11
|
|
|
use Composer\Repository\RepositoryInterface; |
12
|
|
|
use Mediact\DependencyGuard\Candidate\Candidate; |
13
|
|
|
use Mediact\DependencyGuard\Composer\Repository\DependentsResolver; |
14
|
|
|
use Mediact\DependencyGuard\Violation\Violation; |
15
|
|
|
use Mediact\DependencyGuard\Violation\ViolationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @deprecated The conceptual difference between dependents in Composer and |
19
|
|
|
* DependencyGuard is too great to rely on the output of a dependents resolver. |
20
|
|
|
*/ |
21
|
|
|
class DependencyFilter implements ViolationFilterInterface |
22
|
|
|
{ |
23
|
|
|
/** @var ViolationFilterInterface */ |
24
|
|
|
private $filter; |
25
|
|
|
|
26
|
|
|
/** @var CompositeRepository */ |
27
|
|
|
private $repository; |
28
|
|
|
|
29
|
|
|
/** @var DependentsResolver */ |
30
|
|
|
private $dependentsResolver; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* @param RepositoryInterface $repository |
36
|
|
|
* @param ViolationFilterInterface $filter |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct( |
39
|
|
|
RepositoryInterface $repository, |
40
|
|
|
ViolationFilterInterface $filter |
41
|
|
|
) { |
42
|
1 |
|
$this->filter = $filter; |
43
|
1 |
|
$this->repository = new CompositeRepository([$repository]); |
44
|
1 |
|
$this->dependentsResolver = new DependentsResolver($repository); |
|
|
|
|
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Filter violations. |
49
|
|
|
* |
50
|
|
|
* @param ViolationInterface $violation |
51
|
|
|
* |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
5 |
|
public function __invoke(ViolationInterface $violation): bool |
55
|
|
|
{ |
56
|
5 |
|
return array_reduce( |
57
|
5 |
|
array_map( |
58
|
|
|
function ( |
59
|
|
|
array $dependent |
60
|
|
|
) use ($violation): ViolationInterface { |
61
|
|
|
/** @var PackageInterface $package */ |
62
|
2 |
|
[$package] = $dependent; |
63
|
2 |
|
return new Violation( |
64
|
2 |
|
sprintf( |
65
|
2 |
|
'Package "%s" provides violating package "%s".', |
66
|
2 |
|
$package->getName(), |
67
|
2 |
|
$violation->getPackage()->getName() |
68
|
|
|
), |
69
|
2 |
|
new Candidate( |
70
|
2 |
|
$package, |
71
|
2 |
|
$violation->getSymbols() |
72
|
|
|
) |
73
|
|
|
); |
74
|
5 |
|
}, |
75
|
5 |
|
$this->dependentsResolver->resolve( |
76
|
5 |
|
$violation->getPackage()->getName() |
77
|
|
|
) |
78
|
|
|
), |
79
|
|
|
function (bool $carry, ViolationInterface $violation): bool { |
80
|
2 |
|
return $carry || $this->filter->__invoke($violation); |
81
|
5 |
|
}, |
82
|
5 |
|
false |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|