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

CodeValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 78.95%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 38
ccs 15
cts 19
cp 0.7895
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isValid() 0 30 4
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