Completed
Push — master ( 5017d8...561e2a )
by Christian
07:36 queued 03:33
created

PreCheckPhp::checkXDebug()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Installer\SubCommand;
4
5
use N98\Magento\Command\SubCommand\AbstractSubCommand;
6
7
class PreCheckPhp extends AbstractSubCommand
8
{
9
    /**
10
     * Check PHP environment against minimal required settings modules
11
     *
12
     * @return void
13
     */
14
    public function execute()
15
    {
16
        $this->checkExtensions();
17
        $this->checkXDebug();
18
    }
19
20
    /**
21
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
22
     */
23
    protected function checkExtensions()
24
    {
25
        $extensions = $this->commandConfig['installation']['pre-check']['php']['extensions'];
26
        $missingExtensions = array();
27
        foreach ($extensions as $extension) {
28
            if (!extension_loaded($extension)) {
29
                $missingExtensions[] = $extension;
30
            }
31
        }
32
33
        if (count($missingExtensions) > 0) {
34
            throw new \RuntimeException(
35
                'The following PHP extensions are required to start installation: ' . implode(',', $missingExtensions)
36
            );
37
        }
38
    }
39
40
    /**
41
     * @throws \RuntimeException
42
     */
43
    protected function checkXDebug()
44
    {
45
        if (extension_loaded('xdebug') && xdebug_is_enabled() && ini_get('xdebug.max_nesting_level') != -1 && ini_get('xdebug.max_nesting_level') < 200) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 154 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
46
            $errorMessage = 'Please change PHP ini setting "xdebug.max_nesting_level". '
47
                            . 'Please change it to a value >= 200. '
48
                            . 'Your current value is ' . ini_get('xdebug.max_nesting_level');
49
            throw new \RuntimeException($errorMessage);
50
        }
51
    }
52
}
53