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... ( 6eed57 )
by Brad
02:17
created

FooGallery_LazyLoad::add_lazyload_fields()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 2
nop 2
dl 0
loc 18
rs 9.2
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() ) {
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_attributes', array( $this, 'add_lazyload_attributes' ), 10, 2 );
24
25
			//add the appropriate lazy load class
26
			add_filter( 'foogallery_build_class_attribute', array( $this, 'add_lazyload_class' ), 10, 2 );
27
		}
28
29
		/**
30
		 * Add lazy load fields to the gallery template
31
		 *
32
		 * @uses "foogallery_override_gallery_template_fields"
33
		 * @param $fields
34
		 * @param $template
35
		 *
36
		 * @return array
37
		 */
38
		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...
39
			if ( $template && array_key_exists( 'lazyload_support', $template ) && true === $template['lazyload_support'] ) {
40
				$fields[] = array(
41
					'id'      => 'lazyload',
42
					'title'   => __( 'Lazy Loading', 'foogallery' ),
43
					'desc'    => __( 'Lazy loading means images in your gallery are only loaded when they are visible in browser. This significantly improves page loading times.', 'foogallery' ),
44
					'section' => __( 'Gallery Settings', 'foogallery' ),
45
					'type'    => 'radio',
46
					'choices' => array(
47
						'yes'  => __( 'Enable Lazy Loading', 'foogallery' ),
48
						'no'   => __( 'Disabled', 'foogallery' )
49
					),
50
					'spacer'  => '<span class="spacer"></span>'
51
				);
52
			}
53
54
			return $fields;
55
		}
56
57
		/**
58
		 * Determine if the gallery has lazy loading enabled
59
		 *
60
		 * @param $foogallery
61
		 * @param $post
62
		 */
63
		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...
64
			$gallery_template = $foogallery->gallery_template;
65
66
			$setting_key = "{$gallery_template}_lazyload";
67
68
			if ( 'yes' === $foogallery->get_meta( $setting_key, 'yes' ) ) {
69
				$foogallery->lazyload = true;
70
			}
71
		}
72
73
		/**
74
		 * @param array $attr
75
		 * @param array $args
76
		 * @param FooGalleryAttachment $attachment
77
		 * @return mixed
78
		 */
79
		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...
80
			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...
81
82
			if ( isset( $current_foogallery->lazyload) && true === $current_foogallery->lazyload) {
83
84
				if ( isset( $attr['src'] ) ) {
85
					//rename src => data-src
86
					$src = $attr['src'];
87
					unset( $attr['src'] );
88
					$attr['data-src'] = $src;
89
				}
90
91
				if ( isset( $attr['srcset'] ) ) {
92
					//rename srcset => data-srcset
93
					$src = $attr['srcset'];
94
					unset( $attr['srcset'] );
95
					$attr['data-srcset'] = $src;
96
				}
97
			}
98
99
			return $attr;
100
		}
101
102
103
		/**
104
		 * Add the required lazy load attributes onto the gallery container div
105
		 *
106
		 * @param $attributes array
107
		 * @param $gallery FooGallery
108
		 *
109
		 * @return array
110
		 */
111
		function add_lazyload_attributes($attributes, $gallery) {
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...
112
			if ( isset( $gallery->lazyload) && true === $gallery->lazyload) {
113
				$attributes['data-loader-options'] = '{\'lazy\':true}';
114
			}
115
			return $attributes;
116
		}
117
118
		/**
119
		 * Add the required lazy load class to the gallery
120
		 *
121
		 * @param $classes array
122
		 * @param $gallery FooGallery
123
		 *
124
		 * @return array
125
		 */
126
		function add_lazyload_class($classes, $gallery) {
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...
127
			if ( isset( $gallery->lazyload) && true === $gallery->lazyload) {
128
				$classes[] = apply_filters( 'foogallery_lazyload_class', 'loaded-fade-in' );
129
			}
130
			return $classes;
131
		}
132
	}
133
}