mambax7/extgallery

View on GitHub
assets/js/ml-slider/inc/slide/metaslide.class.php

Summary

Maintainability
A
1 hr
Test Coverage

get_slide_html accesses the super-global variable $_GET.
Open

    public function get_slide_html()
    {
        if (is_admin() && isset($_GET['page']) && 'metaslider-theme-editor' === $_GET['page']) {
            return $this->get_public_slide();
        }

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

get_slide_html accesses the super-global variable $_GET.
Open

    public function get_slide_html()
    {
        if (is_admin() && isset($_GET['page']) && 'metaslider-theme-editor' === $_GET['page']) {
            return $this->get_public_slide();
        }

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

get_slide_html accesses the super-global variable $_GET.
Open

    public function get_slide_html()
    {
        if (is_admin() && isset($_GET['page']) && 'metaslider-theme-editor' === $_GET['page']) {
            return $this->get_public_slide();
        }

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method update_menu_order has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function update_menu_order()
    {
        $menu_order = 0;

        // get the slide with the highest menu_order so far
Severity: Minor
Found in assets/js/ml-slider/inc/slide/metaslide.class.php - About 1 hr to fix

    Function add_or_update_or_delete_meta has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {
    Severity: Minor
    Found in assets/js/ml-slider/inc/slide/metaslide.class.php - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

            $query = new WP_Query($args);

    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 '240', column '28').
    Open

            $imageHelper = new MetaSliderImageHelper($this->slide->ID, 150, 150, 'false');

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

                } else {
                    add_post_meta($post_id, $key, $value, true);
                }

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

            } else {
                if (get_post_meta($post_id, $key)) {
                    update_post_meta($post_id, $key, $value);
                } else {
                    add_post_meta($post_id, $key, $value, true);

    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 parameters such as '$slider_id'.
    Open

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)

    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

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

    class MetaSlide

    The parameter $slide_id is not named in camelCase.
    Open

        public function save_slide($slide_id, $slider_id, $fields)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
            $this->save($fields);

    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

    The parameter $slider_id is not named in camelCase.
    Open

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)
        {
            $type = get_post_meta($slide_id, 'ml-slider_type', true);
    
            return !mb_strlen($type) || 'image' === $type;

    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

    The parameter $slide_id is not named in camelCase.
    Open

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)
        {
            $type = get_post_meta($slide_id, 'ml-slider_type', true);
    
            return !mb_strlen($type) || 'image' === $type;

    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

    The parameter $slider_id is not named in camelCase.
    Open

        public function save_slide($slide_id, $slider_id, $fields)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
            $this->save($fields);

    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

    The parameter $slide_id is not named in camelCase.
    Open

        public function slide_exists_in_slideshow($slider_id, $slide_id)
        {
            return has_term((string)$slider_id, 'ml-slider', $slide_id);
        }

    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

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

        public function set_slide($id)

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

    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

    The parameter $slider_id is not named in camelCase.
    Open

        public function get_slide($slide_id, $slider_id)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
    
    

    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

    The parameter $slide_id is not named in camelCase.
    Open

        public function get_slide($slide_id, $slider_id)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
    
    

    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

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

        public function set_slider($id)

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

        public function slide_exists_in_slideshow($slider_id, $slide_id)
        {
            return has_term((string)$slider_id, 'ml-slider', $slide_id);
        }

    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 "MetaSlide::set_slide" is not in camel caps format
    Open

        public function set_slide($id)

    Method name "MetaSlide::get_slide" is not in camel caps format
    Open

        public function get_slide($slide_id, $slider_id)

    Method name "MetaSlide::save_slide" is not in camel caps format
    Open

        public function save_slide($slide_id, $slider_id, $fields)

    Method name "MetaSlide::set_slider" is not in camel caps format
    Open

        public function set_slider($id)

    Method name "MetaSlide::build_anchor_tag" is not in camel caps format
    Open

        public function build_anchor_tag($attributes, $content)

    Method name "MetaSlide::update_menu_order" is not in camel caps format
    Open

        public function update_menu_order()

    Method name "MetaSlide::get_slide_html" is not in camel caps format
    Open

        public function get_slide_html()

    Method name "MetaSlide::slide_is_unassigned_or_image_slide" is not in camel caps format
    Open

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)

    Method name "MetaSlide::tag_slide_to_slider" is not in camel caps format
    Open

        public function tag_slide_to_slider()

    Method name "MetaSlide::add_or_update_or_delete_meta" is not in camel caps format
    Open

        public function add_or_update_or_delete_meta($post_id, $name, $value)

    Method name "MetaSlide::slide_exists_in_slideshow" is not in camel caps format
    Open

        public function slide_exists_in_slideshow($slider_id, $slide_id)

    Method name "MetaSlide::get_thumb" is not in camel caps format
    Open

        public function get_thumb()

    Method name "MetaSlide::build_image_tag" is not in camel caps format
    Open

        public function build_image_tag($attributes)

    The variable $slider_id is not named in camelCase.
    Open

        public function slide_exists_in_slideshow($slider_id, $slide_id)
        {
            return has_term((string)$slider_id, 'ml-slider', $slide_id);
        }

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

        public function update_menu_order()
        {
            $menu_order = 0;
    
            // get the slide with the highest menu_order so far

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

        public function save_slide($slide_id, $slider_id, $fields)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
            $this->save($fields);

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

        public function get_slide($slide_id, $slider_id)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
    
    

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

        public function update_menu_order()
        {
            $menu_order = 0;
    
            // get the slide with the highest menu_order so far

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function update_menu_order()
        {
            $menu_order = 0;
    
            // get the slide with the highest menu_order so far

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)
        {
            $type = get_post_meta($slide_id, 'ml-slider_type', true);
    
            return !mb_strlen($type) || 'image' === $type;

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

        public function get_slide($slide_id, $slider_id)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
    
    

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

        public function slide_exists_in_slideshow($slider_id, $slide_id)
        {
            return has_term((string)$slider_id, 'ml-slider', $slide_id);
        }

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

        public function update_menu_order()
        {
            $menu_order = 0;
    
            // get the slide with the highest menu_order so far

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

        public function save_slide($slide_id, $slider_id, $fields)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
            $this->save($fields);

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function set_slider($id)
        {
            $this->slider   = get_post($id);
            $this->settings = get_post_meta($id, 'ml-slider_settings', true);
        }

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

        public function slide_exists_in_slideshow($slider_id, $slide_id)
        {
            return has_term((string)$slider_id, 'ml-slider', $slide_id);
        }

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

        public function update_menu_order()
        {
            $menu_order = 0;
    
            // get the slide with the highest menu_order so far

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

        public function get_slide($slide_id, $slider_id)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
    
    

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

        public function save_slide($slide_id, $slider_id, $fields)
        {
            $this->set_slider($slider_id);
            $this->set_slide($slide_id);
            $this->save($fields);

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

        public function set_slide($id)
        {
            $this->slide = get_post($id);
        }

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

        public function build_anchor_tag($attributes, $content)
        {
            $html = '<a';
    
            foreach ($attributes as $att => $val) {

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

        public function get_slide_html()
        {
            if (is_admin() && isset($_GET['page']) && 'metaslider-theme-editor' === $_GET['page']) {
                return $this->get_public_slide();
            }

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

        public function slide_is_unassigned_or_image_slide($slider_id, $slide_id)
        {
            $type = get_post_meta($slide_id, 'ml-slider_type', true);
    
            return !mb_strlen($type) || 'image' === $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 get_thumb is not named in camelCase.
    Open

        public function get_thumb()
        {
            $imageHelper = new MetaSliderImageHelper($this->slide->ID, 150, 150, 'false');
    
            return $imageHelper->get_image_url();

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

        public function add_or_update_or_delete_meta($post_id, $name, $value)
        {
            $key = 'ml-slider_' . $name;
    
            if ('false' === $value || '' === $value || !$value) {

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

        public function build_image_tag($attributes)
        {
            $html = '<img';
    
            foreach ($attributes as $att => $val) {

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

        public function tag_slide_to_slider()
        {
            if (!term_exists($this->slider->ID, 'ml-slider')) {
                // create the taxonomy term, the term is the ID of the slider itself
                wp_insert_term($this->slider->ID, 'ml-slider');

    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