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-dimensions ( 3a26b7 )
by Brad
05:02 queued 02:32
created

FooGallery_Thumbnail_Dimensions   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A start_watching_for_thumbnail_generation_calls() 0 12 2
A stop_watching_for_thumbnail_generation_calls() 0 15 3
B intercept_thumb_generation() 0 24 4
A change_thumbnail_resize_args() 0 5 1
1
<?php
2
/**
3
 * Class to calculate thumb dimensions for a gallery
4
 * Date: 21/03/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Thumbnail_Dimensions' ) ) {
7
8
	class FooGallery_Thumbnail_Dimensions {
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_action( 'foogallery_before_save_gallery', array( $this, 'start_watching_for_thumbnail_generation_calls' ), 10, 2 );
13
				add_action( 'foogallery_after_save_gallery', array( $this, 'stop_watching_for_thumbnail_generation_calls' ), 99, 2 );
14
			}
15
		}
16
17
		/**
18
		 * Start watching for calls to the thumbnail generator so we can intercept and store info about the thumbs
19
		 *
20
		 * @param $post_id
21
		 * @param $form_post
22
		 */
23
		function start_watching_for_thumbnail_generation_calls( $post_id, $form_post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_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...
24
			global $foogallery_thumb_dimensions;
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...
25
26
			//clear the array
27
			if ( empty( $foogallery_thumb_dimensions ) ) {
28
				$foogallery_thumb_dimensions[$post_id] = array();
29
			}
30
31
			//and hook up actions
32
			add_filter( 'wpthumb_image_post', array( $this, 'intercept_thumb_generation' ), 10, 2 );
33
			add_filter( 'foogallery_thumbnail_resize_args', array( $this, 'change_thumbnail_resize_args' ), 10, 3 );
34
		}
35
36
		/**
37
		 * Stop watching for calls to the thumbnail generator
38
		 *
39
		 * @param $post_id
40
		 * @param $form_post
41
		 */
42
		function stop_watching_for_thumbnail_generation_calls( $post_id, $form_post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_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...
43
			global $foogallery_thumb_dimensions;
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...
44
45
			//if we have nothing to store then get out
46
			if ( empty( $foogallery_thumb_dimensions ) || !array_key_exists( $post_id, $foogallery_thumb_dimensions ) ) {
47
				return;
48
			}
49
50
			//check if we have data and store it against the foogallery
51
			update_post_meta( $post_id, FOOGALLERY_META_THUMB_DIMENSIONS, $foogallery_thumb_dimensions[$post_id] );
52
53
			//unhook the action
54
			remove_filter( 'wpthumb_image_post', array( $this, 'intercept_thumb_generation' ), 10 );
55
			remove_filter( 'foogallery_thumbnail_resize_args', array( $this, 'change_thumbnail_resize_args' ), 10 );
56
		}
57
58
		/**
59
		 * Intercept calls to the thumb generation and store dimensions values
60
		 *
61
		 * @param $editor
62
		 * @param $args
63
		 */
64
		function intercept_thumb_generation( $editor, $args ) {
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...
65
			global $foogallery_thumb_dimensions;
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...
66
67
			//if we have nothing stored then get out
68
			if ( empty( $foogallery_thumb_dimensions ) ) {
69
				return;
70
			}
71
72
			//if we are not generating a thumb for a foogallery then get out
73
			if ( !array_key_exists( 'foogallery_id', $args ) ) {
74
				return;
75
			}
76
77
			//if we are not generating a thumb for a foogallery attachment then get out
78
			if ( !array_key_exists( 'foogallery_attachment_id', $args ) ) {
79
				return;
80
			}
81
82
			$foogallery_id = $args['foogallery_id'];
83
			$foogallery_attachment_id = $args['foogallery_attachment_id'];
84
			$size = $editor->get_size();
85
86
			$foogallery_thumb_dimensions[$foogallery_id][$foogallery_attachment_id] = $size;
87
		}
88
89
		/**
90
		 * Change any arguments passed to the thumb generation class
91
		 *
92
		 * @param $args
93
		 * @param $original_image_src
94
		 * @param $thumbnail_object
95
		 *
96
		 * @return mixed
97
		 */
98
		function change_thumbnail_resize_args($args, $original_image_src, $thumbnail_object) {
0 ignored issues
show
Unused Code introduced by
The parameter $original_image_src 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 $thumbnail_object 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...
99
			//we only want to force the thumb to be generated even if done so before
100
			$args['cache'] = false;
101
			return $args;
102
		}
103
	}
104
}