Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Call / RuntimeCallee.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Call;
12
13 use Behat\Testwork\Call\Exception\BadCallbackException;
14 use ReflectionFunction;
15 use ReflectionFunctionAbstract;
16 use ReflectionMethod;
17
18 /**
19  * Represents callee created and executed in the runtime.
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 class RuntimeCallee implements Callee
24 {
25     /**
26      * @var callable
27      */
28     private $callable;
29     /**
30      * @var null|string
31      */
32     private $description;
33     /**
34      * @var ReflectionFunctionAbstract
35      */
36     private $reflection;
37     /**
38      * @var string
39      */
40     private $path;
41
42     /**
43      * Initializes callee.
44      *
45      * @param callable    $callable
46      * @param null|string $description
47      *
48      * @throws BadCallbackException If invalid callback provided
49      */
50     public function __construct($callable, $description = null)
51     {
52         if (!is_array($callable) && !is_callable($callable)) {
53             throw new BadCallbackException(sprintf(
54                 '%s expects a valid callable, but `%s` given',
55                 get_class($this),
56                 gettype($callable)
57             ), $callable);
58         }
59
60         if (is_array($callable)) {
61             $this->reflection = new ReflectionMethod($callable[0], $callable[1]);
62             $this->path = $callable[0] . '::' . $callable[1] . '()';
63         } else {
64             $this->reflection = new ReflectionFunction($callable);
65             $this->path = $this->reflection->getFileName() . ':' . $this->reflection->getStartLine();
66         }
67
68         $this->callable = $callable;
69         $this->description = $description;
70     }
71
72     /**
73      * Returns callee description.
74      *
75      * @return string
76      */
77     public function getDescription()
78     {
79         return $this->description;
80     }
81
82     /**
83      * Returns callee definition path.
84      *
85      * @return string
86      */
87     public function getPath()
88     {
89         return $this->path;
90     }
91
92     /**
93      * Returns callable.
94      *
95      * @return callable
96      */
97     public function getCallable()
98     {
99         return $this->callable;
100     }
101
102     /**
103      * Returns callable reflection.
104      *
105      * @return ReflectionFunctionAbstract
106      */
107     public function getReflection()
108     {
109         return $this->reflection;
110     }
111
112     /**
113      * Returns true if callee is a method, false otherwise.
114      *
115      * @return Boolean
116      */
117     public function isAMethod()
118     {
119         return $this->reflection instanceof ReflectionMethod;
120     }
121
122     /**
123      * Returns true if callee is an instance (non-static) method, false otherwise.
124      *
125      * @return Boolean
126      */
127     public function isAnInstanceMethod()
128     {
129         return $this->reflection instanceof ReflectionMethod
130             && !$this->reflection->isStatic();
131     }
132 }