Spec::insert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SpeckCatalog\Service;
4
5
class Spec extends AbstractService
6
{
7
    protected $entityMapper = 'speckcatalog_spec_mapper';
8
9 2
    public function find(array $data, $populate = false, $recursive = false)
10
    {
11 2
        $spec = $this->getEntityMapper()->find($data);
12 2
        if ($populate) {
13 1
            $this->populate($spec, $recursive);
0 ignored issues
show
Unused Code introduced by
The call to the method SpeckCatalog\Service\Spec::populate() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
14 1
        }
15 2
        return $spec;
16
    }
17
18 1
    public function getByProductId($productId)
19
    {
20 1
        return $this->getEntityMapper()->getByProductId($productId);
21
    }
22
23 1
    public function insert($spec)
24
    {
25 1
        $id = parent::insert($spec);
26 1
        $spec = $this->find(array('spec_id' => $id));
27
28 1
        return $spec;
29
    }
30
}
31