chamilo/chamilo-lms

View on GitHub
public/main/inc/lib/formvalidator/FormValidator.class.php

Summary

Maintainability
A
0 mins
Test Coverage

The method FormValidator::addFile() calls the typical debug function var_dump() which is mostly only used during development.
Open

            var_dump($e->getMessage());

DevelopmentCodeFragment

Since: 2.3.0

Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.

Example

class SuspectCode {

    public function doSomething(array $items)
    {
        foreach ($items as $i => $item) {
            // …

            if ('qafoo' == $item) var_dump($i);

            // …
        }
    }
}

Source https://phpmd.org/rules/design.html#developmentcodefragment

The method __construct() has an NPath complexity of 1008. The configured NPath complexity threshold is 200.
Open

    public function __construct(
        string $name,
        ?string $method = 'post',
        ?string $action = '',
        ?string $target = '',

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

The class FormValidator has a coupling between objects value of 23. Consider to reduce the number of dependencies under 13.
Open

class FormValidator extends HTML_QuickForm
{
    public const LAYOUT_HORIZONTAL = 'horizontal';
    public const LAYOUT_INLINE = 'inline';
    public const LAYOUT_BOX = 'box';

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

Source https://phpmd.org/rules/design.html#couplingbetweenobjects

Missing class import via use statement (line '1713', column '28').
Open

        $mailManager = new MailTemplateManager();

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 '287', column '23').
Open

            throw new \Exception('select_ajax needs an URL');

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 '971', column '31').
Open

                    throw new Exception('If you use the crop functionality the element must have an id');

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 '1667', column '35').
Open

                        throw new Exception("The $groupName doesn't have the element $elementName");

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

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

        } else {
            $renderer->setElementTemplate($this->getDefaultElementTemplate());

            // Display a gray div in the buttons
            $templateSimple = '<div class="form-actions">{label} {element}</div>';

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

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

        } else {
            $element = $this->addElement('text', $name, $label, $attributes);
        }

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

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

            } else {
                $this->addRule(
                    $elementName,
                    $message,
                    'callback',

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

Avoid unused local variables such as '$parent'.
Open

        $parent = null;

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

Avoid unused parameters such as '$delay'.
Open

    public function addProgress($delay = 2, $label = '')

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

The property $with_progress_bar is not named in camelCase.
Open

class FormValidator extends HTML_QuickForm
{
    public const LAYOUT_HORIZONTAL = 'horizontal';
    public const LAYOUT_INLINE = 'inline';
    public const LAYOUT_BOX = 'box';

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

Missing function doc comment
Open

    public function getFormTemplate(): string

Expected 6 spaces after parameter name; 3 found
Open

     * @param bool         $required   (optional)    Is the form-element required (default=true)

Expected 3 spaces after parameter type; 2 found
Open

     * @param null  $maxValue

Variable "allowed_tags" is not in valid camel caps format
Open

    $cleaned_html = kses($html, $allowed_tags);

Consider putting global function "html_filter_student_fullpage" in a static class
Open

function html_filter_student_fullpage($html)

Missing function doc comment
Open

    public function getGridFormTemplate(): string

Expected 5 spaces after parameter type; 1 found
Open

     * @param string $textCallable  set a function getStringValue() by default __toString()

Missing function doc comment
Open

function html_filter_student($html)

Missing function doc comment
Open

    public function getLayout(): string

Doc comment for parameter $attributes does not match actual variable name $options
Open

     * @param array  $attributes

Missing function doc comment
Open

    public function addMultiSelect(string $name, $label, array $options, array $attributes = [])

Method name "FormValidator::add_multiple_required_rule" is not in camel caps format
Open

    public function add_multiple_required_rule($elements, $message)

Expected 4 spaces after parameter type; 3 found
Open

     * @param int   $minValue

Consider putting global function "html_filter" in a static class
Open

function html_filter($html, $mode = NO_HTML)

Consider putting global function "html_filter_teacher" in a static class
Open

function html_filter_teacher($html)

Member variable "with_progress_bar" is not in valid camel caps format
Open

    public $with_progress_bar = false;

Expected 4 spaces after parameter name; 1 found
Open

     * @param array        $attributes (optional)    List of attributes for the form-element

Missing parameter name
Open

     * @param      $label

Expected 2 spaces after parameter type; 1 found
Open

     * @param bool $hideGeoLocalizationDetails

Doc comment for parameter $hideGeoLocalizationDetails does not match actual variable name $dataValue
Open

     * @param bool $hideGeoLocalizationDetails

Method name "FormValidator::return_form" is not in camel caps format
Open

    public function return_form()

Variable "cleaned_html" is not in valid camel caps format
Open

    $cleaned_html = kses($html, $allowed_tags);

Expected 9 spaces after parameter name; 6 found
Open

     * @param string|array $label      The label for the form-element

Expected 7 spaces after parameter type; 3 found
Open

     * @param bool   $addNoneOption

Expected 8 spaces after parameter type; 2 found
Open

     * @param array  $attributes

Missing function doc comment
Open

    public function addEndPanel(): void

Missing function doc comment
Open

function html_filter_student_fullpage($html)

Missing parameter name
Open

     * @param $label

Expected 3 spaces after parameter type; 2 found
Open

     * @param bool  $required

Expected 3 spaces after parameter type; 2 found
Open

     * @param bool  $allowNegative

Consider putting global function "html_filter_student" in a static class
Open

function html_filter_student($html)

Missing function doc comment
Open

function html_filter_teacher_fullpage($html)

Doc comment for parameter $trackSubmit does not match actual variable name $layout
Open

     * @param bool        $trackSubmit Whether to track if the form was submitted by adding a special hidden field

Missing function doc comment
Open

    public function setLayout(string $layout)

Variable "with_progress_bar" is not in valid camel caps format
Open

        if (isset($this->with_progress_bar) && $this->with_progress_bar) {

Missing parameter name
Open

     * @param $label

Consider putting global function "html_filter_teacher_fullpage" in a static class
Open

function html_filter_teacher_fullpage($html)

Missing parameter name
Open

     * @param $name

Missing parameter name
Open

     * @param $collection

Missing function doc comment
Open

    public function addStartPanel(string $id, string $title, bool $open = false, $icon = null): void

Missing parameter name
Open

     * @param      $name

Consider putting global function "mobile_phone_number_filter" in a static class
Open

function mobile_phone_number_filter($mobilePhoneNumber)

Missing function doc comment
Open

    public function addSelectTheme($name, $label, $options = [], $attributes = [])

Variable "with_progress_bar" is not in valid camel caps format
Open

        if (isset($this->with_progress_bar) && $this->with_progress_bar) {

Variable "allowed_tags" is not in valid camel caps format
Open

    $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);

Variable "cleaned_html" is not in valid camel caps format
Open

    return $cleaned_html;

Doc comment for parameter $label does not match actual variable name $name
Open

     * @param string|array $label

Expected 2 spaces after parameter type; 1 found
Open

     * @param array $attributes

Expected 7 spaces after parameter type; 1 found
Open

     * @param string $name

Expected 6 spaces after parameter type; 2 found
Open

     * @param array  $attributes

Variable "with_progress_bar" is not in valid camel caps format
Open

        $this->with_progress_bar = true;

Missing function doc comment
Open

function html_filter_teacher($html)

Expected 10 spaces after parameter name; 7 found
Open

     * @param string       $name       The element name

The variable $cleaned_html is not named in camelCase.
Open

function html_filter($html, $mode = NO_HTML)
{
    $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
    $cleaned_html = kses($html, $allowed_tags);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $allowed_tags is not named in camelCase.
Open

function html_filter($html, $mode = NO_HTML)
{
    $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
    $cleaned_html = kses($html, $allowed_tags);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $cleaned_html is not named in camelCase.
Open

function html_filter($html, $mode = NO_HTML)
{
    $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
    $cleaned_html = kses($html, $allowed_tags);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $allowed_tags is not named in camelCase.
Open

function html_filter($html, $mode = NO_HTML)
{
    $allowed_tags = HTML_QuickForm_Rule_HTML::get_allowed_tags($mode);
    $cleaned_html = kses($html, $allowed_tags);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The method add_multiple_required_rule is not named in camelCase.
Open

    public function add_multiple_required_rule($elements, $message)
    {
        $this->_required[] = $elements[0];
        $this->addRule($elements, $message, 'multiple_required');
    }

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

The method return_form is not named in camelCase.
Open

    public function return_form()
    {
        return $this->returnForm();
    }

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

There are no issues that match your filters.

Category
Status