Passed
Push — main ( 7dc7cf...2fdc69 )
by Pranjal
02:49
created

Setter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperties() 0 6 2
A setLoadedProperties() 0 9 2
A setLoaded() 0 5 1
1
<?php
2
3
namespace Scrawler\Arca\Traits\Model;
4
use Scrawler\Arca\Model;
5
trait Setter{
6
7
      /**
8
     * Set all properties of model via array
9
     * @param array<mixed> $properties
10
     * @return Model
11
     */
12
    public function setProperties(array $properties): Model
13
    {
14
        foreach ($properties as $key => $value) {
15
            $this->set($key, $value);
0 ignored issues
show
Bug introduced by
It seems like set() 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

15
            $this->/** @scrutinizer ignore-call */ 
16
                   set($key, $value);
Loading history...
16
        }
17
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Scrawler\Arca\Traits\Model\Setter which includes types incompatible with the type-hinted return Scrawler\Arca\Model.
Loading history...
18
    }
19
20
     /**
21
     * Set all properties of model loaded via database
22
     * @param array<mixed> $properties
23
     * @return Model
24
     */
25
    public function setLoadedProperties(array $properties): Model
26
    {
27
        $this->__properties['all'] = $properties;
0 ignored issues
show
Bug Best Practice introduced by
The property __properties does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
        $this->__properties['self'] = $properties;
29
        foreach ($properties as $key => $value) {
30
            $this->__properties['type'][$key] = $this->connection->getTableManager()->getTable($this->table)->getColumn($key)->getComment();
31
        }
32
        $this->__meta['id'] = $properties['id'];
0 ignored issues
show
Bug Best Practice introduced by
The property __meta does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Scrawler\Arca\Traits\Model\Setter which includes types incompatible with the type-hinted return Scrawler\Arca\Model.
Loading history...
34
    }
35
36
     /**
37
     * call when model is loaded from database
38
     * @return Model
39
     */
40
    public function setLoaded(): Model
41
    {
42
        $this->__meta['is_loaded'] = true;
0 ignored issues
show
Bug Best Practice introduced by
The property __meta does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
        $this->__meta['id_error'] = false;
44
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Scrawler\Arca\Traits\Model\Setter which includes types incompatible with the type-hinted return Scrawler\Arca\Model.
Loading history...
45
    }
46
}