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 ( 75651d...c2ec74 )
by Cees-Jan
10:47
created

ResourcesYml::operate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 3
1
<?php declare(strict_types = 1);
2
3
namespace ApiClients\Tools\Installer\Operation;
4
5
use ApiClients\Tools\Installer\Filesystem;
6
use ApiClients\Tools\Installer\OperationInterface;
7
use Composer\Factory;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
use Symfony\Component\Yaml\Yaml;
10
11
final class ResourcesYml implements OperationInterface
12
{
13
    /**
14
     * @var Filesystem
15
     */
16
    private $filesystem;
17
18
    /**
19
     * @internal
20
     * @param Filesystem $filesystem
21
     */
22
    public function __construct(Filesystem $filesystem)
23
    {
24
        $this->filesystem = $filesystem;
25
    }
26
27
    /**
28
     * @return OperationInterface
29
     */
30
    public static function create(): OperationInterface
31
    {
32
        return new self(new Filesystem());
33
    }
34
35
    /**
36
     * @param array        $replacements
37
     * @param array        $environment
38
     * @param SymfonyStyle $style
39
     */
40
    public function operate(array $replacements, array $environment, SymfonyStyle $style)
41
    {
42
        $path = str_replace(
43
            'composer.json',
44
            'resources.yml',
45
            Factory::getComposerFile()
46
        );
47
        $style->section('Updating resources.yml');
48
        $style->text('Reading resources.yml');
49
        $resourcesYml = Yaml::parse($this->filesystem->read($path));
50
51
        $style->text('Replacing api_settings');
52
        $resourcesYml['api_settings'] = $replacements['ns_vendor'] . '\\' . $replacements['ns_project'] . '\\ApiSettings';
53
54
        $style->text('Replacing src.namespace');
55
        $resourcesYml['src']['namespace'] = $replacements['ns_vendor'] . '\\' . $replacements['ns_project'] . '\\Resource';
56
57
        $style->text('Replacing tests.namespace');
58
        $resourcesYml['tests']['namespace'] = $replacements['ns_tests_vendor'] . '\\' . $replacements['ns_project'] . '\\Resource';
59
60
        $style->text('Writing updated resources.yml');
61
        $this->filesystem->write($path, Yaml::dump($resourcesYml));
62
        $style->success('Updated resources.yml');
63
    }
64
}
65