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.
Completed
Push — master ( 850dec...5e08ba )
by Cees-Jan
10:31
created

Installer.php$0 ➔ doWrite()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
<?php declare(strict_types = 1);
2
3
namespace ApiClients\Tools\Installer;
4
5
use Composer\Factory;
6
use Composer\IO\IOInterface;
7
use Composer\Script\Event;
8
use InvalidArgumentException;
9
use PackageVersions\Versions;
10
use Symfony\Component\Console\Application;
11
use Symfony\Component\Console\Input\ArgvInput;
12
use Symfony\Component\Console\Output\Output;
13
use Symfony\Component\Yaml\Yaml;
14
use Throwable;
15
16
final class Installer
17
{
18
    const TITLE = 'PHP API Clients skeleton installer';
19
20
    public static function postCreateProject(Event $composerEvent)
21
    {
22
        require_once str_replace(
23
            'composer.json',
24
            'vendor/autoload.php',
25
            Factory::getComposerFile()
26
        );
27
28
        try {
29
            $path = str_replace(
30
                'composer.json',
31
                'installer.yml',
32
                Factory::getComposerFile()
33
            );
34
35
            if (!file_exists($path)) {
36
                throw new InvalidArgumentException('Missing installer configuration file');
37
            }
38
39
            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...
40
        } catch (Throwable $throwable) {
41
            echo get_class($throwable), ' thrown with message: ', $throwable->getMessage(), PHP_EOL;
42
            echo $throwable->getTraceAsString(), PHP_EOL;
43
            exit(1);
44
        }
45
    }
46
47
    private static function install(string $fileName, IOInterface $io)
48
    {
49
        $yaml = Yaml::parse(
50
            file_get_contents(
51
                $fileName
52
            )
53
        );
54
        $app = new Application(
55
            self::TITLE,
56
            Versions::getVersion('api-clients/installer')
57
        );
58
        $app->add((new Install(Install::COMMAND))->setYaml($yaml));
59
60
        $consoleOutput = new class($io) extends Output
61
        {
62
            /**
63
             * @var IOInterface
64
             */
65
            private $io;
66
67
            /**
68
             *  constructor.
69
             * @param IOInterface $io
70
             */
71
            public function __construct(IOInterface $io)
72
            {
73
74
                parent::__construct();
75
                $this->io = $io;
76
            }
77
78
            protected function doWrite($message, $newline)
79
            {
80
                $this->io->write($message);
81
            }
82
        };
83
84
        $app->find(Install::COMMAND)->run(new ArgvInput([]), $consoleOutput);
85
    }
86
}
87