Passed
Push — trunk ( c9d12c...17fc57 )
by Christian
15:14 queued 14s
created

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Administration\Command;
4
5
use Shopware\Core\Framework\Bundle;
6
use Shopware\Core\Framework\Log\Package;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
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...
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
use Symfony\Component\Filesystem\Filesystem;
13
use Symfony\Component\HttpKernel\KernelInterface;
14
15
#[AsCommand(
16
    name: 'administration:delete-extension-local-public-files',
17
    description: 'Deletes all files in the local public folder of the extension. This command should run after assets:install so the assets are available in the public folder.',
18
)]
19
#[Package('admin')]
20
class DeleteExtensionLocalPublicFilesCommand extends Command
21
{
22
    /**
23
     * @internal
24
     */
25
    public function __construct(private readonly KernelInterface $kernel)
26
    {
27
        parent::__construct();
28
    }
29
30
    protected function execute(InputInterface $input, OutputInterface $output): int
31
    {
32
        $fs = new Filesystem();
33
        $io = new SymfonyStyle($input, $output);
34
35
        foreach ($this->kernel->getBundles() as $bundle) {
36
            if (!$bundle instanceof Bundle) {
37
                continue;
38
            }
39
40
            $bundlePath = $bundle->getPath();
41
            $publicPath = $bundlePath . '/Resources/public';
42
43
            if (!is_dir($publicPath)) {
44
                continue;
45
            }
46
47
            if (file_exists($bundlePath . '/Resources/public/administration/css')) {
48
                touch($bundle->getPath() . '/Resources/.administration-css');
49
            }
50
51
            if (file_exists($bundlePath . '/Resources/public/administration/js')) {
52
                touch($bundle->getPath() . '/Resources/.administration-js');
53
            }
54
55
            $fs->remove($publicPath);
56
57
            $io->success(sprintf('Removed public assets for bundle "%s"', $bundle->getName()));
58
        }
59
60
        return self::SUCCESS;
61
    }
62
}
63