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/cache_busting ( b901fc...6e1449 )
by Brad
04:14 queued 44s
created

run_thumbnail_generation_tests()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 18
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 28
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
		    global $foogallery_last_generated_thumb_url;
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...
18
19
			$arg_defaults = array(
20
				'width'                   => 0,
21
				'height'                  => 0,
22
				'crop'                    => true,
23
				'jpeg_quality'            => foogallery_thumbnail_jpeg_quality(),
24
				'thumb_resize_animations' => foogallery_get_setting( 'thumb_resize_animations' )
25
			);
26
27
			$args = wp_parse_args( $args, $arg_defaults );
28
29
			if ( 'on' === foogallery_get_setting( 'use_original_thumbs' ) ) {
30
				$width  = (int)$args['width'];
31
				$height = (int)$args['height'];
32
				$crop   = (bool)$args['crop'];
33
34
				//check if we are trying to get back the default thumbnail that we already have
35
				if ( $thumbnail_object->ID > 0 && $width == get_option( 'thumbnail_size_w' ) && $height == get_option( 'thumbnail_size_h' ) && $crop == get_option( 'thumbnail_crop' ) ) {
36
					$thumbnail_attributes = wp_get_attachment_image_src( $thumbnail_object->ID );
37
38
					return $thumbnail_attributes[0];
39
				}
40
			}
41
42
			if ( $thumbnail_object->ID > 0 ) {
43
				$crop_from_position = get_post_meta( $thumbnail_object->ID, 'wpthumb_crop_pos', true );
44
45
				if ( !empty( $crop_from_position ) ) {
46
					$args['crop_from_position'] = $crop_from_position;
47
				}
48
			}
49
50
			//save the generated thumb url to a global so that we can use it later if needed
51
            $foogallery_last_generated_thumb_url = wpthumb( $original_image_src, $args );
52
53
            return $foogallery_last_generated_thumb_url;
54
		}
55
56
		function run_thumbnail_generation_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...
57
            $test_image_url = foogallery_test_thumb_url();
58
59
            //first, clear any previous cached files
60
            $thumb = new WP_Thumb( $test_image_url );
61
            wpthumb_rmdir_recursive( $thumb->getCacheFileDirectory() );
62
63
            //next, generate a thumbnail
64
			$test_args = array(
65
				'width'                   => 20,
66
				'height'                  => 20,
67
				'crop'                    => true,
68
				'jpeg_quality'            => foogallery_thumbnail_jpeg_quality()
69
			);
70
			$test_thumb = new WP_Thumb( $test_image_url, $test_args );
71
            $generated_thumb = $test_thumb->returnImage();
72
            $success = $test_image_url !== $generated_thumb;
73
74
			$test_results = array(
75
			    'success' => $success,
76
				'thumb' => $generated_thumb,
77
				'error' => $test_thumb->error(),
78
			);
79
80
            do_action( 'foogallery_thumbnail_generation_test', $test_results );
81
82
            return $test_results;
83
		}
84
	}
85
}
86