Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Call / Handler / Exception / MethodNotFoundHandler.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\Handler\Exception;
12
13 use Behat\Testwork\Call\Handler\ExceptionHandler;
14 use Error;
15
16 /**
17  * Handles method not found exceptions.
18  *
19  * @see ExceptionHandler
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 abstract class MethodNotFoundHandler implements ExceptionHandler
24 {
25     const PATTERN = '/^Call to undefined method ([^:]+)::([^\)]+)\(\)$/';
26
27     /**
28      * {@inheritdoc}
29      */
30     final public function supportsException($exception)
31     {
32         if (!$exception instanceof Error) {
33             return false;
34         }
35
36         return null !== $this->extractNonExistentCallable($exception);
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     final public function handleException($exception)
43     {
44         $this->handleNonExistentMethod($this->extractNonExistentCallable($exception));
45
46         return $exception;
47     }
48
49     /**
50      * Override to handle non-existent method.
51      *
52      * @param array $callable
53      */
54     abstract public function handleNonExistentMethod(array $callable);
55
56     /**
57      * Extract callable from exception.
58      *
59      * @param Error $exception
60      *
61      * @return null|array
62      */
63     private function extractNonExistentCallable(Error $exception)
64     {
65         if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) {
66             return array($matches[1], $matches[2]);
67         }
68
69         return null;
70     }
71 }