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.

TbJsonPager::createPageButton()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 8.8571
cc 5
eloc 6
nc 4
nop 5
crap 30
1
<?php
2
/**
3
 *## TbJsonPager class file.
4
 *
5
 * @author: antonio ramirez <[email protected]>
6
 * @copyright Copyright &copy; Clevertech 2012-
7
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) 
8
 */
9
10
Yii::import('booster.widgets.TbPager');
11
12
/**
13
 *## Class TbJsonPager
14
 *
15
 * Use this specific pager for JSON grid, not the standard one!
16
 *
17
 * @package booster.widgets.supplementary
18
 */
19
class TbJsonPager extends TbPager
20
{
21
	/**
22
	 * @var string json.
23
	 */
24
	public $json;
25
26
	/**
27
	 *### .run()
28
	 *
29
	 * Runs the widget.
30
	 */
31
	public function run()
32
	{
33
		if (!$this->json) {
34
			parent::run();
35
		}
36
37
		return $this->createPageButtons();
38
	}
39
40
	/**
41
	 *### .createPageButton()
42
	 *
43
	 * Creates a page button.
44
	 * You may override this method to customize the page buttons.
45
	 *
46
	 * @param string $label the text label for the button
47
	 * @param integer $page the page number
48
	 * @param string $class the CSS class for the page button. This could be 'page', 'first', 'last', 'next' or 'previous'.
49
	 * @param boolean $hidden whether this page button is visible
50
	 * @param boolean $selected whether this page button is selected
51
	 *
52
	 * @return string the generated button
53
	 */
54
	protected function createPageButton($label, $page, $class, $hidden, $selected)
55
	{
56
		if ($this->json) {
57
			if ($hidden || $selected) {
58
				$class .= ' ' . ($hidden ? 'disabled' : 'active');
59
			}
60
			return array('class' => $class, 'url' => $this->createPageUrl($page), 'text' => $label);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('class' => ...ge), 'text' => $label); (array) is incompatible with the return type of the parent method TbPager::createPageButton of type string.

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...
61
		}
62
		return parent::createPageButton($label, $page, $class, $hidden, $selected);
63
	}
64
}
65