Issues (155)

src/Commands/ExtractFilesCommand.php (5 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)) {
0 ignored issues
show
It seems like $output_dir can also be of type null and string[]; however, parameter $filename of is_dir() 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

27
        if (!is_dir(/** @scrutinizer ignore-type */ $output_dir)) {
Loading history...
28
            mkdir($output_dir, 0777, true);
0 ignored issues
show
It seems like $output_dir can also be of type null and string[]; however, parameter $directory of mkdir() 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

28
            mkdir(/** @scrutinizer ignore-type */ $output_dir, 0777, true);
Loading history...
29
        } else if (!is_writable($output_dir)) {
0 ignored issues
show
It seems like $output_dir can also be of type null and string[]; however, parameter $filename of is_writable() 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

29
        } else if (!is_writable(/** @scrutinizer ignore-type */ $output_dir)) {
Loading history...
30
            chmod($output_dir, 0777);
0 ignored issues
show
It seems like $output_dir can also be of type null and string[]; however, parameter $filename of chmod() 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

30
            chmod(/** @scrutinizer ignore-type */ $output_dir, 0777);
Loading history...
31
        }
32
        $archive = $this->getArchive($input, $output);
33
        $entry_selector = $input->getArgument('entrySelector');
34
35
        $archive->extract($output_dir, $entry_selector, true);
0 ignored issues
show
It seems like $output_dir can also be of type string[]; however, parameter $outputFolder of wapmorgan\UnifiedArchive\UnifiedArchive::extract() 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

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