ListCommand::execute()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 25
rs 8.439
cc 5
eloc 19
nc 6
nop 2
1
<?php
2
3
namespace kujaff\VersionsBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Installation after schema update
11
 */
12
class ListCommand extends ContainerAwareCommand
13
{
14
15
    /**
16
     * {@inherited}
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('bundle:list')
22
            ->setDescription('List all versionned bundles')
23
        ;
24
    }
25
26
    /**
27
     * {@inherited}
28
     */
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $output->writeln('<comment>Bundle</comment>                         <comment>Files</comment>      <comment>Installed</comment>  <comment>Installation</comment>         <comment>Last update</comment>');
32
33
        $bundles = $this->getContainer()->get('versions.bundle')->getBundles();
34
        foreach ($bundles as $bundleVersion) {
35
            $name = sprintf('%-30s', $bundleVersion->getName());
36
            $version = sprintf('%-10s', $bundleVersion->getVersion()->asString());
37
            if ($bundleVersion->isInstalled()) {
38
                $installedVersion = sprintf('%-10s', $bundleVersion->getInstalledVersion()->asString());
39
                if ($bundleVersion->needUpdate()) {
40
                    $installedVersion = '<error>' . $installedVersion . '</error>';
41
                } else {
42
                    $installedVersion = '<info>' . $installedVersion . '</info>';
43
                }
44
                $installationDate = $bundleVersion->getInstallationDate()->format('Y-m-d H:i:s');
45
                $updateDate = ($bundleVersion->getUpdateDate() === null) ? null : $bundleVersion->getUpdateDate()->format('Y-m-d H:i:s');
46
            } else {
47
                $installedVersion = '<error>' . sprintf('%-10s', 'none') . '</error> ';
48
                $installationDate = sprintf('%-19s', null);
49
                $updateDate = sprintf('%-19s', null);
50
            }
51
            $output->writeln($name . ' ' . $version . ' ' . $installedVersion . ' ' . $installationDate . '  ' . $updateDate);
52
        }
53
    }
54
}
55