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
Pull Request — feature/justified-gallery-imag... (#68)
by
unknown
02:18
created

JustifiedOverrides::fill_sizes()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 3
nop 3
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
1
<?php
2
/**
3
 * Simple class to override settings necessary to work with WordPress thumbnails instead of generated ones
4
 */
5
if ( !class_exists( 'JustifiedOverrides' ) ) {
6
7
	class JustifiedOverrides {
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...
8
9
		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...
10
			//override thumbnail resizing
11
			add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'get_thumb' ), 99, 3 );
12
			//add additional parameters to image args
13
			add_filter( 'foogallery_attachment_html_image_attributes', array( $this, 'fill_sizes' ), 99, 3 );
14
		}
15
16
        function get_thumb($original_image_src, $args, $image) {
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...
17
			//of course the height is merely the label of the chosen thumbnail            
18
            $thumb_url = $image->sizes[$args['height']]['url'];            
19
            return $thumb_url;
20
        }
21
        
22
        function fill_sizes($attr, $args, $image) {
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...
23
            $thumbnail_label = foogallery_gallery_template_setting("thumb_initial");
0 ignored issues
show
Unused Code introduced by
$thumbnail_label is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
25
            //get selected alternate image sizes from settings
26
            $image_sizes = foogallery_gallery_template_setting("thumb_sizes");
27
			
28
			//create width/height array and string
29
			if (is_array($image_sizes)) {
30
				foreach ($image_sizes as $image_size) {
31
					$size_str[] = '{"width" : "' . $image->sizes[$image_size]['width'] . '", "height" : "' . $image->sizes[$image_size]['height'] . '"}';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$size_str was never initialized. Although not strictly required by PHP, it is generally a good practice to add $size_str = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
32
				}
33
			
34
				if (isset($size_str) && !is_null($size_str)) {
35
					$img_sizes = "[" . implode(',', $size_str) . "]";
36
					$attr['data-sizes'] = $img_sizes;
37
				}
38
			
39
			}            
40
            
41
            return $attr;
42
        }
43
	}
44
}
45