Passed
Pull Request — master (#312)
by Sergei
02:59
created

ArrayIteratorTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 3
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Trait;
6
7
use ArrayIterator;
8
use IteratorAggregate;
9
10
/**
11
 * Trait to implement {@see IteratorAggregate} interface for ActiveRecord.
12
 *
13
 * @method array getAttributes(array|null $names = null, array $except = [])
14
 * @see ActiveRecordInterface::getAttributes() for more info.
15
 */
16
trait ArrayIteratorTrait
17
{
18
    /**
19
     * Returns an iterator for traversing the attributes in the ActiveRecord.
20
     *
21
     * This method is required by the interface {@see IteratorAggregate}.
22
     *
23
     * @return ArrayIterator an iterator for traversing the items in the list.
24
     */
25
    public function getIterator(): ArrayIterator
26
    {
27
        $attributes = $this->getAttributes();
28
29
        return new ArrayIterator($attributes);
30
    }
31
}
32