SyntaxChecker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isCorrect() 0 15 3
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\File;
11
12
/**
13
 * Checks syntax of file
14
 *
15
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
16
 */
17
class SyntaxChecker
18
{
19
20
    /**
21
     * Check syntax of file
22
     *
23
     * @param $filename
24
     * @return int
25
     */
26
    public function isCorrect($filename) {
27
        if(1 === version_compare('5.0.4', PHP_VERSION)) {
28
            return php_check_syntax($filename);
29
        }
30
31
        $php = 'php';
32
33
        if (0 >= version_compare('5.4.0', PHP_VERSION)) {
34
           $php = PHP_BINARY;
35
        }
36
37
        $output = shell_exec(sprintf('"%s" -l %s 2>&1', $php, escapeshellarg($filename)));
38
        
39
        return preg_match('!No syntax errors detected!', $output);
40
    }
41
}
42