DisplayIndexHelper   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

2 Methods

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