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/thumb_generation_testi... ( 03ac2b )
by Brad
02:55
created

FooGallery_Thumbnails::run_tests()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 33
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 44
rs 8.8571
1
<?php
2
/*
3
 * FooGallery Thumbnail Resizing class
4
 */
5
6
if ( !class_exists( 'FooGallery_Thumbnails' ) ) {
7
8
	class FooGallery_Thumbnails {
9
10
		function __construct() {
11
			//generate thumbs using WPThumb
12
			add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'resize' ), 10, 3 );
13
		}
14
15
		function resize( $original_image_src, $args, $thumbnail_object ) {
16
17
			$arg_defaults = array(
18
				'width'                   => 0,
19
				'height'                  => 0,
20
				'crop'                    => true,
21
				'jpeg_quality'            => foogallery_thumbnail_jpeg_quality(),
22
				'thumb_resize_animations' => foogallery_get_setting( 'thumb_resize_animations' )
23
			);
24
25
			$args = wp_parse_args( $args, $arg_defaults );
26
27
			if ( 'on' === foogallery_get_setting( 'use_original_thumbs' ) ) {
28
				$width  = (int)$args['width'];
29
				$height = (int)$args['height'];
30
				$crop   = (bool)$args['crop'];
31
32
				//check if we are trying to get back the default thumbnail that we already have
33
				if ( $thumbnail_object->ID > 0 && $width == get_option( 'thumbnail_size_w' ) && $height == get_option( 'thumbnail_size_h' ) && $crop == get_option( 'thumbnail_crop' ) ) {
34
					$thumbnail_attributes = wp_get_attachment_image_src( $thumbnail_object->ID );
35
36
					return $thumbnail_attributes[0];
37
				}
38
			}
39
40
			if ( $thumbnail_object->ID > 0 ) {
41
				$crop_from_position = get_post_meta( $thumbnail_object->ID, 'wpthumb_crop_pos', true );
42
43
				if ( !empty( $crop_from_position ) ) {
44
					$args['crop_from_position'] = $crop_from_position;
45
				}
46
			}
47
48
			return wpthumb( $original_image_src, $args );
49
		}
50
51
		function run_tests() {
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...
52
			$test_image_url = FOOGALLERY_URL . '/assets/test_thumb_1.jpg';
53
			$thumb_width = get_option( 'thumbnail_size_w' );
54
			$thumb_height = get_option( 'thumbnail_size_h' );
55
56
			$test1_args = array(
57
				'width'                   => 20,
58
				'height'                  => 20,
59
				'crop'                    => true,
60
				'jpeg_quality'            => foogallery_thumbnail_jpeg_quality()
61
			);
62
			$thumb1 = new WP_Thumb( $test_image_url, $test1_args );
63
			$results[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$results was never initialized. Although not strictly required by PHP, it is generally a good practice to add $results = 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...
64
				'thumb' => $thumb1->returnImage(),
65
				'error' => $thumb1->error(),
66
			);
67
68
			$test2_args = array(
69
					'width'                   => 50,
70
					'height'                  => 80,
71
					'crop'                    => true,
72
					'crop_from_position'	  => 'right,center',
73
					'jpeg_quality'            => foogallery_thumbnail_jpeg_quality()
74
			);
75
			$thumb2 = new WP_Thumb( $test_image_url, $test2_args );
76
			$results[] = array(
77
					'thumb' => $thumb2->returnImage(),
78
					'error' => $thumb2->error(),
79
			);
80
81
			$test3_args = array(
82
				'width'                   => $thumb_width,
83
				'height'                  => $thumb_height,
84
				'crop'                    => true,
85
				'jpeg_quality'            => foogallery_thumbnail_jpeg_quality()
86
			);
87
			$thumb3 = new WP_Thumb( $test_image_url, $test3_args );
88
			$results[] = array(
89
				'thumb' => $thumb3->returnImage(),
90
				'error' => $thumb3->error(),
91
			);
92
93
			return $results;
94
		}
95
	}
96
}
97