Passed
Branch master (267be1)
by Eugene
03:26
created

ActionSearchAbstract::action()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
namespace Staticus\Middlewares;
3
4
use Staticus\Resources\ResourceDOInterface;
5
use Zend\Diactoros\Response\EmptyResponse;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Staticus\Resources\File\ResourceDO;
9
use Zend\Diactoros\Response\JsonResponse;
10
11
abstract class ActionSearchAbstract extends MiddlewareAbstract
12
{
13
    /**
14
     * @var ResourceDO
15
     */
16
    protected $resourceDO;
17
18
    /**
19
     * Search provider
20
     * @var mixed
21
     */
22
    protected $searcher;
23
24
    public function __construct(
25
        ResourceDOInterface $resourceDO, $generator)
26
    {
27
        $this->resourceDO = $resourceDO;
0 ignored issues
show
Documentation Bug introduced by
$resourceDO is of type object<Staticus\Resources\ResourceDOInterface>, but the property $resourceDO was declared to be of type object<Staticus\Resources\File\ResourceDO>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
28
        $this->searcher = $generator;
29
    }
30
31
    /**
32
     * @param ServerRequestInterface $request
33
     * @param ResponseInterface $response
34
     * @param callable|null $next
35
     * @return EmptyResponse
36
     * @throws \Exception
37
     */
38 View Code Duplication
    public function __invoke(
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
        ServerRequestInterface $request,
40
        ResponseInterface $response,
41
        callable $next = null
42
    )
43
    {
44
        parent::__invoke($request, $response, $next);
45
        $this->response = $this->action();
46
47
        return $this->next();
48
    }
49
50
    abstract protected function search(ResourceDOInterface $resourceDO);
51
52
    protected function action()
53
    {
54
        $response = $this->search($this->resourceDO);
55
56
        return new JsonResponse(['found' => $response]);
57
    }
58
}