Completed
Push — master ( 9e1b08...fbe734 )
by Sascha-Oliver
02:17
created

KeySearchResults::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license.  See the LICENSE file for details.
8
 */
9
10
namespace FAPI\PhraseApp\Model\Key;
11
12
use FAPI\PhraseApp\Model\CreatableFromArray;
13
use Traversable;
14
15
/**
16
 * @author Sascha-Oliver Prolic <[email protected]>
17
 */
18 View Code Duplication
class KeySearchResults implements CreatableFromArray, \IteratorAggregate
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * @var KeySearchResult[]
22
     */
23
    private $searchResults = [];
24
25
    /**
26
     * @param array $data
27
     *
28
     * @return KeySearchResults
29
     */
30
    public static function createFromArray(array $data)
31
    {
32
        $self = new self();
33
34
        foreach ($data as $searchResult) {
35
            $self->addSearchResult(KeySearchResult::createFromArray($searchResult));
36
        }
37
38
        return $self;
39
    }
40
41
    /**
42
     * @return KeySearchResult[]|\Iterator
43
     */
44
    public function getIterator(): \Iterator
45
    {
46
        return new \ArrayIterator($this->searchResults);
47
    }
48
49
    private function addSearchResult(KeySearchResult $searchResult)
50
    {
51
        $this->searchResults[] = $searchResult;
52
    }
53
}
54