GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( f00e4a...d725c4 )
by Brad
03:10
created

determine_lazyloading_support()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class used to handle lazy loading for gallery templates
4
 * Date: 20/03/2017
5
 */
6
if ( ! class_exists( 'FooGallery_LazyLoad' ) ) {
7
8
	class FooGallery_LazyLoad
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
    {
10
11
        function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
        {
13
            //change the image src attribute to data attributes if lazy loading is enabled
14
            add_filter('foogallery_attachment_html_image_attributes', array($this, 'change_src_attributes'), 99, 3);
15
16
            //add the lazy load attributes to the gallery container
17
            add_filter('foogallery_build_container_data_options', array($this, 'add_lazyload_options'), 10, 3);
18
19
            //add common fields to the templates that support it
20
            add_filter('foogallery_override_gallery_template_fields', array($this, 'add_lazyload_field'), 100, 2);
21
22
            //build up preview arguments
23
            add_filter( 'foogallery_preview_arguments', array( $this, 'preview_arguments' ), 10, 3 );
24
        }
25
26
        /**
27
         * Determine if the gallery has lazy loading support
28
         *
29
         * @param $foogallery
30
         * @param $foogallery_template
31
         */
32
        function determine_lazyloading_support($foogallery, $foogallery_template)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
        {
34
            //make sure we only do this once for better performance
35
            if (!isset($foogallery->lazyload)) {
36
37
                //load the gallery template
38
                $template_info = foogallery_get_gallery_template($foogallery_template);
39
40
                //check if the template supports lazy loading
41
                $lazy_load = isset($template_info['lazyload_support']) &&
42
                    true === $template_info['lazyload_support'];
43
44
                $foogallery->lazyload = apply_filters('foogallery_lazy_load', $lazy_load, $foogallery, $foogallery_template);
45
            }
46
        }
47
48
        /**
49
         * @param array $attr
50
         * @param array $args
51
         * @param FooGalleryAttachment $attachment
52
         * @return mixed
53
         */
54
        function change_src_attributes($attr, $args, $attachment)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $attachment is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
        {
56
            global $current_foogallery;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
57
            global $current_foogallery_template;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
58
59
            if ($current_foogallery !== null) {
60
61
                $this->determine_lazyloading_support($current_foogallery, $current_foogallery_template);
62
63
                if (isset($current_foogallery->lazyload) && true === $current_foogallery->lazyload) {
64
65
                    if (isset($attr['src'])) {
66
                        //rename src => data-src
67
                        $src = $attr['src'];
68
                        unset($attr['src']);
69
                        $attr['data-src'] = $src;
70
                    }
71
72
                    if (isset($attr['srcset'])) {
73
                        //rename srcset => data-srcset
74
                        $src = $attr['srcset'];
75
                        unset($attr['srcset']);
76
                        $attr['data-srcset'] = $src;
77
                    }
78
                }
79
            }
80
81
            return $attr;
82
        }
83
84
85
        /**
86
         * Add the required lazy load options if needed
87
         *
88
         * @param $attributes array
89
         * @param $gallery FooGallery
90
         *
91
         * @return array
92
         */
93
        function add_lazyload_options($options, $gallery, $attributes)
0 ignored issues
show
Unused Code introduced by
The parameter $attributes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
94
        {
95
            global $current_foogallery_template;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
96
97
            $this->determine_lazyloading_support($gallery, $current_foogallery_template);
98
99
            if (isset($gallery->lazyload) && true === $gallery->lazyload) {
100
                $lazyloading_enabled = foogallery_gallery_template_setting( 'lazyload', '' ) === '';
101
102
                $options['lazy'] = $lazyloading_enabled;
103
            }
104
            return $options;
105
        }
106
107
        /**
108
         * Add lazyload field to the gallery template if supported
109
         *
110
         * @param $fields
111
         * @param $template
112
         *
113
         * @return array
114
         */
115
        function add_lazyload_field($fields, $template)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
116
        {
117
            //check if the template supports lazy loading
118
            if ($template && array_key_exists('lazyload_support', $template) && true === $template['lazyload_support']) {
119
120
                $fields[] = array(
121
                    'id'      => 'lazyload',
122
                    'title'   => __( 'Lazy Loading', 'foogallery' ),
123
                    'desc'    => __( 'If you choose to disable lazy loading, then all thumbnails will be loaded at once. This means you will lose the performance improvements that lazy loading gives you.', 'foogallery' ),
124
                    'section' => __( 'Advanced', 'foogallery' ),
125
                    'type'     => 'radio',
126
                    'spacer'   => '<span class="spacer"></span>',
127
                    'default'  => '',
128
                    'choices'  => array(
129
                        '' => __( 'Enable Lazy Loading', 'foogallery' ),
130
                        'disabled' => __( 'Disable Lazy Loading', 'foogallery' ),
131
                    ),
132
                    'row_data' => array(
133
                        'data-foogallery-change-selector' => 'input:radio',
134
                        'data-foogallery-preview' => 'shortcode'
135
                    )
136
                );
137
            }
138
139
            return $fields;
140
        }
141
142
        /**
143
         * Build up a arguments used in the preview of the gallery
144
         * @param $args
145
         * @param $post_data
146
         * @param $template
147
         *
148
         * @return mixed
149
         */
150
        function preview_arguments( $args, $post_data, $template ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
151
            if ( isset( $post_data[FOOGALLERY_META_SETTINGS][$template . '_lazyload'] ) ) {
152
                $args['lazyload'] = $post_data[FOOGALLERY_META_SETTINGS][$template . '_lazyload'];
153
            }
154
            return $args;
155
        }
156
    }
157
}