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 — master ( b0f362...88f370 )
by Brad
07:37 queued 03:48
created

FooGallery_Default_Crop_Position::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class to provide a way to override the default attachment crop position. Handy if you want to override the default of center,center
4
 * Date: 19/02/2018
5
 *
6
 * @since 1.4.18
7
 */
8
if ( ! class_exists( 'FooGallery_Default_Crop_Position' ) ) {
9
10
	class FooGallery_Default_Crop_Position {
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...
11
12
		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...
13
			add_filter( 'foogallery_admin_settings_override', array( $this, 'add_default_crop_position_setting' ) );
14
			add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_crop_position_setting' ) );
15
			add_filter( 'wpthumb_default_crop_position', array( $this, 'override_default_crop_position' ) );
16
		}
17
18
		/**
19
		 * Adds the crop position setting to the settings array
20
		 *
21
		 * @param $settings
22
		 *
23
		 * @return mixed
24
		 */
25
		function add_default_crop_position_setting( $settings ) {
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...
26
			$just_settings = $settings['settings'];
27
			$position = 0;
28
			//find the position of the 'thumb_jpeg_quality' setting
29
			foreach( $just_settings as $setting ) {
30
				$position++;
31
				if ( 'thumb_jpeg_quality' === $setting['id'] ) {
32
					break;
33
				}
34
			}
35
36
			$new_settings[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$new_settings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $new_settings = 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...
37
				'id'      => 'default_crop_position',
38
				'title'   => __( 'Default Crop Position', 'foogallery' ),
39
				'desc'    => __( 'The default crop position when resizing thumbnails.', 'foogallery' ),
40
				'type'    => 'crop',
41
				'default' => 'center,center',
42
				'tab'     => 'thumb'
43
			);
44
45
			array_splice( $just_settings, $position, 0, $new_settings );
46
47
			$settings['settings'] = $just_settings;
48
49
			return $settings;
50
		}
51
52
		/**
53
		 * Render the custom crop position to the settings page
54
		 *
55
		 * @param array $args
56
		 */
57
		function render_crop_position_setting( $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...
58
			 if ( 'crop' === $args['type'] ) {
59
				$current_position = foogallery_get_setting( 'default_crop_position', 'center,center'); ?>
0 ignored issues
show
Documentation introduced by
'center,center' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
				<style>.foogallery_crop_pos input { margin: 5px !important; width: auto; }</style>
61
				<div class="foogallery_crop_pos">
62
					<input type="radio" name="foogallery[default_crop_position]" value="left,top" title="Left, Top" <?php checked( 'left,top', $current_position ) ?>/>
63
					<input type="radio" name="foogallery[default_crop_position]" value="center,top" title="Center, Top" <?php checked( 'center,top', $current_position ) ?>/>
64
					<input type="radio" name="foogallery[default_crop_position]" value="right,top" title="Right, Top" <?php checked( 'right,top', $current_position ) ?>/><br/>
65
					<input type="radio" name="foogallery[default_crop_position]" value="left,center" title="Left, Center" <?php checked( 'left,center', $current_position ) ?>/>
66
					<input type="radio" name="foogallery[default_crop_position]" value="center,center" title="Center, Center" <?php checked( 'center,center', $current_position ) ?>/>
67
					<input type="radio" name="foogallery[default_crop_position]" value="right,center" title="Right, Center" <?php checked( 'right,center', $current_position ) ?>/><br/>
68
					<input type="radio" name="foogallery[default_crop_position]" value="left,bottom" title="Left, Bottom" <?php checked( 'left,bottom', $current_position ) ?>/>
69
					<input type="radio" name="foogallery[default_crop_position]" value="center,bottom" title="Center, Bottom" <?php checked( 'center,bottom', $current_position ) ?>/>
70
					<input type="radio" name="foogallery[default_crop_position]" value="right,bottom" title="Right, Bottom" <?php checked( 'right,bottom', $current_position ) ?>/>
71
				</div>
72
			<?php }
73
		}
74
75
		function override_default_crop_position( $default ) {
0 ignored issues
show
Unused Code introduced by
The parameter $default 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...
76
			$crop_position = foogallery_get_setting( 'default_crop_position', 'center,center');
0 ignored issues
show
Documentation introduced by
'center,center' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
			return $crop_position;
78
		}
79
	}
80
}