Passed
Branch account (796afc)
by vincent
02:20
created

GeneratorTrait::setGeneratorTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
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\Interfaces\TmdbInterface;
17
18
/**
19
 * Generator trait
20
 * @package Tmdb
21
 * @author Vincent Faliès <[email protected]>
22
 * @copyright Copyright (c) 2017
23
 */
24
trait GeneratorTrait
25
{
26
    /**
27
     * GeneratorTrait object variable
28
     * @var \stdClass
29
     */
30
    protected $generator_trait;
31
32
    /**
33
     * Set GeneratorTrait variable
34
     * @param TmdbInterface $tmdb
35
     * @return void
36
     */
37 66
    protected function setGeneratorTrait(TmdbInterface $tmdb) : void
38
    {
39 66
        $this->generator_trait         = new \stdClass();
40 66
        $this->generator_trait->tmdb   = $tmdb;
41 66
        $this->generator_trait->logger = $tmdb->getLogger();
42 66
    }
43
44
    /**
45
     * Item generator method
46
     * @param array $results
47
     * @param string $class
48
     */
49 35
    protected function searchItemGenerator(array $results, string $class)
50
    {
51 35
        $this->generator_trait->logger->debug('Starting search item generator', array('results' => $results, 'class' => $class));
52 35
        foreach ($results as $result) {
53 32
            $element = new $class($this->generator_trait->tmdb, $result);
54
55 32
            yield $element;
56
        }
57 10
    }
58
}
59