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

PropertyAccessException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 43
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
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