Completed
Pull Request — master (#233)
by
unknown
10:59
created

Serie::getAllSeries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * COPS (Calibre OPDS PHP Server) class file
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     S�bastien Lucas <[email protected]>
7
 */
8
9
require_once('base.php');
10
11
class Serie extends Base {
12
    const ALL_SERIES_ID = "cops:series";
13
    const SQL_ALL_SERIES = 
14
    	"select series.id as id, series.name as name, series.sort as sort, count(*) as count 
15
    	 from series 
16
    	 	inner join books_series_link as link on series.id = link.series
17
    		inner join ({0}) as filter on filter.id = link.book
18
    	 group by series.id, series.name, series.sort 
19
    	 order by series.sort";
20 46
    const SQL_SERIES_FOR_SEARCH = 
21 46
    	"select series.id as id, series.name as name, series.sort as sort, count(*) as count 
22 46
    	 from series
23 46
    		inner join books_series_link as link on series.id = series
24
    		inner join ({0}) as filter on filter.id = link.book 
25 46
    	 where upper (series.name) like ? 
26 46
    	 group by series.id, series.name, series.sort 
27
    	 order by series.sort";
28
29 7
    public $id;
30 7
    public $name;
31
32
    public function __construct($post) {
33 7
        $this->id = $post->id;
34
        $this->name = $post->name;
35 7
    }
36
37
    public function getUri () {
38 45
        return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
39 45
    }
40
41 45
    public function getEntryId () {
42 45
        return self::ALL_SERIES_ID.":".$this->id;
43 45
    }
44 40
45
    public static function getCount() {
46 19
        // str_format (localize("series.alphabetical", count(array))
47
        return parent::getCountGeneric ("series", self::ALL_SERIES_ID, parent::PAGE_ALL_SERIES);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getCountGeneric() instead of getCount()). Are you sure this is correct? If so, you might want to change this to $this->getCountGeneric().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48
    }
49 1
50 1
    public static function getSerieByBookId ($bookId) {
51 1
        $result = parent::getDb ()->prepare('select  series.id as id, name
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getSerieByBookId()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
52 1
from books_series_link, series
53 1
where series.id = series and book = ?');
54
        $result->execute (array ($bookId));
55
        if ($post = $result->fetchObject ()) {
56
            return new Serie ($post);
57
        }
58 2
        return NULL;
59 2
    }
60
61
    public static function getSerieById ($serieId) {
62 22
        $result = parent::getDb ()->prepare('select id, name  from series where id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getSerieById()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
63 22
        $result->execute (array ($serieId));
64
        if ($post = $result->fetchObject ()) {
65
            return new Serie ($post);
66
        }
67
        return NULL;
68
    }
69
70
    public static function getAllSeries() {
71
        return Base::getEntryArrayWithBookNumber (self::SQL_ALL_SERIES, array (), "Serie");
72
    }
73
74
    public static function getAllSeriesByQuery($query) {
75
        return Base::getEntryArrayWithBookNumber (self::SQL_SERIES_FOR_SEARCH, array ('%' . $query . '%'), "Serie");
76
    }
77
}
78