Completed
Pull Request — master (#35)
by Saif Eddin
02:55 queued 38s
created

CodeValidator::isValid()   B

Complexity

Conditions 4
Paths 18

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.1492

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 30
ccs 15
cts 19
cp 0.7895
rs 8.5806
cc 4
eloc 19
nc 18
nop 1
crap 4.1492
1
<?php
2
3
namespace PhpToZephir;
4
5
use Zephir\Commands\CommandGenerate;
6
use Zephir\Config;
7
use Zephir\Logger as ZephirLogger;
8
use Zephir\Commands\CommandFullClean;
9
10
class CodeValidator
11
{
12
    /**
13
     * @param string $zephirCode
14
     *
15
     * @throws \Exception
16
     */
17 79
    public function isValid($namespace)
18
    {
19 79
        $currentDir = getcwd();
20
21 79
        chdir(FileWriter::BASE_DESTINATION . $namespace);
22
23 79
        if (!defined('ZEPHIRPATH'))
24 79
            define('ZEPHIRPATH', realpath(__DIR__.'/../../vendor/phalcon/zephir').'/');
25
26 79
        $generateCommand = new CommandGenerate();
27 79
        $cleanCommand = new CommandFullClean();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28
29
        try {
30 79
            $config = new Config();
31 79
            $config->set('namespace', strtolower($namespace));
32 79
            $config->set('silent', true);
33
34 79
            if (is_dir('ext')) {
35
                $cleanCommand->execute($config, new ZephirLogger($config));
36
            }
37 79
            $generateCommand->execute($config, new ZephirLogger($config));
38 79
        } catch (Exception $e) {
39
            chdir($currentDir);
40
            throw new \Exception(sprintf('Error on %s', $e->getMessage()));
41
        }
42
43 79
        chdir($currentDir);
44
45 79
        return true;
46
    }
47
}
48