Issues (3)

src/Patcher/FileTemplatesPatcher.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Copyright MediaCT. All rights reserved.
5
 * https://www.mediact.nl
6
 */
7
8
declare(strict_types=1);
9
10
namespace Mediact\CodingStandard\PhpStorm\Patcher;
11
12
use Mediact\CodingStandard\PhpStorm\EnvironmentInterface;
13
use Mediact\CodingStandard\PhpStorm\FilesystemInterface;
14
use Mediact\CodingStandard\PhpStorm\XmlAccessorInterface;
15
16
class FileTemplatesPatcher implements ConfigPatcherInterface
17
{
18
    use CopyFilesTrait;
19
20
    /**
21
     * @var XmlAccessorInterface
22
     */
23
    private $xmlAccessor;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param XmlAccessorInterface $xmlAccessor
29
     */
30 1
    public function __construct(XmlAccessorInterface $xmlAccessor)
31
    {
32 1
        $this->xmlAccessor = $xmlAccessor;
33 1
    }
34
35
    /**
36
     * Patch the config.
37
     *
38
     * @param EnvironmentInterface $environment
39
     *
40
     * @return void
41
     */
42 1
    public function patch(
43
        EnvironmentInterface $environment
44
    ): void {
45 1
        $this->copyDirectory(
46 1
            $environment->getDefaultsFilesystem(),
47 1
            $environment->getIdeConfigFilesystem(),
48 1
            'fileTemplates'
49
        );
50
51 1
        $this->patchWorkspaceConfig(
52 1
            $environment->getIdeConfigFilesystem()
53
        );
54 1
    }
55
56
    /**
57
     * Patch the workspace config.
58
     *
59
     * @param FilesystemInterface $ideConfigFs
60
     *
61
     * @return void
62
     */
63 2
    private function patchWorkspaceConfig(
64
        FilesystemInterface $ideConfigFs
65
    ): void {
66 2
        if (!$ideConfigFs->has('workspace.xml')) {
67 1
            return;
68
        }
69
70 1
        $xml = simplexml_load_string(
71 1
            $ideConfigFs->read('workspace.xml')
72
        );
73
74 1
        $node = $this->xmlAccessor->getDescendant(
75 1
            $xml,
76
            [
77 1
                ['component', ['name' => 'FileTemplateManagerImpl']],
78
                ['option', ['name' => 'SCHEME']]
79
            ]
80
        );
81
82 1
        $this->xmlAccessor->setAttributes(
83 1
            $node,
84 1
            ['value' => 'Project']
85
        );
86
87 1
        $ideConfigFs->put('workspace.xml', $xml->asXML());
0 ignored issues
show
It seems like $xml->asXML() can also be of type true; however, parameter $contents of Mediact\CodingStandard\P...esystemInterface::put() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $ideConfigFs->put('workspace.xml', /** @scrutinizer ignore-type */ $xml->asXML());
Loading history...
88 1
    }
89
}
90