Completed
Push — master ( ff8ed5...dcad7a )
by Mike
15:53 queued 12:44
created

UpToDateCommand::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 9.4285
cc 3
eloc 13
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Doctrine\DBAL\Migrations\Tools\Console\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
/**
9
 * Command to show if your schema is up-to-date.
10
 */
11
class UpToDateCommand extends AbstractCommand
12
{
13 4
    protected function configure()
14
    {
15 4
        $this
16 4
            ->setName('migrations:up-to-date')
17 4
            ->setDescription('Tells you if your schema is up-to-date.')
18 4
            ->setHelp(<<<EOT
19
The <info>%command.name%</info> command tells you if your schema is up-to-date:
20
21
    <info>%command.full_name%</info>
22
EOT
23 4
        );
24
25 4
        parent::configure();
26 4
    }
27
28
    /**
29
     * @param InputInterface $input
30
     * @param OutputInterface $output
31
     * @return int|null
32
     */
33 4
    public function execute(InputInterface $input, OutputInterface $output)
34
    {
35 4
        $configuration = $this->getMigrationConfiguration($input, $output);
36
        
37 4
        $migrations = count($configuration->getMigrations());
38 4
        $migratedVersions = count($configuration->getMigratedVersions());
39 4
        $availableMigrations = $migrations - $migratedVersions;
40
        
41 4
        if ($availableMigrations === 0) {
42 2
            $output->writeln('<comment>Up-to-date! No migrations to execute.</comment>');
43 2
            return 0;
44
        }
45
        
46 2
        $output->writeln(sprintf(
47 2
            '<comment>Out-of-date! %u migration%s available to execute.</comment>',
48 2
            $availableMigrations,
49 2
            $availableMigrations > 1 ? 's are' : ' is'
50 2
        ));
51 2
        return 1;
52
    }
53
}
54