SimpleGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generate() 0 3 1
A yieldContent() 0 4 2
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Infrastructure Related Agent
5
 * @author Max Demian <[email protected]>
6
 */
7
8
namespace Ticaje\FileManager\Infrastructure\Driver\Source;
9
10
use Iterator as BuiltInAgent;
11
use Ticaje\FileManager\Infrastructure\Driver\Reader\Interfaces\DocumentManagerInterface;
12
13
/**
14
 * Class SimpleGenerator
15
 * @package Ticaje\FileManager\Infrastructure\Source\Generator
16
 */
17
class SimpleGenerator implements SimpleGeneratorInterface
18
{
19
    /** @var DocumentManagerInterface $documentManager */
20
    private $documentManager;
21
22
    /**
23
     * Generator constructor.
24
     *
25
     * @param DocumentManagerInterface $documentManager
26
     */
27
    public function __construct(
28
        DocumentManagerInterface $documentManager
29
    ) {
30
        $this->documentManager = $documentManager;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function generate(): BuiltInAgent
37
    {
38
        $this->yieldContent();
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Iterator. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
    }
40
41
    /**
42
     * @return BuiltInAgent
43
     * This is specific implementation
44
     */
45
    private function yieldContent(): BuiltInAgent
46
    {
47
        foreach ($this->documentManager->generateContent() as $item) {
48
            yield $item;
49
        }
50
    }
51
}
52