Completed
Pull Request — master (#274)
by Markus
07:36
created

rating.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count";
15
    const SQL_ALL_RATINGS ="select {0} from ratings, books_ratings_link where books_ratings_link.rating = ratings.id group by ratings.id order by ratings.rating";
16
    public $id;
17
    public $name;
18
19 2
    public function __construct($pid, $pname) {
20 2
        $this->id = $pid;
21 2
        $this->name = $pname;
22 2
    }
23
24 1
    public function getUri () {
25 1
        return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id";
26
    }
27
28 2
    public function getEntryId () {
29 2
        return self::ALL_RATING_ID.":".$this->id;
30
    }
31
32 19
    public static function getCount() {
33
        // str_format (localize("ratings", count(array))
34 19
        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...
35
    }
36
37 1
    public static function getAllRatings() {
38 1
        return self::getEntryArray (self::SQL_ALL_RATINGS, array ());
39
    }
40
41 1
    public static function getEntryArray ($query, $params) {
42 1
        list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuery() instead of getEntryArray()). Are you sure this is correct? If so, you might want to change this to $this->executeQuery().

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...
43 1
        $entryArray = array();
44 1
        while ($post = $result->fetchObject ())
45
        {
46 1
            $ratingObj = new Rating ($post->id, $post->rating);
47 1
            $rating=$post->rating/2;
48 1
            $rating = str_format (localize("ratingword", $rating), $rating);
49 1
            array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (),
50 1
                str_format (localize("bookword", $post->count), $post->count), "text",
51 1
                array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count));
52 1
        }
53 1
        return $entryArray;
54
    }
55
56 1
    public static function getRatingById ($ratingId) {
57 1
        $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...
58 1
        $result->execute (array ($ratingId));
59 1
        return new Rating ($ratingId, $result->fetchColumn ());
60
    }
61
}
62