1<?php
2
3/*
4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 *     Marcello Duarte <marcello.duarte@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Prophecy\Doubler\ClassPatch;
13
14use Prophecy\Doubler\Generator\Node\ClassNode;
15
16/**
17 * Exception patch for HHVM to remove the stubs from special methods
18 *
19 * @author Christophe Coevoet <stof@notk.org>
20 */
21class 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