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

DisplayIndexHelper::displayIndex()   B

Complexity

Conditions 7
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 8.5706
cc 7
nc 2
nop 2
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