Completed
Push — master ( d648a6...70bf01 )
by Sébastien
07:21 queued 12s
created

language.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     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
    public $id;
15
    public $lang_code;
16
17 3
    public function __construct($pid, $plang_code) {
18 3
        $this->id = $pid;
19 3
        $this->lang_code = $plang_code;
20 3
    }
21
22 2
    public function getUri () {
23 2
        return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id";
24
    }
25
26 3
    public function getEntryId () {
27 3
        return self::ALL_LANGUAGES_ID.":".$this->id;
28
    }
29
30 12
    public static function getLanguageString ($code) {
31 12
        $string = localize("languages.".$code);
32 12
        if (preg_match ("/^languages/", $string)) {
33
            return $code;
34
        }
35 12
        return $string;
36
    }
37
38 7
    public static function getCount() {
39
        // str_format (localize("languages.alphabetical", count(array))
40 7
        return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES);
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...
41
    }
42
43 1
    public static function getLanguageById ($languageId) {
44 1
        $result = parent::getDb ()->prepare('select id, lang_code  from languages where id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
45 1
        $result->execute (array ($languageId));
46 1
        if ($post = $result->fetchObject ()) {
47 1
            return new Language ($post->id, Language::getLanguageString ($post->lang_code));
48
        }
49
        return NULL;
50
    }
51
52
53
54 2
    public static function getAllLanguages() {
55 2
        $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllLanguages()). 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...
56
from languages, books_languages_link
57
where languages.id = books_languages_link.lang_code
58
group by languages.id, books_languages_link.lang_code
59 2
order by languages.lang_code');
60 2
        $entryArray = array();
61 2
        while ($post = $result->fetchObject ())
62
        {
63 2
            $language = new Language ($post->id, $post->lang_code);
64 2
            array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
65 2
                str_format (localize("bookword", $post->count), $post->count), "text",
66 2
                array ( new LinkNavigation ($language->getUri ())), "", $post->count));
67 2
        }
68 2
        return $entryArray;
69
    }
70
}
71