Passed
Push — trunk ( d5f833...1348b1 )
by Christian
30:13 queued 20:11
created

GenerateAdministrationGitAttributes::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Administration\Command;
4
5
use Shopware\Core\Framework\Log\Package;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Finder\Finder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
#[AsCommand(
13
    name: 'administration:generate-git-attributes',
14
    description: 'Generates the .gitattributes file for the administration.',
15
)]
16
#[Package('admin')]
17
class GenerateAdministrationGitAttributes extends Command
18
{
19
    /**
20
     * @internal
21
     */
22
    public function __construct(
23
        private readonly string $projectDir
24
    ) {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function configure(): void
32
    {
33
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $output->writeln('Generating .gitattributes file for the administration...');
38
39
        $attributeFile = $this->projectDir . '/src/Administration/.gitattributes';
40
        $staticContent = <<<EOT
41
# General ignore rules
42
/Test export-ignore
43
/Resources/ide-twig.json export-ignore
44
/Resources/app/administration/build export-ignore
45
/Resources/app/administration/test export-ignore
46
/Resources/app/administration/src/meta export-ignore
47
/Resources/app/administration/src/scripts/create-spec-file export-ignore
48
49
# Ignore all spec files
50
51
EOT;
52
53
        \file_put_contents($attributeFile, $staticContent);
54
55
        $finder = new Finder();
56
        $files = $finder->in($this->projectDir . '/src/Administration/Resources/app/administration')
57
            ->notPath('node_modules')
58
            ->name('/.*\.spec\.(js|ts)/')
59
            ->files()
60
            ->getIterator();
61
62
        $files = \iterator_to_array($files);
63
        \sort($files);
64
65
        $handler = \fopen($attributeFile, 'ab');
66
        if (!$handler) {
0 ignored issues
show
introduced by
$handler is of type resource, thus it always evaluated to false.
Loading history...
67
            throw new \RuntimeException('Could not open file for writing: ' . $attributeFile);
68
        }
69
70
        foreach ($files as $file) {
71
            fwrite($handler, '/Resources/app/administration/' . $file->getRelativePathname() . ' export-ignore' . \PHP_EOL);
72
        }
73
74
        fclose($handler);
75
76
        $output->writeln('Done!');
77
78
        return 0;
79
    }
80
}
81