Completed
Push — master ( 9eb332...ef5bef )
by Arne
02:27
created

DisplayIndexHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
B displayIndex() 0 26 7
1
<?php
2
3
namespace Storeman\Cli\Helper;
4
5
use Storeman\Index\Index;
6
use Storeman\Index\IndexObject;
7
use Symfony\Component\Console\Helper\Helper;
8
use Symfony\Component\Console\Helper\HelperInterface;
9
use Symfony\Component\Console\Helper\Table;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class DisplayIndexHelper extends Helper implements HelperInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getName(): string
18
    {
19
        return 'displayIndex';
20
    }
21
22
    public function displayIndex(Index $index, OutputInterface $output)
23
    {
24
        $table = new Table($output);
25
        $table->setStyle('compact');
26
        $table->setHeaders(['Path', 'Type', 'Times', 'Permissions', 'Inode', 'LinkTarget', 'Size', 'BlobId', 'Hashes']);
27
28
        foreach ($index as $indexObject)
29
        {
30
            /** @var IndexObject $indexObject */
31
32
            $table->addRow([
33
                $indexObject->getRelativePath(),
34
                $indexObject->getTypeName(),
35
                'mtime: ' . \DateTime::createFromFormat('U', $indexObject->getMtime())->format('c') . "\n" .
36
                'ctime: ' . \DateTime::createFromFormat('U', $indexObject->getCtime())->format('c'),
37
                "0{$indexObject->getPermissionsString()}",
38
                $indexObject->getInode() ?: '-',
39
                $indexObject->getLinkTarget() ?: '-',
40
                $indexObject->getSize() ? static::formatMemory($indexObject->getSize()) : '-',
41
                $indexObject->getBlobId() ?: '-',
42
                    $indexObject->getHashes() ? str_replace(', ', "\n", $indexObject->getHashes()->__toString()) : '-',
43
            ]);
44
        }
45
46
        $table->render();
47
    }
48
}
49