Completed
Push — master ( f68934...3c6d4a )
by Marwan
22s queued 12s
created

MagicMethodsExceptionsTrait::__callStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * @author Marwan Al-Soltany <[email protected]>
4
 * @copyright Marwan Al-Soltany 2020
5
 * For the full copyright and license information, please view
6
 * the LICENSE file that was distributed with this source code.
7
 */
8
9
namespace MAKS\AmqpAgent\Exception;
10
11
use MAKS\AmqpAgent\Exception\PropertyDoesNotExistException;
12
use MAKS\AmqpAgent\Exception\MethodDoesNotExistException;
13
14
/**
15
 * A trait to throw exceptions on calls to magic methods.
16
 * @since 1.2.0
17
 */
18
trait MagicMethodsExceptionsTrait
19
{
20
    /**
21
     * Throws an exception when trying to get a class member via public property assignment notation.
22
     * @param string $property Property name.
23
     * @return void
24
     * @throws PropertyDoesNotExistException
25
     */
26 1
    public function __get(string $property)
27
    {
28 1
        throw new PropertyDoesNotExistException(
29 1
            sprintf(
30 1
                'The requested property with the name "%s" does not exist!',
31
                $property
32
            )
33
        );
34
    }
35
36
    /**
37
     * Throws an exception when trying to set a class member via public property assignment notation.
38
     * @param string $property Property name.
39
     * @param array $value Property value.
40
     * @return void
41
     * @throws PropertyDoesNotExistException
42
     */
43 1
    public function __set(string $property, $value)
44
    {
45 1
        throw new PropertyDoesNotExistException(
46 1
            sprintf(
47 1
                'A property with the name "%s" is immutable or does not exist!',
48
                $property
49
            )
50
        );
51
    }
52
53
    /**
54
     * Throws an exception for calls to undefined methods.
55
     * @param string $method Function name.
56
     * @param array $parameters Function arguments.
57
     * @return mixed
58
     * @throws MethodDoesNotExistException
59
     */
60 1
    public function __call(string $method, $parameters)
61
    {
62 1
        throw new MethodDoesNotExistException(
63 1
            sprintf(
64 1
                'The called method "%s" with the parameter(s) "%s" does not exist!',
65
                $method,
66 1
                implode(', ', $parameters)
67
            )
68
        );
69
    }
70
71
    /**
72
     * Throws an exception for calls to undefined static methods.
73
     * @param string $method Function name.
74
     * @param array $parameters Function arguments.
75
     * @return mixed
76
     * @throws MethodDoesNotExistException
77
     */
78 1
    public static function __callStatic(string $method, $parameters)
79
    {
80 1
        throw new MethodDoesNotExistException(
81 1
            sprintf(
82 1
                'The called static method "%s" with the parameter(s) "%s" does not exist',
83
                $method,
84 1
                implode(', ', $parameters)
85
            )
86
        );
87
    }
88
}
89