Completed
Push — master ( 302460...3743d3 )
by Marcel
02:34
created

getRequiredPhpVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use Illuminate\Filesystem\Filesystem;
6
7
class CorrectPhpVersionIsInstalled implements Check
8
{
9
    /** @var Filesystem */
10
    private $filesystem;
11
12
    public function __construct(Filesystem $filesystem)
13
    {
14
        $this->filesystem = $filesystem;
15
    }
16
17
    /**
18
     * The name of the check.
19
     *
20
     * @return string
21
     */
22
    public function name(): string
23
    {
24
        return 'The correct PHP Version is installed';
25
    }
26
27
    /**
28
     * Perform the actual verification of this check.
29
     *
30
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
31
     * @return bool
32
     */
33
    public function check(): bool
34
    {
35
        return version_compare(phpversion(), $this->getRequiredPhpVersion(), '>=');
36
    }
37
38
    /**
39
     * The error message to display in case the check does not pass.
40
     *
41
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
42
     * @return string
43
     */
44
    public function message() : string
45
    {
46
        return 'You do not have the required PHP version installed.'.PHP_EOL.'Required: '.$this->getRequiredPhpVersion().PHP_EOL.'Used: '.phpversion();
47
    }
48
49
    /**
50
     * @return mixed
51
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
52
     */
53
    public function getRequiredPhpVersion()
54
    {
55
        $composer = json_decode($this->filesystem->get(base_path('composer.json')), true);
56
        $versionString = array_get($composer, 'require.php');
57
58
        return str_replace(['^', '~', '<', '>', '='], '', $versionString);
59
    }
60
}