Completed
Pull Request — master (#204)
by Vitor
07:26
created

TelegramInlineTemplate::previousDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace Pagerfanta\View\Template;
3
4
use Pagerfanta\View\Template\Template;
5
/**
6
 * @author Vitor Mattos <[email protected]>
7
 */
8
class TelegramInlineTemplate extends Template
9
{
10
    static protected $defaultOptions = array(
11
        'first_page_template' => '« %text%',
12
        'last_page_template'  => '%text% »',
13
        'previous_template'   => '‹ %text%',
14
        'next_template'       => '%text% ›',
15
        'page_template'       => '%text%',
16
        'current_template'    => '· %text% ·',
17
    );
18
19
    public function container() { }
20
21 7
    public function page($page)
22
    {
23 7
        $text = $page;
24
25 7
        return $this->pageWithText($page, $text);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithText($page, $text); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template\TemplateInterface::page 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...
26
    }
27
28 10
    public function pageWithText($page, $text)
29
    {
30
        return array(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('text' => s...age), 'page' => $page); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template...Interface::pageWithText 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...
31 10
            'text' => str_replace('%text%', $text, $this->option('page_template')),
32 10
            'callback_data' => $this->generateRoute($page),
33
            'page' => $page
34 10
        );
35
    }
36
37
    public function previousDisabled() { }
38
39 3
    public function previousEnabled($page)
40
    {
41 3
        return $this->pageWithText($page, str_replace('%text%', $page, $this->option('previous_template')));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithTe...'previous_template'))); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template...erface::previousEnabled 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...
42
    }
43
44
    public function nextDisabled() { }
45
46 9
    public function nextEnabled($page)
47
    {
48 9
        return $this->pageWithText($page, str_replace('%text%', $page, $this->option('next_template')));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithTe...ion('next_template'))); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template...eInterface::nextEnabled 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...
49
    }
50
51 3
    public function first()
52
    {
53 3
        $text = str_replace('%text%', 1, $this->option('first_page_template'));
54
55 3
        return $this->pageWithText(1, $text);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithText(1, $text); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template\TemplateInterface::first 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...
56
    }
57
58 7
    public function last($page)
59
    {
60 7
        $text = str_replace('%text%', $page, $this->option('last_page_template'));
61
62 7
        return $this->pageWithText($page, $text);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithText($page, $text); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template\TemplateInterface::last 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...
63
    }
64
65 10
    public function current($page)
66
    {
67 10
        $text = str_replace('%text%', $page, $this->option('current_template'));
68
69 10
        return $this->pageWithText($page, $text);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->pageWithText($page, $text); (array) is incompatible with the return type declared by the interface Pagerfanta\View\Template...plateInterface::current 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...
70
    }
71
72
    public function separator() { }
73
74
    private function generateSpan($class, $page)
75
    {
76
        $search = array('%class%', '%text%');
77
        $replace = array($class, $page);
78
79
        return str_replace($search, $replace, $this->option('span_template'));
80
    }
81
}
82