Completed
Pull Request — master (#60)
by
unknown
177:15
created

MigrationsAreUpToDate::check()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 4
nop 1
crap 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 4
    public function name(array $config): string
18
    {
19 4
        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 12
    public function check(array $config): bool
29
    {
30
        try {
31 12
            Artisan::call('migrate', ['--pretend' => 'true', '--force' => 'true']);
32 8
            $output = Artisan::output();
33 8
            return strstr($output, 'Nothing to migrate.');
34 4
        } catch (\PDOException $e) {
35 4
            $this->databaseError = $e->getMessage();
36
        }
37 4
        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 8
    public function message(array $config): string
47
    {
48 8
        if ($this->databaseError !== null) {
49 4
            return trans('self-diagnosis::checks.migrations_are_up_to_date.message.unable_to_check', [
50 4
                'reason' => $this->databaseError,
51
            ]);
52
        }
53 8
        return trans('self-diagnosis::checks.migrations_are_up_to_date.message.need_to_migrate');
54
    }
55
}
56