Completed
Push — master ( 85994b...9d10cb )
by Dmitry
02:11
created

FieldFactory::createByModelAttributes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 5
cp 0
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
crap 12
1
<?php
2
3
namespace hiapi\query;
4
5
use hiqdev\billing\hiapi\models\ModelInterface;
6
7
class FieldFactory implements FieldFactoryInterface
8
{
9
    /**
10
     * @param ModelInterface $model
11
     * @param $map
12
     * @return Field[]
13
     */
14
    public function createByModelAttributes($model, $map)
15
    {
16
        $result = [];
17
18
        foreach ($map as $attributeName => $sql) {
19
            $attribute = $model->hasAttribute($attributeName)
20
                ? $model->getAttribute($attributeName)
21
                : $model->getRelatedAttribute($attributeName);
22
23
            $result[] = new Field($attributeName, $sql, $attribute);
24
        }
25
26
        return $result;
27
    }
28
}
29