Failed Conditions
Pull Request — master (#632)
by Michael
02:44
created

UpToDateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 21 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools\Console\Command;
6
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use function count;
10
use function sprintf;
11
12
class UpToDateCommand extends AbstractCommand
13
{
14 4
    protected function configure() : void
15
    {
16
        $this
17 4
            ->setName('migrations:up-to-date')
18 4
            ->setDescription('Tells you if your schema is up-to-date.')
19 4
            ->setHelp(<<<EOT
20 4
The <info>%command.name%</info> command tells you if your schema is up-to-date:
21
22
    <info>%command.full_name%</info>
23
EOT
24
        );
25
26 4
        parent::configure();
27 4
    }
28
29 4
    public function execute(InputInterface $input, OutputInterface $output) : int
30
    {
31 4
        $configuration = $this->getMigrationConfiguration($input, $output);
32
33 4
        $migrations          = count($configuration->getMigrations());
34 4
        $migratedVersions    = count($configuration->getMigratedVersions());
35 4
        $availableMigrations = $migrations - $migratedVersions;
36
37 4
        if ($availableMigrations === 0) {
38 2
            $output->writeln('<comment>Up-to-date! No migrations to execute.</comment>');
39
40 2
            return 0;
41
        }
42
43 2
        $output->writeln(sprintf(
44 2
            '<comment>Out-of-date! %u migration%s available to execute.</comment>',
45 2
            $availableMigrations,
46 2
            $availableMigrations > 1 ? 's are' : ' is'
47
        ));
48
49 2
        return 1;
50
    }
51
}
52