Completed
Pull Request — 2.x (#216)
by Akihito
03:32
created

PrivateProperty::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 3
nc 3
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Compiler;
6
7
final class PrivateProperty
8
{
9
    /**
10
     * @param null|object $object
11
     * @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...
12
     *
13
     * @return mixed
14
     */
15
    public function __invoke($object, string $prop, $default = null)
16
    {
17
        try {
18
            if ($object === null) {
19
                return $default;
20
            }
21
            $refProp = (new \ReflectionProperty($object, $prop));
22
        } catch (\Exception $e) {
23
            return $default;
24
        }
25
        $refProp->setAccessible(true);
26
27
        return $refProp->getValue($object);
28
    }
29
}
30