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... ( 6aeec2...b1ae38 )
by Brad
02:46
created

FooGallery_LazyLoad::change_src_attributes()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 6
nop 3
dl 0
loc 28
rs 8.439
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
			//change the image src attribute to data attributes if lazy loading is enabled
12
			add_filter( 'foogallery_attachment_html_image_attributes', array($this, 'change_src_attributes'), 99, 3);
13
14
			//add the lazy load attributes to the gallery container
15
			add_filter( 'foogallery_build_container_data_options', array( $this, 'add_lazyload_options' ), 10, 3 );
16
		}
17
18
		/**
19
		 * Determine if the gallery has lazy loading support
20
		 *
21
		 * @param $foogallery
22
		 * @param $foogallery_template
23
		 */
24
		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...
25
26
			//make sure we only do this once for better performance
27
			if ( !isset( $foogallery->lazyload ) ) {
28
29
				//load the gallery template
30
				$template_info = foogallery_get_gallery_template( $foogallery_template );
31
32
				//check if the template supports lazy loading
33
				$lazy_load = isset($template_info['lazyload_support']) &&
34
					true === $template_info['lazyload_support'];
35
36
				$foogallery->lazyload = apply_filters( 'foogallery_lazy_load', $lazy_load, $foogallery, $foogallery_template );
37
			}
38
		}
39
40
		/**
41
		 * @param array $attr
42
		 * @param array $args
43
		 * @param FooGalleryAttachment $attachment
44
		 * @return mixed
45
		 */
46
		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...
47
			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...
48
			global $current_foogallery_template;
49
50
			if ( $current_foogallery !== null ) {
51
52
				$this->determine_lazyloading_support( $current_foogallery, $current_foogallery_template );
53
54
				if ( isset( $current_foogallery->lazyload ) && true === $current_foogallery->lazyload ) {
55
56
					if ( isset( $attr['src'] ) ) {
57
						//rename src => data-src
58
						$src = $attr['src'];
59
						unset( $attr['src'] );
60
						$attr['data-src'] = $src;
61
					}
62
63
					if ( isset( $attr['srcset'] ) ) {
64
						//rename srcset => data-srcset
65
						$src = $attr['srcset'];
66
						unset( $attr['srcset'] );
67
						$attr['data-srcset'] = $src;
68
					}
69
				}
70
			}
71
72
			return $attr;
73
		}
74
75
76
		/**
77
		 * Add the required lazy load options if needed
78
		 *
79
		 * @param $attributes array
80
		 * @param $gallery FooGallery
81
		 *
82
		 * @return array
83
		 */
84
		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...
85
			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...
86
87
			$this->determine_lazyloading_support( $gallery, $current_foogallery_template );
88
89
			if ( isset( $gallery->lazyload) && true === $gallery->lazyload) {
90
				$options['lazy'] = true;
91
			}
92
			return $options;
93
		}
94
	}
95
}