HhvmExceptionPatch   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 8 3
A apply() 0 9 3
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
 * Exception patch for HHVM to remove the stubs from special methods
18
 *
19
 * @author Christophe Coevoet <[email protected]>
20
 */
21
class HhvmExceptionPatch implements ClassPatchInterface
22
{
23
    /**
24
     * Supports exceptions on HHVM.
25
     *
26
     * @param ClassNode $node
27
     *
28
     * @return bool
29
     */
30
    public function supports(ClassNode $node)
31
    {
32
        if (!defined('HHVM_VERSION')) {
33
            return false;
34
        }
35
36
        return 'Exception' === $node->getParentClass() || is_subclass_of($node->getParentClass(), 'Exception');
37
    }
38
39
    /**
40
     * Removes special exception static methods from the doubled methods.
41
     *
42
     * @param ClassNode $node
43
     *
44
     * @return void
45
     */
46
    public function apply(ClassNode $node)
47
    {
48
        if ($node->hasMethod('setTraceOptions')) {
49
            $node->getMethod('setTraceOptions')->useParentCode();
50
        }
51
        if ($node->hasMethod('getTraceOptions')) {
52
            $node->getMethod('getTraceOptions')->useParentCode();
53
        }
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getPriority()
60
    {
61
        return -50;
62
    }
63
}
64