Passed
Pull Request — master (#6)
by
unknown
02:45
created

ManifestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ElevenLabs\ApiServiceBundle\Command;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class ManifestCommand.
13
 */
14
class ManifestCommand extends Command
15
{
16
    protected static $defaultName = 'api:manifest';
17
18
    /**
19
     *
20
     */
21
    protected function configure()
22
    {
23
        $this
24
            ->setDescription('Removes unnecessary files from the recorder')
25
            ->addArgument('dir')
26
        ;
27
    }
28
29
    /**
30
     * @param InputInterface  $input
31
     * @param OutputInterface $output
32
     *
33
     * @return int|void|null
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $dir = $input->getArgument('dir');
38
        $file = \realpath(sprintf('%s/manifest.json', $dir));
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type string[]; however, parameter $args of sprintf() 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

38
        $file = \realpath(sprintf('%s/manifest.json', /** @scrutinizer ignore-type */ $dir));
Loading history...
39
40
        if (!\is_file($file)) {
41
            return ;
42
        }
43
44
        $files = array_keys(json_decode(file_get_contents($file) ?? '[]', true));
45
        foreach (scandir($dir) as $file) {
0 ignored issues
show
Bug introduced by
It seems like $dir can also be of type string[]; however, parameter $directory of scandir() 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

45
        foreach (scandir(/** @scrutinizer ignore-type */ $dir) as $file) {
Loading history...
46
            if ('.' === $file[0]) {
47
                continue;
48
            }
49
50
            if (!\in_array($file, $files)) {
51
                unlink($file);
52
            }
53
        }
54
    }
55
}
56