Passed
Push — master ( 0d8a9b...48a836 )
by f
12:20
created

src/Commands/ExtractFilesCommand.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace wapmorgan\UnifiedArchive\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ExtractFilesCommand extends BaseArchiveCommand
10
{
11
    protected static $defaultName = 'files:extract';
12
13
    protected function configure()
14
    {
15
        parent::configure();
16
        $this
17
            ->setDescription('Extracts archive contents by selector')
18
            ->setHelp('Extracts all archive contents by selector.')
19
            ->addArgument('outputDir', InputArgument::REQUIRED, 'Folder to extract contents')
20
            ->addArgument('entrySelector', InputArgument::OPTIONAL, 'Prefix of entry selector. Default is null, means root of archive')
21
        ;
22
    }
23
24
    public function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $output_dir = $input->getArgument('outputDir');
27
        if (!is_dir($output_dir)) {
28
            mkdir($output_dir, 0777, true);
29
        } else if (!is_writable($output_dir)) {
30
            chmod($output_dir, 0777);
31
        }
32
        $archive = $this->getArchive($input, $output);
33
        $entry_selector = $input->getArgument('entrySelector');
34
35
        $archive->extract($output_dir, $entry_selector, true);
36
        $output->writeln('<info>Extracted:</info> ' . implode(', ', $entry_selector) . ' (' . count($entry_selector) . ') file(s)');
0 ignored issues
show
It seems like $entry_selector can also be of type null and string; however, parameter $pieces of implode() does only seem to accept array, 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

36
        $output->writeln('<info>Extracted:</info> ' . implode(', ', /** @scrutinizer ignore-type */ $entry_selector) . ' (' . count($entry_selector) . ') file(s)');
Loading history...
It seems like $entry_selector can also be of type null and string; however, parameter $value of count() does only seem to accept Countable|array, 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

36
        $output->writeln('<info>Extracted:</info> ' . implode(', ', $entry_selector) . ' (' . count(/** @scrutinizer ignore-type */ $entry_selector) . ') file(s)');
Loading history...
37
38
        return 0;
39
    }
40
}
41