Source of file MagicMethodsExceptionsTrait.php
Size: 2,757 Bytes - Last Modified: 2021-01-12T22:04:13+00:00
C:/Users/MAKS/Code/_PROJECTS/amqp-agent/src/Exception/MagicMethodsExceptionsTrait.php
1234567891011121314151617181920212223242526272829303132
Covered by 1 test(s):
33
Covered by 1 test(s):
34
Covered by 1 test(s):
353637383940414243444546474849
Covered by 1 test(s):
50
Covered by 1 test(s):
51
Covered by 1 test(s):
525354555657585960616263646566
Covered by 1 test(s):
67
Covered by 1 test(s):
68
Covered by 1 test(s):
6970
Covered by 1 test(s):
7172737475767778798081828384
Covered by 1 test(s):
85
Covered by 1 test(s):
86
Covered by 1 test(s):
8788
Covered by 1 test(s):
8990919293
| <?php /** * @author Marwan Al-Soltany <MarwanAlsoltany@gmail.com> * @copyright Marwan Al-Soltany 2020 * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ declare(strict_types=1); namespace MAKS\AmqpAgent\Exception; use MAKS\AmqpAgent\Helper\ArrayProxy; use MAKS\AmqpAgent\Exception\PropertyDoesNotExistException; use MAKS\AmqpAgent\Exception\MethodDoesNotExistException; /** * A trait to throw exceptions on calls to magic methods. * @since 1.2.0 */ trait MagicMethodsExceptionsTrait { /** * Throws an exception when trying to get a class member via public property assignment notation. * @param string $property Property name. * @return void * @throws PropertyDoesNotExistException */ public function __get(string $property) { throw new PropertyDoesNotExistException( sprintf( 'The requested property with the name "%s" does not exist!', $property ) ); } /** * Throws an exception when trying to set a class member via public property assignment notation. * @param string $property Property name. * @param array $value Property value. * @return void * @throws PropertyDoesNotExistException */ public function __set(string $property, $value) { throw new PropertyDoesNotExistException( sprintf( 'A property with the name "%s" is immutable or does not exist!', $property ) ); } /** * Throws an exception for calls to undefined methods. * @param string $method Function name. * @param array $parameters Function arguments. * @return mixed * @throws MethodDoesNotExistException */ public function __call(string $method, $parameters) { throw new MethodDoesNotExistException( sprintf( 'The called method "%s" with the parameter(s) "%s" does not exist!', $method, ArrayProxy::castArrayToString($parameters) ) ); } /** * Throws an exception for calls to undefined static methods. * @param string $method Function name. * @param array $parameters Function arguments. * @return mixed * @throws MethodDoesNotExistException */ public static function __callStatic(string $method, $parameters) { throw new MethodDoesNotExistException( sprintf( 'The called static method "%s" with the parameter(s) "%s" does not exist', $method, ArrayProxy::castArrayToString($parameters) ) ); } } |