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 Sébastien Lucas <[email protected]> |
||
| 7 | */ |
||
| 8 | |||
| 9 | class CustomColumn extends Base { |
||
|
0 ignored issues
–
show
|
|||
| 10 | const ALL_CUSTOMS_ID = "cops:custom"; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
cops:custom 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 | public $id; |
||
| 13 | public $name; |
||
| 14 | public $customId; |
||
| 15 | |||
| 16 | 6 | public function __construct($pid, $pname, $pcustomId) { |
|
| 17 | 6 | $this->id = $pid; |
|
| 18 | 6 | $this->name = $pname; |
|
| 19 | 6 | $this->customId = $pcustomId; |
|
| 20 | 6 | } |
|
| 21 | |||
| 22 | 3 | public function getUri () { |
|
| 23 | 3 | return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&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 | 6 | public function getEntryId () { |
|
| 27 | 6 | return self::ALL_CUSTOMS_ID.":".$this->customId.":".$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 | 10 | public static function getTableName ($customId) { |
|
| 31 | 10 | return "custom_column_{$customId}"; |
|
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $customId 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...
|
|||
| 32 | } |
||
| 33 | |||
| 34 | 6 | public static function getTableLinkName ($customId) { |
|
| 35 | 6 | return "books_custom_column_{$customId}_link"; |
|
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $customId 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...
|
|||
| 36 | } |
||
| 37 | |||
| 38 | 6 | public static function getTableLinkColumn ($customId) { |
|
|
0 ignored issues
–
show
|
|||
| 39 | 6 | return "value"; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
value 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...
|
|||
| 40 | } |
||
| 41 | |||
| 42 | 7 | public static function getAllCustomsId ($customId) { |
|
| 43 | 7 | return self::ALL_CUSTOMS_ID . ":" . $customId; |
|
|
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...
|
|||
| 44 | } |
||
| 45 | |||
| 46 | 4 | public static function getUriAllCustoms ($customId) { |
|
| 47 | 4 | return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}"; |
|
|
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 $customId 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...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | 7 | public static function getAllTitle ($customId) { |
|
| 51 | 7 | $result = parent::getDb ()->prepare('select name from custom_columns where id = ?'); |
|
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getAllTitle()). 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...
|
|||
| 52 | 7 | $result->execute (array ($customId)); |
|
| 53 | 7 | $post = $result->fetchObject (); |
|
| 54 | 7 | return $post->name; |
|
| 55 | } |
||
| 56 | |||
| 57 | 4 | public static function getCustomId ($lookup) { |
|
| 58 | 4 | $result = parent::getDb ()->prepare('select id from custom_columns where label = ?'); |
|
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getCustomId()). 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...
|
|||
| 59 | 4 | $result->execute (array ($lookup)); |
|
| 60 | 4 | if ($post = $result->fetchObject ()) { |
|
| 61 | 4 | return $post->id; |
|
| 62 | } |
||
| 63 | return NULL; |
||
| 64 | } |
||
| 65 | |||
| 66 | 4 | public static function getCount($customId) { |
|
| 67 | 4 | $nCustoms = parent::executeQuerySingle ('select count(*) from ' . self::getTableName ($customId)); |
|
|
0 ignored issues
–
show
It seems like you call parent on a different method (
executeQuerySingle() instead of getCount()). Are you sure this is correct? If so, you might want to change this to $this->executeQuerySingle().
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...
|
|||
| 68 | 4 | $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), |
|
| 69 | 4 | str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
tags.alphabetical 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...
|
|||
| 70 | 4 | array ( new LinkNavigation (self::getUriAllCustoms ($customId))), "", $nCustoms); |
|
|
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...
|
|||
| 71 | 4 | return $entry; |
|
| 72 | } |
||
| 73 | |||
| 74 | 3 | View Code Duplication | public static function getCustomById ($customId, $id) { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 75 | 3 | $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?'); |
|
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getCustomById()). 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...
|
|||
| 76 | 3 | $result->execute (array ($id)); |
|
| 77 | 3 | if ($post = $result->fetchObject ()) { |
|
| 78 | 3 | return new CustomColumn ($post->id, $post->name, $customId); |
|
| 79 | } |
||
| 80 | return NULL; |
||
| 81 | } |
||
| 82 | |||
| 83 | 3 | public static function getAllCustoms($customId) { |
|
| 84 | 3 | $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count |
|
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getAllCustoms()). 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...
|
|||
| 85 | from {0}, {1} |
||
| 86 | where {0}.id = {1}.{2} |
||
| 87 | group by {0}.id, {0}.value |
||
| 88 | 3 | order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($customId), self::getTableLinkColumn ($customId))); |
|
| 89 | 3 | $entryArray = array(); |
|
| 90 | 3 | View Code Duplication | while ($post = $result->fetchObject ()) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 91 | { |
||
| 92 | 3 | $customColumn = new CustomColumn ($post->id, $post->name, $customId); |
|
| 93 | 3 | array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), |
|
| 94 | 3 | 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...
|
|||
| 95 | 3 | array ( new LinkNavigation ($customColumn->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...
|
|||
| 96 | 3 | } |
|
| 97 | 3 | return $entryArray; |
|
| 98 | } |
||
| 99 | } |
||
| 100 |
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.