GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

anonymous//src/Installer.php$0   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 21
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace ApiClients\Tools\Installer;
4
5
use Closure;
6
use Composer\Factory;
7
use Composer\IO\ConsoleIO;
8
use Composer\IO\IOInterface;
9
use Composer\Script\Event;
10
use InvalidArgumentException;
11
use Jean85\PrettyVersions;
12
use Symfony\Component\Console\Application;
13
use Symfony\Component\Console\Input\ArgvInput;
14
use Symfony\Component\Console\Output\Output;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Yaml\Yaml;
17
use Throwable;
18
19
final class Installer
20
{
21
    const TITLE = 'PHP API Clients skeleton installer';
22
23
    public static function postCreateProject(Event $composerEvent)
24
    {
25
        require_once str_replace(
26
            'composer.json',
27
            'vendor/autoload.php',
28
            Factory::getComposerFile()
29
        );
30
31
        try {
32
            $path = str_replace(
33
                'composer.json',
34
                'installer.yml',
35
                Factory::getComposerFile()
36
            );
37
38
            if (!file_exists($path)) {
39
                throw new InvalidArgumentException('Missing installer configuration file');
40
            }
41
42
            static::install($path, $composerEvent->getIO());
0 ignored issues
show
Comprehensibility introduced by
Since ApiClients\Tools\Installer\Installer is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
43
        } catch (Throwable $throwable) {
44
            echo get_class($throwable), ' thrown with message: ', $throwable->getMessage(), PHP_EOL;
45
            echo $throwable->getTraceAsString(), PHP_EOL;
46
            exit(1);
47
        }
48
    }
49
50
    private static function install(string $fileName, IOInterface $io)
51
    {
52
        $yaml = Yaml::parse(
53
            file_get_contents(
54
                $fileName
55
            )
56
        );
57
        $app = new Application(
58
            self::TITLE,
59
            PrettyVersions::getVersion('api-clients/installer')->getShortVersion()
60
        );
61
        $app->add((new Install(Install::COMMAND))->setYaml($yaml));
62
        $app->find(Install::COMMAND)->run(new ArgvInput([]), self::getOutput($io));
63
    }
64
65
    private static function getOutput(IOInterface $io): OutputInterface
66
    {
67
        if ($io instanceof ConsoleIO) {
68
            return Closure::bind(function (ConsoleIO $consoleIO): OutputInterface {
69
                return $consoleIO->output;
0 ignored issues
show
Bug introduced by
The property output cannot be accessed from this context as it is declared protected in class Composer\IO\ConsoleIO.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
70
            }, null, ConsoleIO::class)($io);
71
        }
72
73
        return new class($io) extends Output {
74
            /**
75
             * @var IOInterface
76
             */
77
            private $io;
78
79
            /**
80
             *  constructor.
81
             * @param IOInterface $io
82
             */
83
            public function __construct(IOInterface $io)
84
            {
85
                parent::__construct();
86
                $this->io = $io;
87
            }
88
89
            protected function doWrite($message, $newline)
90
            {
91
                $this->io->write($message, $newline);
92
            }
93
        };
94
    }
95
}
96