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

Rating::getAllRatings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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     Michael Pfitzner
7
 */
8
9
require_once('base.php');
10
11
class Rating extends Base {
12
    const ALL_RATING_ID = "cops:rating";
13
14
    const SQL_ALL_RATINGS = 
15
    	"select ratings.id as id, ratings.rating as rating, count(*) as count 
16
    	 from ratings 
17
    		inner join books_ratings_link as link on link.rating = ratings.id
18
    		inner join ({0}) as filter on filter.id = link.book 
19 2
    	 group by ratings.id 
20 2
    	 order by ratings.rating";
21 2
    public $id;
22 2
    public $name;
23
24 1
    public function __construct($pid, $pname) {
25 1
        $this->id = $pid;
26
        $this->name = $pname;
27
    }
28 2
29 2
    public function getUri () {
30
        return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
31
    }
32 8
33
    public function getEntryId () {
34 8
        return self::ALL_RATING_ID.":".$this->id;
35
    }
36
37 1
    public static function getCount() {
38 1
        // str_format (localize("ratings", count(array))
39
        return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings");
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...
40
    }
41 1
42 1
    public static function getAllRatings() {
43 1
        return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
44 1
    }
45
46 1
    public static function getEntryArray ($query, $params) {
47 1
        list (, $result) = parent::executeFilteredQuery($query, $params, -1);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeFilteredQuery() instead of getEntryArray()). Are you sure this is correct? If so, you might want to change this to $this->executeFilteredQuery().

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 1
        $entryArray = array();
49 1
        while ($post = $result->fetchObject ())
50 1
        {
51 1
            $ratingObj = new Rating ($post->id, $post->rating);
52 1
            $rating=$post->rating/2;
53 1
            $rating = str_format (localize("ratingword", $rating), $rating);
54
            array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
55
                str_format (localize("bookword", $post->count), $post->count), "text",
56 1
                array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
57 1
        }
58 1
        return $entryArray;
59 1
    }
60
61
    public static function getRatingById ($ratingId) {
62
        $result = parent::getDb ()->prepare('select rating from ratings where id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getRatingById()). 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
        $result->execute (array ($ratingId));
64
        return new Rating ($ratingId, $result->fetchColumn ());
65
    }
66
}
67