Passed
Push — master ( c4fb31...6466f2 )
by Antônio
01:43
created

AEntidadePropriedades::getAtributes()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 1
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
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
21
        $atributosPreenchidos = [];
22
        foreach ($atributos as $atributoNome => $valor) {
23
            if ($valor != null) {
24
                $atributosPreenchidos[$atributoNome] = $this->getAtributoValor($valor);
25
            }
26
        }
27
28
        return $atributosPreenchidos;
29
    }
30
31
    private function percorrerArrayAtributo($valor) {
32
        $atributoValor = [];
33
34
        foreach ($valor as $v) {
35
            if (is_object($v)) {
36
                $atributoValor[] = $this->getAtributes($v);
37
            } else {
38
                $atributoValor[] = $v;
39
            }
40
        }
41
42
        return $atributoValor;
43
    }
44
45
    private function getAtributoValor($atributoValor) {
46
        if (is_array($atributoValor)) {
47
            return $this->percorrerArrayAtributo($atributoValor);
48
        } else if (is_object($atributoValor)) {
49
            return $this->getAtributes($atributoValor);
50
        } else {
51
            return $atributoValor;
52
        }
53
    }
54
55
    /// ====
56
    /// MAGIC METHODS
57
    /// ====
58
59
    public function __get($name) {
60
        if (property_exists($this, $name)) {
61
            return $this->$name;
62
        }
63
    }
64
65
    public function __call($metodo, $param) {
66
        if (strtolower(substr($metodo, 0, 3)) == "get") {
67
            $get = substr($metodo, 3);
68
            $property = $this->pascalCaseParaUnderscore($get);
69
70
            return $this->$property;
71
        }
72
    }
73
74
}
75