chamilo/chamilo-lms

View on GitHub
src/CourseBundle/Component/CourseCopy/Course.php

Summary

Maintainability
A
0 mins
Test Coverage

The method get_sample_text() has an NPath complexity of 291. The configured NPath complexity threshold is 200.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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

Remove error control operator '@' on line 349.
Open

    public static function unserialize($course)
    {
        // Uncompress
        if (function_exists('gzdeflate')) {
            $inflated = @gzinflate($course);

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

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

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

        } else {
            $unserialized = UnserializeApi::unserialize(
                'course',
                $course
            );

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 serialize uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $serialized = serialize($course);
        }

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 '$id'.
Open

                foreach ($resources as $id => &$resource) {

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

The property $destination_path is not named in camelCase.
Open

class Course
{
    public $resources;
    public $code;
    public $path;

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 $destination_db is not named in camelCase.
Open

class Course
{
    public $resources;
    public $code;
    public $path;

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 parameter $resource_to_check is not named in camelCase.
Open

    public function is_linked_resource(&$resource_to_check): bool
    {
        foreach ($this->resources as $type => $resources) {
            if (is_array($resources)) {
                foreach ($resources as $resource) {

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

Method name "Course::get_sample_text" is not in camel caps format
Open

    public function get_sample_text()

Method name "Course::add_resource" is not in camel caps format
Open

    public function add_resource(&$resource)

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

                            $resource->survey_question_comment = api_to_system_encoding($resource->survey_question_comment, $this->encoding);

Missing parameter name
Open

     * @param $resource

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

                            $title = $resource->survey_question;

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

                        $sample_text .= $description."\n";

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

                            $resource->topic_poster_name = api_to_system_encoding($resource->topic_poster_name, $this->encoding);

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

                            $resource->poster_name = api_to_system_encoding($resource->poster_name, $this->encoding);

Method name "Course::is_linked_resource" is not in camel caps format
Open

    public function is_linked_resource(&$resource_to_check): bool

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

    public function is_linked_resource(&$resource_to_check): bool

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

                            $description = $resource->intro_text;

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

                        $sample_text .= "\n";

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

                            $resource->content_maker = api_to_system_encoding($resource->content_maker, $this->encoding);

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

                            $resource->intro_text = api_to_system_encoding($resource->intro_text, $this->encoding);

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

    public $destination_db;

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

                        if ($resource->has_item($resource_to_check)) {

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

                            $resource->survey_question = api_to_system_encoding($resource->survey_question, $this->encoding);

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

    public $destination_path;

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

        $sample_text = '';

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

                            $description = $resource->survey_question_comment;

Method name "Course::to_system_encoding" is not in camel caps format
Open

    public function to_system_encoding()

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

                            $resource->title_qualify = api_to_system_encoding($resource->title_qualify, $this->encoding);

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

                            $resource->title_qualify = api_to_system_encoding($resource->title_qualify, $this->encoding);

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

                            $resource->content_license = api_to_system_encoding($resource->content_license, $this->encoding);

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

                    if ($resource->links_to($resource_to_check)) {

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

                            $resource->content_license = api_to_system_encoding($resource->content_license, $this->encoding);

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

                            $resource->survey_question_comment = api_to_system_encoding($resource->survey_question_comment, $this->encoding);

Method name "Course::has_resources" is not in camel caps format
Open

    public function has_resources($type = null)

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

        return $sample_text;

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

                            $resource->poster_name = api_to_system_encoding($resource->poster_name, $this->encoding);

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

                            $resource->topic_poster_name = api_to_system_encoding($resource->topic_poster_name, $this->encoding);

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

                            $resource->survey_question = api_to_system_encoding($resource->survey_question, $this->encoding);

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

                            $resource->content_maker = api_to_system_encoding($resource->content_maker, $this->encoding);

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

        $this->backup_path = '';

Missing function doc comment
Open

    public function show()

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

                        $sample_text .= $title."\n";

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

                            $resource->intro_text = api_to_system_encoding($resource->intro_text, $this->encoding);

The variable $sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 $resource_to_check is not named in camelCase.
Open

    public function is_linked_resource(&$resource_to_check): bool
    {
        foreach ($this->resources as $type => $resources) {
            if (is_array($resources)) {
                foreach ($resources as $resource) {

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 $sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 $sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 $sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 $resource_to_check is not named in camelCase.
Open

    public function is_linked_resource(&$resource_to_check): bool
    {
        foreach ($this->resources as $type => $resources) {
            if (is_array($resources)) {
                foreach ($resources as $resource) {

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 $sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 is_linked_resource is not named in camelCase.
Open

    public function is_linked_resource(&$resource_to_check): bool
    {
        foreach ($this->resources as $type => $resources) {
            if (is_array($resources)) {
                foreach ($resources as $resource) {

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 get_sample_text is not named in camelCase.
Open

    public function get_sample_text()
    {
        $sample_text = '';
        foreach ($this->resources as $type => &$resources) {
            if (count($resources) > 0) {

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 add_resource is not named in camelCase.
Open

    public function add_resource(&$resource)
    {
        $this->resources[$resource->get_type()][$resource->get_id()] = $resource;
    }

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 has_resources is not named in camelCase.
Open

    public function has_resources($type = null)
    {
        if (null != $type) {
            return
                isset($this->resources[$type]) && is_array($this->resources[$type]) && (

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 to_system_encoding is not named in camelCase.
Open

    public function to_system_encoding()
    {
        /*if (api_equal_encodings($this->encoding, api_get_system_encoding())) {
            return;
        }*/

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