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/demo-content ( 34d331 )
by Brad
02:59
created

FooGallery_PixabayClient::search()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 2
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
/**
3
 * pixabay-php-api
4
 * PixabayClient API
5
 *
6
 * PHP Version 5
7
 *
8
 * @category Production
9
 * @package  Default
10
 * @author   Philipp Tkachev <[email protected]>
11
 * @date     12/14/14 9:18 AM
12
 * @license  https://www.zoonman.com/projects/pixabay/license.txt MIT
13
 * @version  GIT: 1.0
14
 * @link     https://www.zoonman.com/projects/pixabay/
15
 */
16
17
/**
18
 * Class PixabayClient
19
 * @package Pixabay\PixabayClient
20
 */
21
class FooGallery_PixabayClient {
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...
22
	/**
23
	 * @var array
24
	 */
25
	private $optionsList = [
0 ignored issues
show
Unused Code introduced by
The property $optionsList is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
		'key',
27
		'response_group',
28
		'id',
29
		'q',
30
		'lang',
31
		'callback',
32
		'image_type',
33
		'orientation',
34
		'category',
35
		'min_width',
36
		'min_height',
37
		'editors_choice',
38
		'safesearch',
39
		'page',
40
		'per_page',
41
		'pretty',
42
		'response_group',
43
		'order',
44
		'video_type'
45
	];
46
47
	/**
48
	 * Root of Pixabay REST API
49
	 */
50
	const API_ROOT = 'https://pixabay.com/api/';
51
52
	/**
53
	 * Get Data from Pixabay API
54
	 *
55
	 * @return mixed
56
	 */
57
	public function search( $key, $query )
58
	{
59
		$options['key'] = $key;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = 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...
60
		$options['q'] = $query;
61
62
		$url = add_query_arg( array(
63
			'key' => $key,
64
			'q' => $query,
65
		), self::API_ROOT );
66
67
		$transient_key = 'foogallery-pixabay-' . esc_attr($query);
68
69
		if ( false === ( $response_data = get_transient( $transient_key ) ) ) {
70
			$response = wp_remote_get( esc_url( $url ) );
71
			$response_data = wp_remote_retrieve_body( $response );
72
73
			$expires = 60 * 60 * 24; //cache for 24 hours
74
75
			//Cache the result
76
			set_transient( $transient_key, $response_data, $expires );
77
		}
78
79
		return json_decode( $response_data, false );
80
	}
81
}