RequestUrlHelper::getObjectProperty()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
namespace DMT\Aura\Psr\Helpers;
4
5
use Aura\Web\Request\Url as RequestUrl;
6
use InvalidArgumentException;
7
8
/**
9
 * Class RequestUrlHelper
10
 *
11
 * This helper allows access to the Aura Request Url parts property.
12
 *
13
 * @package DMT\Aura\Psr\Helpers
14
 */
15
class RequestUrlHelper extends RequestUrl implements PropertyAccessorInterface
16
{
17
    use PropertyAccessorTrait;
18
19
    /**
20
     * Access a property.
21
     *
22
     * @param string $property the property to access.
23
     * @param mixed|null $default the default value.
24
     *
25
     * @return mixed
26
     * @throws InvalidArgumentException when property does not exists
27
     */
28 3
    public function getObjectProperty($property, $default = null)
29
    {
30 3
        if (!property_exists($this->object, $property)) {
31
            throw new InvalidArgumentException('property does not exists');
32
        }
33
34 3
        return $this->object->{$property} ?? $default;
35
    }
36
}
37