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

keradus / PHP-CS-Fixer / 16253811376

13 Jul 2025 09:50PM UTC coverage: 94.794% (+0.001%) from 94.793%
16253811376

push

github

web-flow
Merge branch 'master' into sf8

2272 of 2348 new or added lines in 338 files covered. (96.76%)

7 existing lines in 5 files now uncovered.

28259 of 29811 relevant lines covered (94.79%)

45.39 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
final class ToolInfo implements ToolInfoInterface
27
{
28
    public const COMPOSER_PACKAGE_NAME = 'friendsofphp/php-cs-fixer';
29

30
    public const COMPOSER_LEGACY_PACKAGE_NAME = 'fabpot/php-cs-fixer';
31

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

37
    private ?bool $isInstalledByComposer = null;
38

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

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

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

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

55
                    break;
×
56
                }
57
            }
58
        }
59

60
        return $this->composerInstallationDetails;
×
61
    }
62

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

67
        $versionSuffix = '';
×
68

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

73
        return $package['version'].$versionSuffix;
×
74
    }
75

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

82
        return Application::VERSION;
1✔
83
    }
84

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

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

96
        return $this->isInstalledByComposer;
3✔
97
    }
98

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

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

116
    private function getComposerInstalledFile(): string
117
    {
118
        return __DIR__.'/../../../composer/installed.json';
3✔
119
    }
120
}
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