DoctrineMigrationCheck   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 17
c 2
b 0
f 1
dl 0
loc 31
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkStatus() 0 21 4
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