GetInfoHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 12
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A buildSpecification() 0 4 1
1
<?php
2
/**
3
 * HiAPI Yii2 base project for building API
4
 *
5
 * @link      https://github.com/hiqdev/hiapi
6
 * @package   hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiapi\commands;
12
13
use hiqdev\DataMapper\Query\Specification;
14
use hiqdev\DataMapper\Repository\BaseRepository;
15
use hiqdev\DataMapper\Repository\EntityManagerInterface;
16
17
/**
18
 * Class GetInfoHandler
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class GetInfoHandler extends SearchHandler
23
{
24
    public function handle(EntityCommandInterface $command)
25
    {
26
        return $this->getRepository($command)->findOneOrFail($this->buildSpecification($command));
0 ignored issues
show
Compatibility introduced by
$command of type object<hiapi\commands\EntityCommandInterface> is not a sub-type of object<hiapi\commands\EntityCommand>. It seems like you assume a concrete implementation of the interface hiapi\commands\EntityCommandInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
27
    }
28
29
    protected function buildSpecification(EntityCommandInterface $command)
30
    {
31
        return $this->createSpecification()->where(['id' => $command->id])->limit(1);
0 ignored issues
show
Bug introduced by
Accessing id on the interface hiapi\commands\EntityCommandInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
32
    }
33
}
34