Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / src / Psy / Exception / TypeErrorException.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
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 Psy\Exception;
13
14 /**
15  * A "type error" Exception for Psy.
16  */
17 class TypeErrorException extends \Exception implements Exception
18 {
19     private $rawMessage;
20
21     /**
22      * Constructor!
23      *
24      * @param string $message (default: "")
25      * @param int    $code    (default: 0)
26      */
27     public function __construct($message = '', $code = 0)
28     {
29         $this->rawMessage = $message;
30         $message = preg_replace('/, called in .*?: eval\\(\\)\'d code/', '', $message);
31         parent::__construct(sprintf('TypeError: %s', $message), $code);
32     }
33
34     /**
35      * Get the raw (unformatted) message for this error.
36      *
37      * @return string
38      */
39     public function getRawMessage()
40     {
41         return $this->rawMessage;
42     }
43
44     /**
45      * Create a TypeErrorException from a TypeError.
46      *
47      * @param \TypeError $e
48      *
49      * @return TypeErrorException
50      */
51     public static function fromTypeError(\TypeError $e)
52     {
53         return new self($e->getMessage(), $e->getLine());
54     }
55 }