DataProvider::get()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.9332
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
4
namespace Lexuss1979\Validol;
5
6
7
class DataProvider
8
{
9
10
    private $data;
11
12 156
    public function __construct($data)
13
    {
14 156
        $this->data = $data;
15 156
    }
16
17 156
    public function get($key)
18
    {
19 156
        if (preg_match("/^(\S*)\s*as\s*(\S*)$/", $key, $matches)) {
20 1
            $name = $matches[1];
21 1
            $alias = $matches[2];
22
        } else {
23 155
            $name = $key;
24 155
            $alias = $key;
25
        }
26 156
        if (!isset($this->data[$name])) return new NullValueObject($name, null);
27
28 153
        $value = new ValueObject($name, $this->data[$name]);
29 153
        $value->setAlias($alias);
30 153
        return $value;
31
    }
32
33
34
}