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

SetProperties::setProperties()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 1
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