ParentTest::getParent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\MultiTenancyBundle\spec;
16
17
use Doctrine\ODM\PHPCR\HierarchyInterface;
18
19
class ParentTest implements HierarchyInterface
20
{
21
    protected $parent;
22
23
    public function getParentDocument()
24
    {
25
        return $this->parent;
26
    }
27
28
    public function getParent()
29
    {
30
        $this->getParentDocument();
0 ignored issues
show
Unused Code introduced by
The call to the method SWP\Bundle\MultiTenancyB...st::getParentDocument() 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...
31
    }
32
33
    public function setParentDocument($parent)
34
    {
35
        $this->parent = $parent;
36
    }
37
38
    public function setParent($parent)
39
    {
40
        $this->setParentDocument($parent);
41
    }
42
}
43