MigrationsAreUpToDate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 49
ccs 4
cts 14
cp 0.2857
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A check() 0 11 2
A message() 0 9 2
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use Illuminate\Support\Facades\Artisan;
6
7
class MigrationsAreUpToDate implements Check
8
{
9
    private $databaseError = null;
10
11
    /**
12
     * The name of the check.
13
     *
14
     * @param array $config
15
     * @return string
16
     */
17
    public function name(array $config): string
18
    {
19
        return trans('self-diagnosis::checks.migrations_are_up_to_date.name');
20
    }
21
22
    /**
23
     * Perform the actual verification of this check.
24
     *
25
     * @param array $config
26
     * @return bool
27
     */
28 8
    public function check(array $config): bool
29
    {
30
        try {
31 8
            Artisan::call('migrate', ['--pretend' => 'true', '--force' => 'true']);
32 8
            $output = Artisan::output();
33 8
            return strstr($output, 'Nothing to migrate.');
34
        } catch (\PDOException $e) {
35
            $this->databaseError = $e->getMessage();
36
        }
37
        return false;
38
    }
39
40
    /**
41
     * The error message to display in case the check does not pass.
42
     *
43
     * @param array $config
44
     * @return string
45
     */
46
    public function message(array $config): string
47
    {
48
        if ($this->databaseError !== null) {
49
            return trans('self-diagnosis::checks.migrations_are_up_to_date.message.unable_to_check', [
50
                'reason' => $this->databaseError,
51
            ]);
52
        }
53
        return trans('self-diagnosis::checks.migrations_are_up_to_date.message.need_to_migrate');
54
    }
55
}
56