SimpleGenerator::generate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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