Model   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 42
ccs 23
cts 23
cp 1
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConstants() 0 5 1
A create() 0 7 1
A getConstructorArguments() 0 10 3
A getFields() 0 13 2
1
<?php
2
3
namespace PHPieces\ANZGateway\models;
4
5
use ReflectionClass;
6
7
class Model
8
{
9
10 18
    private static function getConstants() : array
11
    {
12 18
        $class = static::$fields;
13 18
        return array_flip((new ReflectionClass($class))->getConstants());
14
    }
15
16 18
    private static function getConstructorArguments(array $params, array $constants) : array
17
    {
18 18
        $arguments = [];
19 18
        foreach ($constants as $key => $val) {
20 18
            if (isset($params[$key])) {
21 18
                $arguments[$key] = $params[$key];
22
            }
23
        }
24 18
        return $arguments;
25
    }
26
27 18
    public static function create(array $params) : self
28
    {
29 18
        $reflector = new ReflectionClass(static::class);
30 18
        $constants = self::getConstants();
31 18
        $data = self::getConstructorArguments($params, $constants);
32 18
        return $reflector->newInstanceArgs($data);
33
    }
34
35 9
    public static function getFields() : array
36
    {
37 9
        $fields = (new ReflectionClass(static::$fields))->getConstants();
38
39 9
        $final = [];
40 9
        foreach ($fields as $label => $name) {
41 9
            $label = str_replace("_", " ", $label);
42 9
            $label = strtolower($label);
43 9
            $label = ucwords($label);
44 9
            $final[$label] = $name;
45
        }
46 9
        return $final;
47
    }
48
}
49