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

GeneratorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setGeneratorTrait() 0 6 1
A searchItemGenerator() 0 9 2
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