Passed
Push — master ( b485e3...0a6ef1 )
by Bret R.
07:47
created

DoctrineMigrationCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkStatus() 0 15 3
A __construct() 0 4 1
1
<?php
2
namespace BretRZaun\StatusPage\Check;
3
4
use BretRZaun\StatusPage\Check\AbstractCheck;
5
use BretRZaun\StatusPage\Result;
6
use Doctrine\Migrations\DependencyFactory;
7
8
class DoctrineMigrationCheck extends AbstractCheck
9
{
10
    private DependencyFactory $dependencyFactory;
11
12
    public function __construct(string $label, DependencyFactory $dependencyFactory)
13
    {
14
        parent::__construct($label);
15
        $this->dependencyFactory = $dependencyFactory;
16
    }
17
18
    public function checkStatus(): Result
19
    {
20
        $calc = $this->dependencyFactory->getMigrationStatusCalculator();
21
        $count = $calc->getNewMigrations()->count();
22
        $aliasResolver = $this->dependencyFactory->getVersionAliasResolver();
23
        $version = $aliasResolver->resolveVersionAlias('latest');
24
25
        $result = new Result($this->label);
26
        if ($version) {
0 ignored issues
show
introduced by
$version is of type Doctrine\Migrations\Version\Version, thus it always evaluated to true.
Loading history...
27
            $result->setDetails('current version: '.$version);
28
        }
29
        if ($count > 0) {
30
            $result->setError($count.' outstanding migration(s)');
31
        }
32
        return $result;
33
    }
34
}