ViewModelAssembler   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setViewModelService() 0 4 1
D validateViewModelBySkel() 0 30 10
1
<?php
2
3
namespace gotakk\ViewModelBundle\ViewModel;
4
5
use gotakk\ViewModelBundle\ViewModel\ViewModelNode;
6
7
abstract class ViewModelAssembler
8
{
9
    protected $vmService;
10
    protected $skel = array();
11
12
    public function setViewModelService($vmService)
13
    {
14
        $this->vmService = $vmService;
15
    }
16
17
    public function validateViewModelBySkel(ViewModelNode $vm, $skel = null)
18
    {
19
        if ($skel === null) {
20
            $skel = $this->skel;
21
        }
22
23
        foreach ($skel as $key => $value) {
24
            if (!is_array($value)) {
25
                if (!isset($vm[$value])) {
26
                    throw new \InvalidArgumentException("$value not exists");
27
                }
28
            } elseif (empty($value)) {
29
                if (!isset($vm[$key])) {
30
                    throw new \InvalidArgumentException("$key not exists");
31
                }
32
                foreach ($vm[$key] as $k => $v) {
33
                    if (!is_numeric($k)) {
34
                        throw new \InvalidArgumentException("$key is not sequential array. Contains not numeric key ($k)");
35
                    }
36
                }
37
            } else {
38
                if (!isset($vm[$key])) {
39
                    throw new \InvalidArgumentException("$key not exists");
40
                }
41
                $this->validateViewModelBySkel($vm[$key], $value);
42
            }
43
        }
44
45
        return true;
46
    }
47
}
48