DisplayIndexHelper::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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