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\Input\InputOption; |
||||
8 | use Symfony\Component\Console\Output\OutputInterface; |
||||
9 | |||||
10 | class ExtractFileCommand extends BaseFileCommand |
||||
11 | { |
||||
12 | protected static $defaultName = 'file:extract'; |
||||
13 | |||||
14 | protected function configure() |
||||
15 | { |
||||
16 | parent::configure(); |
||||
17 | $this |
||||
18 | ->setDescription('Extracts a file from archive to disk') |
||||
19 | ->setHelp('Extracts a file from archive to disk.') |
||||
20 | ->addArgument('destination', InputArgument::OPTIONAL, 'File destination (if set folder - extracts file to folder)') |
||||
21 | ->addOption('overwrite', null, InputOption::VALUE_OPTIONAL, 'Overwrite file or not, if exists with the same name', false) |
||||
22 | ; |
||||
23 | } |
||||
24 | |||||
25 | public function execute(InputInterface $input, OutputInterface $output) |
||||
26 | { |
||||
27 | list($archive, $file) = $this->getArchiveAndFile($input, $output); |
||||
28 | $destination = $input->getArgument('destination'); |
||||
29 | if (is_dir($destination)) { |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
30 | $destination = $destination . '/' . basename($file); |
||||
0 ignored issues
–
show
Are you sure
$destination of type null|string|string[] can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
31 | } |
||||
32 | |||||
33 | $overwrite = $input->getOption('overwrite'); |
||||
34 | |||||
35 | if (file_exists($destination) && !$overwrite) { |
||||
0 ignored issues
–
show
It seems like
$destination can also be of type null and string[] ; however, parameter $filename of file_exists() 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
![]() |
|||||
36 | if ($input->getOption('no-interaction')) { |
||||
37 | throw new \LogicException('File destination ' . $destination . ' exists'); |
||||
38 | } |
||||
39 | } |
||||
40 | |||||
41 | return 0; |
||||
42 | } |
||||
43 | } |
||||
44 |