Passed
Push — master ( 326f15...3f57a0 )
by Antônio
01:42
created

AEntidadePropriedades   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 15

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 6 2
A percorrerArrayAtributo() 0 12 3
A __get() 0 3 2
A getAtributoValor() 0 7 3
B getAtributes() 0 14 5
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace OBRSDK\Entidades\Abstratos;
10
11
/**
12
 * Description of ABancos
13
 *
14
 * @author Antonio
15
 */
16
abstract class AEntidadePropriedades extends AEntidadePreenchimento {
17
18
    public function getAtributes($entidade = null) {
19
        $atributos = get_object_vars($entidade == null ? $this : $entidade);
20
        $atributosPreenchidos = [];
21
        foreach ($atributos as $atributoNome => $valor) {
22
            $atributoValor = null;
23
            if ($valor != null) {
24
                $atributoValor = $this->getAtributoValor($valor);
25
            }
26
            
27
            if (count($atributoValor) > 0) {
28
                $atributosPreenchidos[$atributoNome] = $atributoValor;
29
            }
30
        }
31
        return $atributosPreenchidos;
32
    }
33
34
    private function percorrerArrayAtributo($valor) {
35
        $atributoValor = [];
36
37
        foreach ($valor as $v) {
38
            if (is_object($v)) {
39
                $atributoValor[] = $this->getAtributes($v);
40
            } else {
41
                $atributoValor[] = $v;
42
            }
43
        }
44
45
        return $atributoValor;
46
    }
47
48
    private function getAtributoValor($atributoValor) {
49
        if (is_array($atributoValor)) {
50
            return $this->percorrerArrayAtributo($atributoValor);
51
        } else if (is_object($atributoValor)) {
52
            return $this->getAtributes($atributoValor);
53
        } else {
54
            return $atributoValor;
55
        }
56
    }
57
58
    /// ====
59
    /// MAGIC METHODS
60
    /// ====
61
62
    public function __get($name) {
63
        if (property_exists($this, $name)) {
64
            return $this->$name;
65
        }
66
    }
67
68
    public function __call($metodo, $param) {
69
        if (strtolower(substr($metodo, 0, 3)) == "get") {
70
            $get = substr($metodo, 3);
71
            $property = $this->pascalCaseParaUnderscore($get);
72
73
            return $this->$property;
74
        }
75
    }
76
77
}
78