ImpressCMS/impresscms

View on GitHub
htdocs/modules/system/admin/rating/class/rating.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid using undefined variables such as '$ret' which will lead to PHP notices.
Open

        $ret['average'] = isset($average) ? $average : 0;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$ret' which will lead to PHP notices.
Open

        $ret['sum'] = isset($sum) ? $sum : 0;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$ret' which will lead to PHP notices.
Open

        return $ret;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Missing class import via use statement (line '157', column '30').
Open

        $this->pluginsObject = new icms_plugins_Handler();

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '218', column '22').
Open

        $criteria->add(new icms_db_criteria_Item('dirname', $dirname));

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '217', column '22').
Open

        $criteria->add(new icms_db_criteria_Item('itemid', (int) $itemid));

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '215', column '19').
Open

        $criteria = new icms_db_criteria_Compo();

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '216', column '22').
Open

        $criteria->add(new icms_db_criteria_Item('item', $item));

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Missing class import via use statement (line '219', column '22').
Open

        $criteria->add(new icms_db_criteria_Item('user.uid', (int) $uid));

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class 'icms_member_user_Handler' in method 'name'.
Open

        return icms_member_user_Handler::getUserLink($this->getVar('uid', 'e'), TRUE, array());

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class 'icms_member_user_Handler' in method 'getUnameValue'.
Open

        return icms_member_user_Handler::getUserLink($this->getVar('uid'));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method already_rated uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return $ret[0];
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('itemid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_ITEMID);

Reference to undeclared constant \XOBJ_DTYPE_INT
Open

        $this->quickInitVar('uid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_UID);

Parameter $item has undeclared type \str
Open

    public function getRatingAverageByItemId($itemid, $dirname, $item) {

Call to method add from undeclared class \icms_db_criteria_Compo
Open

        $criteria->add(new icms_db_criteria_Item('dirname', $dirname));

Call to method __construct from undeclared class \icms_db_criteria_Item
Open

        $criteria->add(new icms_db_criteria_Item('user.uid', (int) $uid));

Reference to undeclared constant \XOBJ_DTYPE_INT
Open

        $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, TRUE);

Call to method getUserLink from undeclared class \icms_member_user_Handler
Open

        return icms_member_user_Handler::getUserLink($this->getVar('uid'));

Class extends undeclared class \icms_ipf_Handler
Open

class SystemRatingHandler extends icms_ipf_Handler {

Reference to undeclared property \SystemRatingHandler->_itemname
Open

        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';

Reference to undeclared property \SystemRatingHandler->db
Open

        list($average, $sum) = $this->db->fetchRow($result);

Call to undeclared method \SystemRatingHandler::getObjects
Open

        $ret = $this->getObjects($criteria);

Reference to undeclared constant \XOBJ_DTYPE_TXTBOX
Open

        $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_DIRNAME);

Call to undeclared method \SystemRating::setControl
Open

        $this->setControl('item', array('object' => &$this, 'method' => 'getItemList'));

Reference to undeclared property \SystemRating->handler
Open

        $moduleArray = $this->handler->getModuleList();

Reference to undeclared constant \XOBJ_DTYPE_TXTBOX
Open

        $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_ITEM);

Reference to undeclared constant \XOBJ_DTYPE_INT
Open

        $this->quickInitVar('rate', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_RATE);

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('rate', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_RATE);

Reference to undeclared class \icms_ipf_Object
Open

        return parent::getVar($key, $format);

Reference to undeclared property \SystemRatingHandler->db (Did you mean $db)
Open

        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';

Call to method __construct from undeclared class \icms_plugins_Handler
Open

        $this->pluginsObject = new icms_plugins_Handler();

Suspicious array access to false
Open

                $this->_moduleList[$k] = $v;

Parameter $dirname has undeclared type \str
Open

    public function already_rated($item, $itemid, $dirname, $uid) {

Call to method __construct from undeclared class \icms_db_criteria_Compo
Open

        $criteria = new icms_db_criteria_Compo();

Call to method __construct from undeclared class \icms_db_criteria_Item
Open

        $criteria->add(new icms_db_criteria_Item('item', $item));

Call to method add from undeclared class \icms_db_criteria_Compo
Open

        $criteria->add(new icms_db_criteria_Item('user.uid', (int) $uid));

Reference to undeclared constant \XOBJ_DTYPE_INT
Open

        $this->quickInitVar('itemid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_ITEMID);

Call to undeclared method \SystemRating::setControl
Open

        $this->setControl('dirname', array('method' => 'getModuleList', 'onSelect' => 'submit'));

Reference to undeclared property \SystemRatingHandler->db
Open

        $result = $this->db->query($sql);

Call to method add from undeclared class \icms_db_criteria_Compo
Open

        $criteria->add(new icms_db_criteria_Item('itemid', (int) $itemid));

Reference to undeclared constant \XOBJ_DTYPE_LTIME
Open

        $this->quickInitVar('date', XOBJ_DTYPE_LTIME, TRUE, _CO_ICMS_RATING_DATE);

Returning type false but getModuleList() is declared to return array
Open

        return $this->_moduleList;

Call to method getUserLink from undeclared class \icms_member_user_Handler
Open

        return icms_member_user_Handler::getUserLink($this->getVar('uid', 'e'), TRUE, array());

Reference to undeclared property \SystemRatingHandler->table
Open

        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';

Class extends undeclared class \icms_ipf_Object
Open

class SystemRating extends icms_ipf_Object {

Suspicious array access to false
Open

            $this->_moduleList[0] = _CO_ICMS_MAKE_SELECTION;

Reference to undeclared class \icms_ipf_Object
Open

        parent::__construct($handler);

Parameter $item has undeclared type \str
Open

    public function already_rated($item, $itemid, $dirname, $uid) {

Reference to undeclared property \SystemRating->handler
Open

            $this->_modulePlugin = $this->handler->pluginsObject->getPlugin('rating', $this->getVar('dirname', 'n'));

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, TRUE);

Call to method getPluginsArray from undeclared class \icms_plugins_Handler
Open

            $moduleArray = $this->pluginsObject->getPluginsArray('rating');

Assigning array<int></int> to property but \SystemRatingHandler->_moduleList is false
Open

            $this->_moduleList[0] = _CO_ICMS_MAKE_SELECTION;

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_DIRNAME);

Reference to undeclared class \icms_ipf_Handler
Open

        parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'system');

Assigning array to property but \SystemRatingHandler->_moduleList is false
Open

                $this->_moduleList[$k] = $v;

Parameter $dirname has undeclared type \str
Open

    public function getRatingAverageByItemId($itemid, $dirname, $item) {

Variable $ret was undeclared, but array fields are being added to it.
Open

        $ret['average'] = isset($average) ? $average : 0;

Call to undeclared method \SystemRating::setControl
Open

        $this->setControl('rate', array('method' => 'getRateList'));

Reference to undeclared property \SystemRatingHandler->generalSQL
Open

        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('date', XOBJ_DTYPE_LTIME, TRUE, _CO_ICMS_RATING_DATE);

Call to undeclared method \SystemRating::setControl
Open

        $this->setControl('uid', 'user');

Saw unextractable annotation for comment '* @return'
Open

     * @return

Call to method __construct from undeclared class \icms_db_criteria_Item
Open

        $criteria->add(new icms_db_criteria_Item('itemid', (int) $itemid));

Call to method __construct from undeclared class \icms_db_criteria_Item
Open

        $criteria->add(new icms_db_criteria_Item('dirname', $dirname));

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('uid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_UID);

Call to undeclared method \SystemRating::quickInitVar
Open

        $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_ITEM);

Call to method add from undeclared class \icms_db_criteria_Compo
Open

        $criteria->add(new icms_db_criteria_Item('item', $item));

Reference to undeclared constant \XOBJ_DTYPE_TXTBOX
Open

        $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_ICMS_RATING_NAME);

Call to undeclared method \SystemRating::initNonPersistableVar
Open

        $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_ICMS_RATING_NAME);

Suspicious type \str of a variable or expression used to build a string. (Expected type to be able to cast to a string)
Open

        $sql = "SELECT AVG(rate), COUNT(ratingid) FROM " . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";

Reference to undeclared property \SystemRatingHandler->table
Open

        $sql = "SELECT AVG(rate), COUNT(ratingid) FROM " . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class SystemRating extends icms_ipf_Object {

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class SystemRatingHandler extends icms_ipf_Handler {

The property $_moduleList is not named in camelCase.
Open

class SystemRatingHandler extends icms_ipf_Handler {

    public $_rateOptions = array();
    public $_moduleList = FALSE;
    public $pluginsObject;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

Avoid variables with short names like $db. Configured minimum length is 3.
Open

    public function __construct($db) {

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

The property $_modulePlugin is not named in camelCase.
Open

class SystemRating extends icms_ipf_Object {

    /** */
    public $_modulePlugin = FALSE;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_rateOptions is not named in camelCase.
Open

class SystemRatingHandler extends icms_ipf_Handler {

    public $_rateOptions = array();
    public $_moduleList = FALSE;
    public $pluginsObject;

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

Each class must be in a file by itself
Open

class SystemRatingHandler extends icms_ipf_Handler {

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('uid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_UID);

TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
Open

    public $_modulePlugin = FALSE;

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_DIRNAME);

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('date', XOBJ_DTYPE_LTIME, TRUE, _CO_ICMS_RATING_DATE);

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        return icms_member_user_Handler::getUserLink($this->getVar('uid', 'e'), TRUE, array());

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('itemid', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_ITEMID);

Expected 1 space before "=>"; 0 found
Open

            foreach ($moduleArray as $k=>$v) {

Method name "SystemRatingHandler::already_rated" is not in camel caps format
Open

    public function already_rated($item, $itemid, $dirname, $uid) {

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, TRUE, _CO_ICMS_RATING_ITEM);

TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
Open

    public $_moduleList = FALSE;

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('rate', XOBJ_DTYPE_INT, TRUE, _CO_ICMS_RATING_RATE);

Expected 1 space after "=>"; 0 found
Open

            foreach ($moduleArray as $k=>$v) {

TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
Open

            return FALSE;

TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE"
Open

        $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, TRUE);

Whitespace found at end of line
Open

     * 

Whitespace found at end of line
Open

     * 

Whitespace found at end of line
Open

     * 

Whitespace found at end of line
Open

     * Retrieve the username associated with a rating 

Whitespace found at end of line
Open

     * 

Whitespace found at end of line
Open

     * 

The method already_rated is not named in camelCase.
Open

    public function already_rated($item, $itemid, $dirname, $uid) {

        $criteria = new icms_db_criteria_Compo();
        $criteria->add(new icms_db_criteria_Item('item', $item));
        $criteria->add(new icms_db_criteria_Item('itemid', (int) $itemid));

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

Unexpected trailing spaces found.
Open

     * Retrieve the username associated with a rating 

Unexpected trailing spaces found.
Open

    

Unexpected trailing spaces found.
Open

     * 

Unexpected trailing spaces found.
Open

    

Unexpected trailing spaces found.
Open

     * 

Unexpected trailing spaces found.
Open

     * 

Unexpected trailing spaces found.
Open

     * 

Unexpected trailing spaces found.
Open

     * 

There are no issues that match your filters.

Category
Status