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 — feature/gallery-template-clien... ( 0fed14...275fef )
by Brad
04:35
created

FooGallery_LazyLoad::change_src_attributes()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 16
nc 10
nop 3
dl 0
loc 27
rs 6.7272
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
		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...
11
//			if ( is_admin() ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
//				//add extra fields to the templates that support lazy loading
13
//				add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_lazyload_fields' ), 10, 2 );
14
//			}
15
16
			//adds the lazyload property to a FooGallery
17
			add_action( 'foogallery_foogallery_instance_after_load', array( $this, 'determine_lazyload' ), 10, 2 );
18
19
			//change the image src attribute to data attributes if lazy loading is enabled
20
			add_filter( 'foogallery_attachment_html_image_attributes', array($this, 'change_src_attributes'), 99, 3);
21
22
			//add the lazy load attributes to the gallery container
23
			add_filter( 'foogallery_build_container_data_options', array( $this, 'add_lazyload_options' ), 10, 3 );
24
		}
25
26
		/**
27
		 * Add lazy load fields to the gallery template
28
		 *
29
		 * @uses "foogallery_override_gallery_template_fields"
30
		 * @param $fields
31
		 * @param $template
32
		 *
33
		 * @return array
34
		 */
35
		function add_lazyload_fields( $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...
36
			if ( $template && array_key_exists( 'lazyload_support', $template ) && true === $template['lazyload_support'] ) {
37
				$fields[] = array(
38
					'id'      => 'lazyload',
39
					'title'   => __( 'Lazy Loading', 'foogallery' ),
40
					'desc'    => __( 'Lazy loading means images in your gallery are only loaded when they become visible in the browser. This significantly improves page loading times.', 'foogallery' ),
41
					'section' => __( 'Thumbnails', 'foogallery' ),
42
					'spacer'  => '<span class="spacer"></span>',
43
					'type'    => 'radio',
44
					'choices' => array(
45
						'yes'  => __( 'Enabled', 'foogallery' ),
46
						'no'   => __( 'Disabled', 'foogallery' )
47
					)
48
				);
49
			}
50
51
			return $fields;
52
		}
53
54
		/**
55
		 * Determine if the gallery has lazy loading enabled
56
		 *
57
		 * @param $foogallery
58
		 * @param $post
59
		 */
60
		function determine_lazyload( $foogallery, $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post 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...
61
			//always enable lazyload by default
62
			$lazy_load = true;
63
64
			if ( true === foogallery_get_setting( 'disable_lazy_load', false ) ) {
65
				$lazy_load = false;
66
			}
67
68
			$foogallery->lazyload = apply_filters( 'foogallery_lazy_load', $lazy_load, $foogallery );
69
		}
70
71
		/**
72
		 * @param array $attr
73
		 * @param array $args
74
		 * @param FooGalleryAttachment $attachment
75
		 * @return mixed
76
		 */
77
		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...
78
			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...
79
			global $current_foogallery_template;
80
81
			$lazyload_support = isset($current_foogallery_template['lazyload_support']) &&
82
                true === $current_foogallery_template['lazyload_support'];
83
84
			if ( $lazyload_support &&
85
                isset( $current_foogallery->lazyload) && true === $current_foogallery->lazyload) {
86
87
				if ( isset( $attr['src'] ) ) {
88
					//rename src => data-src
89
					$src = $attr['src'];
90
					unset( $attr['src'] );
91
					$attr['data-src'] = $src;
92
				}
93
94
				if ( isset( $attr['srcset'] ) ) {
95
					//rename srcset => data-srcset
96
					$src = $attr['srcset'];
97
					unset( $attr['srcset'] );
98
					$attr['data-srcset'] = $src;
99
				}
100
			}
101
102
			return $attr;
103
		}
104
105
106
		/**
107
		 * Add the required lazy load options if needed
108
		 *
109
		 * @param $attributes array
110
		 * @param $gallery FooGallery
111
		 *
112
		 * @return array
113
		 */
114
		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...
115
			if ( isset( $gallery->lazyload) && true === $gallery->lazyload) {
116
				$options['lazy'] = true;
117
			}
118
			return $options;
119
		}
120
	}
121
}