GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CustomMenuItem::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/**
3
 * @author Nikita Melnikov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.models.menu
8
 *
9
 * @property int $id
10
 * @property string $name
11
 * @property string $url
12
 * @property int $visible
13
 *
14
 * @property CustomMenuItemData[] $data
15
 */
16
class CustomMenuItem extends FActiveRecord implements IMenuItem
17
{
18 3
  public function tableName()
19
  {
20 3
    return '{{menu_custom_item}}';
21
  }
22
23 9
  public function defaultScope()
24
  {
25
    return array(
26
      'with' => 'data'
27 9
    );
28
  }
29
30 1
  public function relations()
31
  {
32
    return array(
33 1
      'data' => array(self::HAS_MANY, 'CustomMenuItemData', 'parent'),
34 1
    );
35
  }
36
37
  /**
38
   * @return array
39
   */
40 9
  public function getMenuUrl()
41
  {
42 9 View Code Duplication
    if( substr($this->url, 0, 1) === '/' && substr($this->url, -1, 1) === '/' )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
43 9
      return $this->url;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->url; (string) is incompatible with the return type declared by the interface IMenuItem::getMenuUrl of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
44
45 9
    $url = array($this->url);
46
47 9
    foreach($this->data as $item)
48
    {
49 9
      $url[$item->name] = $item->value;
50 9
    }
51
52 9
    return $url;
53
  }
54
55
  /**
56
   * @return array
57
   */
58 9
  public function getChildren()
59
  {
60 9
    return array();
61
  }
62
63
  /**
64
   * @return string
65
   */
66 9
  public function getName()
67
  {
68 9
    return $this->name;
69
  }
70
71
  /**
72
   * @param int $depth
73
   */
74 9
  public function setDepth($depth = null)
75
  {
76
77
  }
78
}