Completed
Push — refactor ( 1ac315 )
by Akihito
05:56
created

PrivateProperty   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Compiler;
6
7
use ReflectionProperty;
8
use Throwable;
9
10
final class PrivateProperty
11
{
12
    /**
13
     * @param object|null $object
14
     * @param ?mixed      $default
0 ignored issues
show
Documentation introduced by
The doc-type ?mixed could not be parsed: Unknown type name "?mixed" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
15
     *
16
     * @return mixed
17
     */
18
    public function __invoke($object, string $prop, $default = null)
19
    {
20
        try {
21
            if ($object === null) {
22
                return $default;
23
            }
24
25
            $refProp = (new ReflectionProperty($object, $prop));
26
        } catch (Throwable $e) {
27
            return $default;
28
        }
29
30
        $refProp->setAccessible(true);
31
32
        return $refProp->getValue($object);
33
    }
34
}
35