Passed
Push — 1.1.x ( bc52f7...e8e75c )
by f
12:04
created

InfoCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 16 4
A configure() 0 6 1
1
<?php
2
3
namespace wapmorgan\UnifiedArchive\Commands;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use wapmorgan\UnifiedArchive\Drivers\BasicDriver;
8
9
class InfoCommand extends BaseArchiveCommand
10
{
11
    protected static $defaultName = 'archive:info';
12
13
    protected function configure()
14
    {
15
        parent::configure();
16
        $this
17
            ->setDescription('Renders archive info')
18
            ->setHelp('Renders archive info.')
19
        ;
20
    }
21
22
    /**
23
     * @throws \Exception
24
     */
25
    public function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $file = realpath($input->getArgument('archive'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('archive') can also be of type null and string[]; however, parameter $path of realpath() 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
        $file = realpath(/** @scrutinizer ignore-type */ $input->getArgument('archive'));
Loading history...
28
        $archive = $this->getArchive($input, $output);
29
30
        $output->writeln('Filename: ' . $file . ' (changed <comment>' . $this->formatDate(filemtime($file)) . '</comment>)');
31
        $output->writeln('Type: <info>' . $archive->getFormat() . '</info>, mime <info>' . $archive->getMimeType() . '</info> (via driver <comment>' . $archive->getDriverType() . '</comment>)');
32
        $output->writeln('Contains: ' . $archive->countFiles() . ' file' . ($archive->countFiles() > 1 ? 's' : null));
33
        $output->writeln('Size:');
34
        $output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2)));
35
        $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($archive->getCompressedSize(), 2)));
36
        $output->writeln("\t" . 'ratio: <info>' . round($archive->getOriginalSize() / $archive->getCompressedSize(), 6) . '/1 (' . floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100) . '%</info>)');
37
        if ($archive->getDriver()->checkAbility(BasicDriver::GET_COMMENT) && !empty($comment = $archive->getComment()))
38
            $output->writeln('Comment: <comment>' . $comment . '</comment>');
39
40
        return 0;
41
    }
42
}
43