mbirth /
cops
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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 CustomColumnTypeBool extends CustomColumnType |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 10 | { |
||
| 11 | // PHP pre 5.6 does not support const arrays |
||
| 12 | private $BOOLEAN_NAMES = array( |
||
| 13 | -1 => "customcolumn.boolean.unknown", // localize("customcolumn.boolean.unknown") |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
customcolumn.boolean.unknown 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 | 00 => "customcolumn.boolean.no", // localize("customcolumn.boolean.no") |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
customcolumn.boolean.no 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...
|
|||
| 15 | +1 => "customcolumn.boolean.yes", // localize("customcolumn.boolean.yes") |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
customcolumn.boolean.yes 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...
|
|||
| 16 | ); |
||
| 17 | |||
| 18 | 1 | protected function __construct($pcustomId) |
|
| 19 | { |
||
| 20 | 1 | parent::__construct($pcustomId, self::CUSTOM_TYPE_BOOL); |
|
| 21 | 1 | } |
|
| 22 | |||
| 23 | /** |
||
| 24 | * Get the name of the sqlite table for this column |
||
| 25 | * |
||
| 26 | * @return string|null |
||
| 27 | */ |
||
| 28 | 5 | private function getTableName() |
|
| 29 | { |
||
| 30 | 5 | return "custom_column_{$this->customId}"; |
|
|
0 ignored issues
–
show
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...
|
|||
| 31 | } |
||
| 32 | |||
| 33 | 3 | public function getQuery($id) |
|
| 34 | { |
||
| 35 | 3 | if ($id == -1) { |
|
| 36 | 2 | $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_NULL, "{0}", "{1}", $this->getTableName()); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
{0} 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
{1} 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...
|
|||
| 37 | 2 | return array($query, array()); |
|
| 38 | 3 | } else if ($id == 0) { |
|
| 39 | 3 | $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_FALSE, "{0}", "{1}", $this->getTableName()); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
{0} 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
{1} 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 | 3 | return array($query, array()); |
|
| 41 | 2 | } else if ($id == 1) { |
|
| 42 | 2 | $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_TRUE, "{0}", "{1}", $this->getTableName()); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
{0} 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
{1} 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...
|
|||
| 43 | 2 | return array($query, array()); |
|
| 44 | } else { |
||
| 45 | return NULL; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 3 | public function getCustom($id) |
|
| 50 | { |
||
| 51 | 3 | return new CustomColumn($id, localize($this->BOOLEAN_NAMES[$id]), $this); |
|
| 52 | } |
||
| 53 | |||
| 54 | 1 | View Code Duplication | protected function getAllCustomValuesFromDatabase() |
|
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...
|
|||
| 55 | { |
||
| 56 | 1 | $queryFormat = "SELECT coalesce({0}.value, -1) AS id, count(*) AS count FROM books LEFT JOIN {0} ON books.id = {0}.book GROUP BY {0}.value ORDER BY {0}.value"; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
SELECT coalesce({0}.valu...alue ORDER BY {0}.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...
|
|||
| 57 | 1 | $query = str_format($queryFormat, $this->getTableName()); |
|
| 58 | 1 | $result = Base::getDb()->query($query); |
|
| 59 | |||
| 60 | 1 | $entryArray = array(); |
|
| 61 | 1 | while ($post = $result->fetchObject()) { |
|
| 62 | 1 | $entryPContent = str_format(localize("bookword", $post->count), $post->count); |
|
|
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...
|
|||
| 63 | 1 | $entryPLinkArray = array(new LinkNavigation ($this->getUri($post->id))); |
|
| 64 | |||
| 65 | 1 | $entry = new Entry(localize($this->BOOLEAN_NAMES[$post->id]), $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $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...
|
|||
| 66 | |||
| 67 | 1 | array_push($entryArray, $entry); |
|
| 68 | 1 | } |
|
| 69 | 1 | return $entryArray; |
|
| 70 | } |
||
| 71 | |||
| 72 | 3 | public function getDescription() |
|
| 73 | { |
||
| 74 | 3 | return localize("customcolumn.description.bool"); |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
customcolumn.description.bool 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...
|
|||
| 75 | } |
||
| 76 | |||
| 77 | 2 | public function getCustomByBook($book) |
|
| 78 | { |
||
| 79 | 2 | $queryFormat = "SELECT {0}.value AS boolvalue FROM {0} WHERE {0}.book = {1}"; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
SELECT {0}.value AS bool...0} WHERE {0}.book = {1} 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...
|
|||
| 80 | 2 | $query = str_format($queryFormat, $this->getTableName(), $book->id); |
|
| 81 | |||
| 82 | 2 | $result = Base::getDb()->query($query); |
|
| 83 | 2 | if ($post = $result->fetchObject()) { |
|
| 84 | 2 | return new CustomColumn($post->boolvalue, localize($this->BOOLEAN_NAMES[$post->boolvalue]), $this); |
|
| 85 | } else { |
||
| 86 | return new CustomColumn(-1, localize($this->BOOLEAN_NAMES[-1]), $this); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | 3 | public function isSearchable() |
|
| 91 | { |
||
| 92 | 3 | return true; |
|
| 93 | } |
||
| 94 | } |
||
| 95 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.