Passed
Pull Request — master (#48)
by
unknown
03:49
created

GeneratorTrait::itemChangeGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php declare(strict_types = 1);
2
/**
3
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017
12
 */
13
14
namespace VfacTmdb\Traits;
15
16
use VfacTmdb\Results\Change;
17
use VfacTmdb\Interfaces\TmdbInterface;
18
19
/**
20
 * Generator trait
21
 * @package Tmdb
22
 * @author Vincent Faliès <[email protected]>
23
 * @copyright Copyright (c) 2017
24
 */
25
trait GeneratorTrait
26
{
27
    /**
28
     * GeneratorTrait object variable
29
     * @var \stdClass
30
     */
31
    protected $generator_trait;
32
33
    /**
34
     * Set GeneratorTrait variable
35
     * @param TmdbInterface $tmdb
36
     * @return void
37
     */
38 216
    protected function setGeneratorTrait(TmdbInterface $tmdb) : void
39
    {
40 216
        $this->generator_trait         = new \stdClass();
41 216
        $this->generator_trait->tmdb   = $tmdb;
42 216
        $this->generator_trait->logger = $tmdb->getLogger();
43 216
    }
44
45
    /**
46
     * Item generator method
47
     * @param array $results
48
     * @param string $class
49
     */
50 105
    protected function searchItemGenerator(array $results, string $class)
51
    {
52 105
        $this->generator_trait->logger->debug('Starting search item generator', array('results' => $results, 'class' => $class));
53 105
        foreach ($results as $result) {
54 96
            $element = new $class($this->generator_trait->tmdb, $result);
55
56 96
            yield $element;
57
        }
58 30
    }
59
60
    /**
61
     * Item change generator method
62
     * @param array $results
63
     * @param string $class
64
     * @author Steve Richter <[email protected]>
65
     */
66 24
    protected function itemChangeGenerator(array $results)
67
    {
68 24
        $this->generator_trait->logger->debug('Starting item change generator', array('results' => $results));
69 24
        foreach ($results as $result) {
70 15
            $element = new Change($this->generator_trait->tmdb, $result);
71
72 15
            yield $element;
73
        }
74 9
    }
75
}
76