MapCodeGeneratorTrait::getGenerator()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
4
namespace Gica\Cqrs\CodeGeneration\Traits;
5
6
use Gica\Cqrs\CodeGeneration\CodeGenerator;
7
use Gica\FileSystem\FileSystemInterface;
8
use Gica\FileSystem\OperatingSystemFileSystem;
9
use Psr\Log\LoggerInterface;
10
11
trait MapCodeGeneratorTrait
12
{
13
    /**
14
     * @var LoggerInterface
15
     */
16
    private $logger;
17
    /**
18
     * @var FileSystemInterface
19
     */
20
    private $fileSystem;
21
22 6
    public function __construct(
23
        LoggerInterface $logger,
24
        FileSystemInterface $fileSystem = null
25
    )
26
    {
27 6
        $this->logger = $logger;
28 6
        $this->fileSystem = $fileSystem ?? new OperatingSystemFileSystem();
29 6
    }
30
31 6
    public function generate(
32
        string $templateClassName,
33
        \Iterator $files,
34
        string $outputFilePath,
35
        string $outputShortClassName
36
    )
37
    {
38 6
        $this->getGenerator()
39 6
            ->discoverAndPutContents(
40 6
                $this->discover($files),
0 ignored issues
show
Documentation introduced by
$files is of type object<Iterator>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41 5
                $templateClassName,
42 5
                $outputFilePath,
43 5
                $outputShortClassName
44
            );
45
46 5
        $this->log($outputFilePath, $files);
0 ignored issues
show
Unused Code introduced by
The call to MapCodeGeneratorTrait::log() has too many arguments starting with $files.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
47 5
    }
48
49
    abstract protected function log($outputFilePath);
50
51
    abstract protected function discover(string $searchDirectory): array;
52
53
    abstract protected function getGenerator(): CodeGenerator;
54
}