Passed
Pull Request — master (#26)
by
unknown
06:09
created

RequestModel::withAttributeDelimiter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\RequestModel;
6
7
use Yiisoft\Arrays\ArrayHelper;
8
9
abstract class RequestModel implements RequestModelInterface
10
{
11
    private array $requestData = [];
12
    private string $attributeDelimiter = '.';
13
14 12
    public function setRequestData(array $requestData): void
15
    {
16 12
        $this->requestData = $requestData;
17 12
    }
18
19 9
    public function getAttributeValue(string $attribute, $default = null)
20
    {
21 9
        return ArrayHelper::getValueByPath($this->requestData, $attribute, $default, $this->attributeDelimiter);
22
    }
23
24 1
    public function hasAttribute(string $attribute): bool
25
    {
26 1
        return ArrayHelper::pathExists($this->requestData, $attribute, true, $this->attributeDelimiter);
27
    }
28
29 2
    public function getRequestData(): array
30
    {
31 2
        return $this->requestData;
32
    }
33
34 1
    public function withAttributeDelimiter(string $delimiter): self
35
    {
36 1
        $new = clone $this;
37 1
        $new->attributeDelimiter = $delimiter;
38 1
        return $new;
39
    }
40
}
41