Issues (224)

src/Phar/Differ/GitDiffer.php (2 issues)

Labels
Severity
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
The type Fidry\Console\IO 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use KevinGH\Box\Console\Command\Extract;
19
use KevinGH\Box\Phar\PharInfo;
20
use function array_filter;
21
use function explode;
22
use function implode;
23
use function sprintf;
24
use function str_starts_with;
25
26
final class GitDiffer implements Differ
27
{
28
    public function diff(PharInfo $pharInfoA, PharInfo $pharInfoB, IO $io): void
29
    {
30
        $gitDiff = ProcessCommandBasedDiffer::getDiff(
0 ignored issues
show
The type KevinGH\Box\Phar\Differ\ProcessCommandBasedDiffer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
            $pharInfoA,
32
            $pharInfoB,
33
            'git diff --no-index',
34
        );
35
36
        if (null === $gitDiff) {
37
            $io->writeln(Differ::NO_DIFF_MESSAGE);
38
39
            return;
40
        }
41
42
        $separator = 'diff --git ';
43
44
        $diffLines = explode(
45
            $separator,
46
            $gitDiff,
47
        );
48
49
        $pharMetaLine = sprintf(
50
            'a%2$s/%1$s b%3$s/%1$s',
51
            Extract::PHAR_META_PATH,
52
            $pharInfoA->getFileName(),
53
            $pharInfoB->getFileName(),
54
        );
55
56
        $filteredLines = array_filter(
57
            $diffLines,
58
            static fn (string $line) => !str_starts_with($line, $pharMetaLine)
59
        );
60
61
        $filteredDiff = implode($separator, $filteredLines);
62
63
        $io->writeln('' === $filteredDiff ? Differ::NO_DIFF_MESSAGE : $filteredDiff);
64
    }
65
}
66