BookProjection::project()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\Book\Projection;
6
7
use App\Domain\Book\Event\BookWasCreated;
8
use App\Infrastructure\Book\Query\Projections\BookMysqlRepository;
9
use Prooph\Bundle\EventStore\Projection\ReadModelProjection;
0 ignored issues
show
Bug introduced by
The type Prooph\Bundle\EventStore...ion\ReadModelProjection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Prooph\EventStore\Projection\ReadModelProjector;
0 ignored issues
show
Bug introduced by
The type Prooph\EventStore\Projection\ReadModelProjector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * @method readModel()
14
 */
15
class BookProjection implements ReadModelProjection
16
{
17
    public function project(ReadModelProjector $projector): ReadModelProjector
18
    {
19
        $projector->fromStream('event_stream')
20
            ->when([
21
                BookWasCreated::class => function ($state, BookWasCreated $event) {
22
                    /** @var BookMysqlRepository $readModel */
23
                    $readModel = $this->readModel();
24
                    $readModel->stack('insert', [
25
                        'id' => $event->getId()->toString(),
26
                        'name' => $event->getName()->toString(),
27
                        'description' => $event->getDescription()->toString(),
28
                        'author' => $event->getAuthor(),
29
                        'category' => $event->getCategory(),
30
                    ]);
31
                },
32
            ]);
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 Prooph\EventStore\Projection\ReadModelProjector. 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...
33
    }
34
}
35