mbirth /
cops
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 | class Rating extends Base { |
||
|
0 ignored issues
–
show
|
|||
| 10 | const ALL_RATING_ID = "cops:rating"; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
cops:rating does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 11 | |||
| 12 | const RATING_COLUMNS = "ratings.id as id, ratings.rating as rating, count(*) as count"; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ratings.id as id, rating...ting, count(*) as count does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 13 | 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"; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
select {0} from ratings,...order by ratings.rating does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 14 | public $id; |
||
| 15 | public $name; |
||
| 16 | |||
| 17 | 2 | public function __construct($pid, $pname) { |
|
| 18 | 2 | $this->id = $pid; |
|
| 19 | 2 | $this->name = $pname; |
|
| 20 | 2 | } |
|
| 21 | |||
| 22 | 1 | public function getUri () { |
|
| 23 | 1 | return "?page=".parent::PAGE_RATING_DETAIL."&id=$this->id"; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
?page= does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
As per coding-style, please use concatenation or
sprintf for the variable $this instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||
| 24 | } |
||
| 25 | |||
| 26 | 2 | public function getEntryId () { |
|
| 27 | 2 | return self::ALL_RATING_ID.":".$this->id; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
: does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 28 | } |
||
| 29 | |||
| 30 | 8 | public static function getCount() { |
|
| 31 | // str_format (localize("ratings", count(array)) |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 32 | 8 | return parent::getCountGeneric ("ratings", self::ALL_RATING_ID, parent::PAGE_ALL_RATINGS, "ratings"); |
|
|
0 ignored issues
–
show
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 Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
ratings does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 33 | } |
||
| 34 | |||
| 35 | 1 | public static function getAllRatings() { |
|
| 36 | 1 | return self::getEntryArray (self::SQL_ALL_RATINGS, array ()); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | public static function getEntryArray ($query, $params) { |
|
| 40 | 1 | list (, $result) = parent::executeQuery ($query, self::RATING_COLUMNS, "", $params, -1); |
|
|
0 ignored issues
–
show
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 Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 41 | 1 | $entryArray = array(); |
|
| 42 | 1 | while ($post = $result->fetchObject ()) |
|
| 43 | { |
||
| 44 | 1 | $ratingObj = new Rating ($post->id, $post->rating); |
|
| 45 | 1 | $rating=$post->rating/2; |
|
| 46 | 1 | $rating = str_format (localize("ratingword", $rating), $rating); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ratingword does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 47 | 1 | array_push ($entryArray, new Entry ($rating, $ratingObj->getEntryId (), |
|
| 48 | 1 | str_format (localize("bookword", $post->count), $post->count), "text", |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
bookword does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
text does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 49 | 1 | array ( new LinkNavigation ($ratingObj->getUri ())), "", $post->count)); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 50 | 1 | } |
|
| 51 | 1 | return $entryArray; |
|
| 52 | } |
||
| 53 | |||
| 54 | 1 | public static function getRatingById ($ratingId) { |
|
| 55 | 1 | $result = parent::getDb ()->prepare('select rating from ratings where id = ?'); |
|
|
0 ignored issues
–
show
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 Loading history...
|
|||
| 56 | 1 | $result->execute (array ($ratingId)); |
|
| 57 | 1 | return new Rating ($ratingId, $result->fetchColumn ()); |
|
| 58 | } |
||
| 59 | } |
||
| 60 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.