ReflectionClassNewInstancePatch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A apply() 0 6 2
A getPriority() 0 4 1
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
 * ReflectionClass::newInstance patch.
18
 * Makes first argument of newInstance optional, since it works but signature is misleading
19
 *
20
 * @author Florian Klein <[email protected]>
21
 */
22
class ReflectionClassNewInstancePatch implements ClassPatchInterface
23
{
24
    /**
25
     * Supports ReflectionClass
26
     *
27
     * @param ClassNode $node
28
     *
29
     * @return bool
30
     */
31
    public function supports(ClassNode $node)
32
    {
33
        return 'ReflectionClass' === $node->getParentClass();
34
    }
35
36
    /**
37
     * Updates newInstance's first argument to make it optional
38
     *
39
     * @param ClassNode $node
40
     */
41
    public function apply(ClassNode $node)
42
    {
43
        foreach ($node->getMethod('newInstance')->getArguments() as $argument) {
44
            $argument->setDefault(null);
45
        }
46
    }
47
48
    /**
49
     * Returns patch priority, which determines when patch will be applied.
50
     *
51
     * @return int Priority number (higher = earlier)
52
     */
53
    public function getPriority()
54
    {
55
        return 50;
56
    }
57
}
58