Completed
Push — master ( b8da3f...f66325 )
by Emily
10s
created

PropertyAccessException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
crap 1.0046
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Exception;
16
17
use \Exception;
18
use \Throwable;
19
20
/**
21
 * Thrown when a property cannot be accessed for any reason
22
 */
23
class PropertyAccessException extends Exception
24
{
25
    /**
26
     * The type of access for the error message
27
     *
28
     * Overridden by child classes to provide detailed error feedback.
29
     * Example values might be 'read' or 'write'.
30
     */
31
    const ACCESS_TYPE = 'access';
32
33
    /**
34
     * The type of error for the error message
35
     *
36
     * Overridden by child classes to provide detailed error feedback.
37
     * Example values might be 'Permission denied' or 'Property does not
38
     * exist'
39
     */
40
    const ERROR_REASON = 'Generic Failure';
41
42
    /**
43
     * Creates the exception, populating its error message from class
44
     * and property names
45
     *
46
     * @param string $class The classname accessed
47
     * @param string $property The property accessed
48
     * @param Throwable $previous The exception which caused this
49
     */
50 7
    public function __construct
51
    (
52
        string $class,
53
        string $property,
54
        Throwable $previous = null
55
    )
56
    {
57 7
        parent::__construct
58
        (
59
              'Cannot ' . static::ACCESS_TYPE . ' property: '
60 7
            . $class . '::$' . $property . '. ' . static::ERROR_REASON,
61 7
            0,
62
            $previous
63
        );
64 7
    }
65
}
66