VersionCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 6
c 6
b 0
f 1
lcom 0
cbo 5
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
B execute() 0 31 5
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
use Symfony\Component\Console\Input\InputArgument;
9
10
/**
11
 * Installation after schema update
12
 */
13
class VersionCommand extends ContainerAwareCommand
14
{
15
16
    /**
17
     * {@inherited}
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('bundle:version')
23
            ->setDescription('Informations about a bundle')
24
            ->addArgument('name', InputArgument::REQUIRED)
25
        ;
26
    }
27
28
    /**
29
     * {@inherited}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $name = $input->getArgument('name');
34
        $bundleVersion = $this->getContainer()->get('versions.bundle')->getVersion($name);
35
36
        // informations
37
        $output->writeln('<comment>' . $name . '</comment> informations :');
38
39
        // unversionned bundle
40
        if ($bundleVersion->isVersionned() === false) {
41
            $output->writeln('Bundle <error>not versionned</error>.');
42
            $output->writeln('Unable to get informations, install, update or uninstall it.');
43
            $output->writeln('To create a versionned bundle, see <info>README.md</info>');
44
45
            // versionned bundle
46
        } else {
47
            $output->writeln('Files version : ' . $bundleVersion->getVersion()->asString());
48
            if ($bundleVersion->getInstalledVersion() === null) {
49
                $output->writeln('Installed version : <error>not installed</error>');
50
            } else {
51
                if ($bundleVersion->needUpdate()) {
52
                    $output->writeln('Installed version : <error>' . $bundleVersion->getInstalledVersion()->asString() . '</error> (run php \'app/console bundle:update ' . $name . '\' to update to ' . $bundleVersion->getVersion()->asString() . ')');
53
                } else {
54
                    $output->writeln('Installed version : <info>' . $bundleVersion->getInstalledVersion()->asString() . '</info>');
55
                }
56
                $output->writeln('Installation date : ' . $bundleVersion->getInstallationDate()->format('Y-m-d H:i:s'));
57
                $updateDate = ($bundleVersion->getUpdateDate() === null) ? 'none' : $bundleVersion->getInstallationDate()->format('Y-m-d H:i:s');
58
                $output->writeln('Last update date : ' . $updateDate);
59
            }
60
        }
61
    }
62
}
63