Passed
Branch master (8b6b92)
by Henri
13:52 queued 12:23
created

MagicsTrait::__set()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 22
rs 9.8333
1
<?php
2
3
namespace HnrAzevedo\Datamanager;
4
5
trait MagicsTrait{
6
7
    public function __set(string $prop,$value)
8
    {
9
        if(is_array($value)){
10
            $attr = array_keys($value)[0];
11
            $this->data[$prop][$attr] = $value[$attr];
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
12
            return $this;
13
        }
14
15
        if($this->full){
0 ignored issues
show
Bug Best Practice introduced by
The property full does not exist on HnrAzevedo\Datamanager\MagicsTrait. Since you implemented __get, consider adding a @property annotation.
Loading history...
16
            switch($this->data[$prop]['type']){
17
                case 'date':
18
                    $value = (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value) , 'Y-m-d'));
19
                    break;
20
            }
21
        }
22
23
        $this->isSettable($prop);
0 ignored issues
show
Bug introduced by
It seems like isSettable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        $this->/** @scrutinizer ignore-call */ 
24
               isSettable($prop);
Loading history...
24
25
        $this->data[$prop]['changed'] = true;
26
        $this->data[$prop]['value'] = $value;
27
        
28
        return $this;
29
    }
30
31
    public function __get(string $field)
32
    {
33
        $this->isSettable($field);
34
35
        if($this->full){
0 ignored issues
show
Bug Best Practice introduced by
The property full does not exist on HnrAzevedo\Datamanager\MagicsTrait. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            switch($this->data[$field]['type']){
37
                case 'date': $this->data[$field]['value'] = (date_format( date_create_from_format('Y-m-d' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['dateformat']));
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
            }
39
        }
40
41
        return $this->data[$field]['value'];
42
    }
43
}