GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c11e1b...0baec8 )
by Jonny
03:47
created

ProcedureValidator::validateSyntax()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.1922

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 7
cts 11
cp 0.6364
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2.1922
1
<?php
2
3
/*
4
 * This file is part of the php-phantomjs.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
namespace JonnyW\PhantomJs\Procedure;
10
11
use JonnyW\PhantomJs\Validator\EngineInterface;
12
use JonnyW\PhantomJs\Exception\SyntaxException;
13
use JonnyW\PhantomJs\Exception\RequirementException;
14
15
/**
16
 * PHP PhantomJs
17
 *
18
 * @author Jon Wenmoth <[email protected]>
19
 */
20
class ProcedureValidator implements ProcedureValidatorInterface
21
{
22
    /**
23
     * Procedure loader.
24
     *
25
     * @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
26
     * @access protected
27
     */
28
    protected $procedureLoader;
29
30
    /**
31
     * Validator engine
32
     *
33
     * @var \JonnyW\PhantomJs\Validator\EngineInterface
34
     * @access protected
35
     */
36
    protected $engine;
37
38
    /**
39
     * Internal constructor.
40
     *
41
     * @access public
42
     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
43
     * @param \JonnyW\PhantomJs\Validator\EngineInterface          $engine
44
     */
45 1
    public function __construct(ProcedureLoaderInterface $procedureLoader, EngineInterface $engine)
46
    {
47 1
        $this->procedureLoader = $procedureLoader;
48 1
        $this->engine          = $engine;
49 1
    }
50
51
    /**
52
     * Validate procedure.
53
     *
54
     * @access public
55
     * @param  string                                                   $procedure
56
     * @return boolean
57
     * @throws \JonnyW\PhantomJs\Exception\ProcedureValidationException
58
     */
59 1
    public function validate($procedure)
60
    {
61 1
        $this->validateSyntax($procedure);
62
        $this->validateRequirements($procedure);
63
64
        return true;
65
    }
66
67
    /**
68
     * Validate syntax.
69
     *
70
     * @access protected
71
     * @param  string                                      $procedure
72
     * @return void
73
     * @throws \JonnyW\PhantomJs\Exception\SyntaxException
74
     */
75 1
    protected function validateSyntax($procedure)
76
    {
77 1
        $input  = new Input();
78 1
        $output = new Output();
79
80 1
        $input->set('procedure', $procedure);
81 1
        $input->set('engine', $this->engine->toString());
82
83 1
        $validator = $this->procedureLoader->load('validator');
84 1
        $validator->run($input, $output);
85
86
        $errors = $output->get('errors');
87
88
        if (!empty($errors)) {
89
            throw new SyntaxException('Your procedure failed to compile due to a javascript syntax error', (array) $errors);
90
        }
91
    }
92
93
    /**
94
     * validateRequirements function.
95
     *
96
     * @access protected
97
     * @param  string                                           $procedure
98
     * @return void
99
     * @throws \JonnyW\PhantomJs\Exception\RequirementException
100
     */
101
    protected function validateRequirements($procedure)
102
    {
103
        if (preg_match('/phantom\.exit\(/', $procedure, $matches) !== 1) {
104
            throw new RequirementException('Your procedure must contain a \'phantom.exit(1);\' command to avoid the PhantomJS process hanging');
105
        }
106
    }
107
}
108