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 ( 89ac6f...2b2bce )
by Cees-Jan
07:00
created

Installer::getOutput()   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 30
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 12
nc 2
nop 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Installer.php$0 ➔ __construct() 0 5 1
A Installer.php$0 ➔ doWrite() 0 4 1
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 PackageVersions\Versions;
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
            Versions::getVersion('api-clients/installer')
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->ouput;
0 ignored issues
show
Bug introduced by
The property ouput does not seem to exist. Did you mean output?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

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