DoctrineMigrationCheck::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 4
rs 10
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
        $result = new Result($this->label);
21
22
        try {
23
            $calc = $this->dependencyFactory->getMigrationStatusCalculator();
24
            $count = $calc->getNewMigrations()->count();
25
            $aliasResolver = $this->dependencyFactory->getVersionAliasResolver();
26
            $version = $aliasResolver->resolveVersionAlias('latest');
27
        
28
            if ((string)$version !== '') {
29
                $result->setDetails('current version: '.$version);
30
            }
31
            if ($count > 0) {
32
                $result->setError($count.' outstanding migration(s)');
33
            }
34
        } catch (\Throwable $e) {
35
            $result->setError($e->getMessage());
36
        }
37
        
38
        return $result;
39
    }
40
}
41