Completed
Pull Request — master (#476)
by Ciaran
04:26
created

KeywordPatch::getKeywords()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Prophecy.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *     Marcello Duarte <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Prophecy\Doubler\ClassPatch;
13
14
use Prophecy\Doubler\Generator\Node\ClassNode;
15
16
/**
17
 * Remove method functionality from the double which will clash with php keywords.
18
 *
19
 * @author Milan Magudia <[email protected]>
20
 */
21
class KeywordPatch implements ClassPatchInterface
22
{
23
    /**
24
     * Support any class
25
     *
26
     * @param ClassNode $node
27
     *
28
     * @return boolean
29
     */
30
    public function supports(ClassNode $node)
31
    {
32
        return true;
33
    }
34
35
    /**
36
     * Remove methods that clash with php keywords
37
     *
38
     * @param ClassNode $node
39
     */
40
    public function apply(ClassNode $node)
41
    {
42
        $methodNames = array_keys($node->getMethods());
43
        $methodsToRemove = array_intersect($methodNames, $this->getKeywords());
44
        foreach ($methodsToRemove as $methodName) {
45
            $node->removeMethod($methodName);
46
        }
47
    }
48
49
    /**
50
     * Returns patch priority, which determines when patch will be applied.
51
     *
52
     * @return int Priority number (higher - earlier)
53
     */
54
    public function getPriority()
55
    {
56
        return 49;
57
    }
58
59
    /**
60
     * Returns array of php keywords.
61
     *
62
     * @return array
63
     */
64
    private function getKeywords()
65
    {
66
        return ['__halt_compiler'];
67
    }
68
}
69