Completed
Push — v2 ( 3a6d90 )
by Guillaume
11s
created

SetProperties   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setProperties() 0 11 3
1
<?php
2
3
namespace ETNA\Doctrine\Extensions;
4
5
/**
6
 * Ce trait permet aux classes concernées de setter ses propriétés depuis un array associatif
7
 */
8
trait SetProperties
9
{
10
    /**
11
     * Sette toute les valeurs d'un array associatif à $this.
12
     *
13
     * @param  array $request_data
14
     *
15
     * @return self
16
     */
17
    public function setProperties(array $request_data)
18
    {
19
        foreach ($request_data as $field_name => $field_value) {
20
            $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $field_name)));
21
            if (method_exists($this, $setter_name)) {
22
                $this->{$setter_name}($field_value);
23
            }
24
        }
25
26
        return $this;
27
    }
28
}
29