1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | /* |
||||
6 | * This file is part of the box project. |
||||
7 | * |
||||
8 | * (c) Kevin Herrera <[email protected]> |
||||
9 | * Théo Fidry <[email protected]> |
||||
10 | * |
||||
11 | * This source file is subject to the MIT license that is bundled |
||||
12 | * with this source code in the file LICENSE. |
||||
13 | */ |
||||
14 | |||||
15 | namespace KevinGH\Box\Phar\Differ; |
||||
16 | |||||
17 | use Fidry\Console\IO; |
||||
0 ignored issues
–
show
|
|||||
18 | use KevinGH\Box\Console\PharInfoRenderer; |
||||
19 | use KevinGH\Box\Phar\PharInfo; |
||||
20 | use SplFileInfo; |
||||
21 | use Symfony\Component\Console\Output\BufferedOutput; |
||||
22 | use Symfony\Component\Finder\Finder; |
||||
23 | use function array_diff; |
||||
24 | use function array_map; |
||||
25 | use function array_sum; |
||||
26 | use function count; |
||||
27 | use function explode; |
||||
28 | use function iterator_to_array; |
||||
29 | use function sprintf; |
||||
30 | use function str_replace; |
||||
31 | |||||
32 | final class FilenameDiffer implements Differ |
||||
33 | { |
||||
34 | public function diff( |
||||
35 | PharInfo $pharInfoA, |
||||
36 | PharInfo $pharInfoB, |
||||
37 | IO $io, |
||||
38 | ): void { |
||||
39 | $pharAFiles = self::collectFiles($pharInfoA); |
||||
40 | $pharBFiles = self::collectFiles($pharInfoB); |
||||
41 | |||||
42 | $diffResult = [ |
||||
43 | array_diff($pharAFiles, $pharBFiles), |
||||
44 | array_diff($pharBFiles, $pharAFiles), |
||||
45 | ]; |
||||
46 | $diffCount = array_sum(array_map('count', $diffResult)); |
||||
47 | |||||
48 | if (0 === $diffCount) { |
||||
49 | $io->writeln(Differ::NO_DIFF_MESSAGE); |
||||
50 | |||||
51 | return; |
||||
52 | } |
||||
53 | |||||
54 | self::printDiff( |
||||
55 | $pharInfoA, |
||||
56 | $pharInfoB, |
||||
57 | $diffResult[0], |
||||
58 | $diffResult[1], |
||||
59 | $io, |
||||
60 | ); |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * @param list<non-empty-string> $filesInANotInB |
||||
65 | * @param list<non-empty-string> $filesInBNotInA |
||||
0 ignored issues
–
show
The type
KevinGH\Box\Phar\Differ\list was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
66 | */ |
||||
67 | private static function printDiff( |
||||
68 | PharInfo $pharInfoA, |
||||
69 | PharInfo $pharInfoB, |
||||
70 | array $filesInANotInB, |
||||
71 | array $filesInBNotInA, |
||||
72 | IO $io, |
||||
73 | ): void { |
||||
74 | $io->writeln(sprintf( |
||||
75 | '--- Files present in "%s" but not in "%s"', |
||||
76 | $pharInfoA->getFileName(), |
||||
77 | $pharInfoB->getFileName(), |
||||
78 | )); |
||||
79 | $io->writeln(sprintf( |
||||
80 | '+++ Files present in "%s" but not in "%s"', |
||||
81 | $pharInfoB->getFileName(), |
||||
82 | $pharInfoA->getFileName(), |
||||
83 | )); |
||||
84 | |||||
85 | $io->newLine(); |
||||
86 | |||||
87 | self::renderPaths('-', $pharInfoA, $filesInANotInB, $io); |
||||
88 | $io->newLine(); |
||||
89 | self::renderPaths('+', $pharInfoB, $filesInBNotInA, $io); |
||||
90 | |||||
91 | $io->newLine(2); |
||||
92 | |||||
93 | $io->error( |
||||
94 | sprintf( |
||||
95 | '%d file(s) difference', |
||||
96 | count($filesInANotInB) + count($filesInBNotInA), |
||||
97 | ), |
||||
98 | ); |
||||
99 | } |
||||
100 | |||||
101 | /** |
||||
102 | * @param list<non-empty-string> $paths |
||||
103 | */ |
||||
104 | private static function renderPaths(string $symbol, PharInfo $pharInfo, array $paths, IO $io): void |
||||
0 ignored issues
–
show
The parameter
$paths is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
105 | { |
||||
106 | $bufferedOutput = new BufferedOutput( |
||||
107 | $io->getVerbosity(), |
||||
108 | $io->isDecorated(), |
||||
109 | $io->getOutput()->getFormatter(), |
||||
110 | ); |
||||
111 | |||||
112 | PharInfoRenderer::renderContent( |
||||
113 | $bufferedOutput, |
||||
114 | $pharInfo, |
||||
115 | false, |
||||
116 | false, |
||||
117 | ); |
||||
118 | |||||
119 | $lines = array_map( |
||||
120 | static fn (string $line) => '' === $line ? '' : $symbol.' '.$line, |
||||
121 | explode( |
||||
122 | PHP_EOL, |
||||
123 | $bufferedOutput->fetch(), |
||||
124 | ), |
||||
125 | ); |
||||
126 | |||||
127 | $io->write($lines); |
||||
128 | } |
||||
129 | |||||
130 | /** |
||||
131 | * @return string[] |
||||
132 | */ |
||||
133 | private static function collectFiles(PharInfo $pharInfo): array |
||||
134 | { |
||||
135 | $basePath = $pharInfo->getTmp().DIRECTORY_SEPARATOR; |
||||
136 | |||||
137 | return array_map( |
||||
138 | static fn (SplFileInfo $fileInfo): string => str_replace($basePath, '', $fileInfo->getRealPath()), |
||||
139 | iterator_to_array( |
||||
140 | Finder::create() |
||||
141 | ->files() |
||||
142 | ->in($basePath) |
||||
143 | ->ignoreDotFiles(false), |
||||
144 | false, |
||||
145 | ), |
||||
146 | ); |
||||
147 | } |
||||
148 | } |
||||
149 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths