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

Iterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A toArray() 0 12 4
1
<?php
2
3
namespace Scrawler\Arca\Traits\Model;
4
use Scrawler\Arca\Model;
5
use Scrawler\Arca\Collection;
6
7
trait Iterator{
8
     /**
9
     * Get all properties in array form
10
     * @return array<mixed>
11
     */
12
    public function toArray(): array
13
    {
14
        $props = $this->getProperties();
0 ignored issues
show
Bug introduced by
It seems like getProperties() 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

14
        /** @scrutinizer ignore-call */ 
15
        $props = $this->getProperties();
Loading history...
15
        foreach ($props as $key => $value) {
16
            if ($value instanceof Model) {
17
                $props[$key] = $value->toArray();
18
            }
19
            if ($value instanceof Collection) {
20
                $props[$key] = $value->toArray();
21
            }
22
        }
23
        return $props;
24
    }
25
26
    public function getIterator(): \Traversable
27
    {
28
        return new \ArrayIterator($this->toArray());
29
    }
30
}