Issues (155)

src/Commands/ExtractArchiveCommand.php (6 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 ExtractArchiveCommand extends BaseArchiveCommand
10
{
11
    protected static $defaultName = 'archive:extract';
12
13
    protected function configure()
14
    {
15
        parent::configure();
16
        $this
17
            ->setDescription('Extracts all archive contents and overwrites existing files')
18
            ->setHelp('Extracts all archive contents and overwrites existing files.')
19
            ->addArgument('outputDir', InputArgument::REQUIRED, 'Folder to extract contents')
20
        ;
21
    }
22
23
    public function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $output_dir = $input->getArgument('outputDir');
26
        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

26
        if (!is_dir(/** @scrutinizer ignore-type */ $output_dir)) {
Loading history...
27
            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

27
            mkdir(/** @scrutinizer ignore-type */ $output_dir, 0777, true);
Loading history...
28
        } 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

28
        } else if (!is_writable(/** @scrutinizer ignore-type */ $output_dir)) {
Loading history...
29
            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

29
            chmod(/** @scrutinizer ignore-type */ $output_dir, 0777);
Loading history...
30
        }
31
        $archive = $this->getArchive($input, $output);
32
33
        if (disk_free_space($output_dir) < $archive->getOriginalSize()) {
0 ignored issues
show
It seems like $output_dir can also be of type null and string[]; however, parameter $directory of disk_free_space() 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

33
        if (disk_free_space(/** @scrutinizer ignore-type */ $output_dir) < $archive->getOriginalSize()) {
Loading history...
34
            throw new \LogicException('Archive size ' . implode($this->formatSize($archive->getOriginalSize())) . ' is more that available on disk '
35
                                      . implode($this->formatSize(disk_free_space($output_dir))));
36
        }
37
        $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

37
        $archive->extract(/** @scrutinizer ignore-type */ $output_dir, $entry_selector, true);
Loading history...
38
        $output->writeln('<info>Extracted all archive contents (' . implode($this->formatSize($archive->getOriginalSize())) . ')</info>');
39
40
        return 0;
41
    }
42
}
43