seblucas /
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 | require_once('base.php'); |
||
| 10 | |||
| 11 | class language extends Base { |
||
| 12 | const ALL_LANGUAGES_ID = "cops:languages"; |
||
| 13 | |||
| 14 | const SQL_ALL_LANGUAGES = |
||
| 15 | "select languages.id as id, languages.lang_code as lang_code, count(*) as count |
||
| 16 | from languages |
||
| 17 | 3 | inner join books_languages_link as link on languages.id = link.lang_code |
|
| 18 | 3 | inner join ({0}) as filter on link.book = filter.id |
|
| 19 | 3 | group by languages.id, link.lang_code |
|
| 20 | 3 | order by languages.lang_code"; |
|
| 21 | |||
| 22 | 2 | public $id; |
|
| 23 | 2 | public $lang_code; |
|
| 24 | |||
| 25 | public function __construct($pid, $plang_code) { |
||
| 26 | 3 | $this->id = $pid; |
|
| 27 | 3 | $this->lang_code = $plang_code; |
|
| 28 | } |
||
| 29 | |||
| 30 | 12 | public function getUri () { |
|
| 31 | 12 | return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
|
| 32 | 12 | } |
|
| 33 | |||
| 34 | public function getEntryId () { |
||
| 35 | 12 | return self::ALL_LANGUAGES_ID.":".$this->id; |
|
| 36 | } |
||
| 37 | |||
| 38 | 7 | public static function getLanguageString ($code) { |
|
| 39 | $string = localize("languages.".$code); |
||
| 40 | 7 | if (preg_match ("/^languages/", $string)) { |
|
| 41 | return $code; |
||
| 42 | } |
||
| 43 | 1 | return $string; |
|
| 44 | 1 | } |
|
| 45 | 1 | ||
| 46 | 1 | public static function getCount() { |
|
| 47 | 1 | // str_format (localize("languages.alphabetical", count(array)) |
|
| 48 | return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); |
||
|
0 ignored issues
–
show
|
|||
| 49 | } |
||
| 50 | |||
| 51 | public static function getLanguageById ($languageId) { |
||
| 52 | $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
||
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getDb() instead of getLanguageById()). 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...
|
|||
| 53 | $result->execute (array ($languageId)); |
||
| 54 | 2 | if ($post = $result->fetchObject ()) { |
|
| 55 | 2 | return new Language ($post->id, Language::getLanguageString ($post->lang_code)); |
|
| 56 | } |
||
| 57 | return NULL; |
||
| 58 | } |
||
| 59 | 2 | ||
| 60 | 2 | ||
| 61 | 2 | ||
| 62 | public static function getAllLanguages() { |
||
| 63 | 2 | list (, $result) = self::executeFilteredQuery(self::SQL_ALL_LANGUAGES, array(), -1); |
|
| 64 | 2 | $entryArray = array(); |
|
| 65 | 2 | while ($post = $result->fetchObject ()) |
|
| 66 | 2 | { |
|
| 67 | 2 | $language = new Language ($post->id, $post->lang_code); |
|
| 68 | 2 | array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
|
| 69 | str_format (localize("bookword", $post->count), $post->count), "text", |
||
| 70 | array ( new LinkNavigation ($language->getUri ())), "", $post->count)); |
||
| 71 | } |
||
| 72 | return $entryArray; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Takes a language name and tries to find the language code |
||
| 77 | * @param string $language A language name |
||
| 78 | * @return string the code for this name |
||
| 79 | */ |
||
| 80 | public static function getLanguageCode($language) { |
||
| 81 | // Filtering this call will lead to endless recursion |
||
| 82 | list (, $result) = self::executeQuery("select {0} from languages", "id, lang_code", "", array(), -1); |
||
| 83 | $entryArray = array(); |
||
|
0 ignored issues
–
show
$entryArray is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 84 | while ($post = $result->fetchObject ()) |
||
| 85 | { |
||
| 86 | $code = $post->lang_code; |
||
| 87 | $lang = Language::getLanguageString ($code); |
||
| 88 | if (strcasecmp($lang, $language) == 0) |
||
| 89 | return $code; |
||
| 90 | } |
||
| 91 | return $language; |
||
| 92 | } |
||
| 93 | } |
||
| 94 |
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:
The
getFirstName()method in theSoncalls the wrong method in the parent class.