• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

keradus / PHP-CS-Fixer / 17279562118

27 Aug 2025 09:47PM UTC coverage: 94.693%. Remained the same
17279562118

push

github

keradus
CS

28316 of 29903 relevant lines covered (94.69%)

45.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/ToolInfo.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
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 PhpCsFixer;
16

17
use PhpCsFixer\Console\Application;
18

19
/**
20
 * Obtain information about using version of tool.
21
 *
22
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
23
 *
24
 * @internal
25
 *
26
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
27
 */
28
final class ToolInfo implements ToolInfoInterface
29
{
30
    public const COMPOSER_PACKAGE_NAME = 'friendsofphp/php-cs-fixer';
31

32
    public const COMPOSER_LEGACY_PACKAGE_NAME = 'fabpot/php-cs-fixer';
33

34
    /**
35
     * @var null|array{name: string, version: string, dist: array{reference?: string}}
36
     */
37
    private ?array $composerInstallationDetails = null;
38

39
    private ?bool $isInstalledByComposer = null;
40

41
    public function getComposerInstallationDetails(): array
42
    {
43
        if (!$this->isInstalledByComposer()) {
1✔
44
            throw new \LogicException('Cannot get composer version for tool not installed by composer.');
1✔
45
        }
46

47
        if (null === $this->composerInstallationDetails) {
×
48
            $composerInstalled = json_decode(file_get_contents($this->getComposerInstalledFile()), true, 512, \JSON_THROW_ON_ERROR);
×
49

50
            /** @var list<array{name: string, version: string, dist: array{reference?: string}}> $packages */
51
            $packages = $composerInstalled['packages'] ?? $composerInstalled;
×
52

53
            foreach ($packages as $package) {
×
54
                if (\in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) {
×
55
                    $this->composerInstallationDetails = $package;
×
56

57
                    break;
×
58
                }
59
            }
60
        }
61

62
        return $this->composerInstallationDetails;
×
63
    }
64

65
    public function getComposerVersion(): string
66
    {
67
        $package = $this->getComposerInstallationDetails();
1✔
68

69
        $versionSuffix = '';
×
70

71
        if (isset($package['dist']['reference'])) {
×
72
            $versionSuffix = '#'.$package['dist']['reference'];
×
73
        }
74

75
        return $package['version'].$versionSuffix;
×
76
    }
77

78
    public function getVersion(): string
79
    {
80
        if ($this->isInstalledByComposer()) {
1✔
81
            return Application::VERSION.':'.$this->getComposerVersion();
×
82
        }
83

84
        return Application::VERSION;
1✔
85
    }
86

87
    public function isInstalledAsPhar(): bool
88
    {
89
        return str_starts_with(__DIR__, 'phar://');
4✔
90
    }
91

92
    public function isInstalledByComposer(): bool
93
    {
94
        if (null === $this->isInstalledByComposer) {
3✔
95
            $this->isInstalledByComposer = !$this->isInstalledAsPhar() && file_exists($this->getComposerInstalledFile());
3✔
96
        }
97

98
        return $this->isInstalledByComposer;
3✔
99
    }
100

101
    /**
102
     * Determines if the tool is run inside our pre-built Docker image.
103
     * The `/fixer/` path comes from our Dockerfile, tool is installed there and added to global PATH via symlinked binary.
104
     */
105
    public function isRunInsideDocker(): bool
106
    {
107
        return str_starts_with(__FILE__, '/fixer/') && is_file('/.dockerenv');
×
108
    }
109

110
    public function getPharDownloadUri(string $version): string
111
    {
112
        return \sprintf(
1✔
113
            'https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/%s/php-cs-fixer.phar',
1✔
114
            $version
1✔
115
        );
1✔
116
    }
117

118
    private function getComposerInstalledFile(): string
119
    {
120
        return __DIR__.'/../../../composer/installed.json';
3✔
121
    }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc