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.

Freemius_Api_Base::IsSandbox()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
	/**
3
	 * Copyright 2014 Freemius, Inc.
4
	 *
5
	 * Licensed under the GPL v2 (the "License"); you may
6
	 * not use this file except in compliance with the License. You may obtain
7
	 * a copy of the License at
8
	 *
9
	 *     http://choosealicense.com/licenses/gpl-v2/
10
	 *
11
	 * Unless required by applicable law or agreed to in writing, software
12
	 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
	 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
	 * License for the specific language governing permissions and limitations
15
	 * under the License.
16
	 */
17
18
	if ( ! defined( 'FS_API__VERSION' ) ) {
19
		define( 'FS_API__VERSION', '1' );
20
	}
21
	if ( ! defined( 'FS_SDK__PATH' ) ) {
22
		define( 'FS_SDK__PATH', dirname( __FILE__ ) );
23
	}
24
	if ( ! defined( 'FS_SDK__EXCEPTIONS_PATH' ) ) {
25
		define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
26
	}
27
28
	if ( ! function_exists( 'json_decode' ) ) {
29
		throw new Exception( 'Freemius needs the JSON PHP extension.' );
30
	}
31
32
	// Include all exception files.
33
	$exceptions = array(
34
		'Exception',
35
		'InvalidArgumentException',
36
		'ArgumentNotExistException',
37
		'EmptyArgumentException',
38
		'OAuthException'
39
	);
40
41
	foreach ( $exceptions as $e ) {
42
		require_once FS_SDK__EXCEPTIONS_PATH . $e . '.php';
43
	}
44
45
	if ( class_exists( 'Freemius_Api_Base' ) ) {
46
		return;
47
	}
48
49
	abstract class Freemius_Api_Base {
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...
50
		const VERSION = '1.0.4';
51
		const FORMAT = 'json';
52
53
		protected $_id;
54
		protected $_public;
55
		protected $_secret;
56
		protected $_scope;
57
		protected $_isSandbox;
58
59
		/**
60
		 * @param string $pScope     'app', 'developer', 'plugin', 'user' or 'install'.
61
		 * @param number $pID        Element's id.
62
		 * @param string $pPublic    Public key.
63
		 * @param string $pSecret    Element's secret key.
64
		 * @param bool   $pIsSandbox Whether or not to run API in sandbox mode.
65
		 */
66
		public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
67
			$this->_id        = $pID;
68
			$this->_public    = $pPublic;
69
			$this->_secret    = $pSecret;
70
			$this->_scope     = $pScope;
71
			$this->_isSandbox = $pIsSandbox;
72
		}
73
74
		public function IsSandbox() {
75
			return $this->_isSandbox;
76
		}
77
78
		function CanonizePath( $pPath ) {
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...
79
			$pPath     = trim( $pPath, '/' );
80
			$query_pos = strpos( $pPath, '?' );
81
			$query     = '';
82
83
			if ( false !== $query_pos ) {
84
				$query = substr( $pPath, $query_pos );
85
				$pPath = substr( $pPath, 0, $query_pos );
86
			}
87
88
			// Trim '.json' suffix.
89
			$format_length = strlen( '.' . self::FORMAT );
90
			$start         = $format_length * ( - 1 ); //negative
91
			if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
92
				$pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
93
			}
94
95
			switch ( $this->_scope ) {
96
				case 'app':
97
					$base = '/apps/' . $this->_id;
98
					break;
99
				case 'developer':
100
					$base = '/developers/' . $this->_id;
101
					break;
102
				case 'user':
103
					$base = '/users/' . $this->_id;
104
					break;
105
				case 'plugin':
106
					$base = '/plugins/' . $this->_id;
107
					break;
108
				case 'install':
109
					$base = '/installs/' . $this->_id;
110
					break;
111
				default:
112
					throw new Freemius_Exception( 'Scope not implemented.' );
0 ignored issues
show
Documentation introduced by
'Scope not implemented.' is of type string, but the function expects a array.

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...
113
			}
114
115
			return '/v' . FS_API__VERSION . $base .
116
			       ( ! empty( $pPath ) ? '/' : '' ) . $pPath .
117
			       ( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
118
		}
119
120
		abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
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...
121
122
		/**
123
		 * @param string $pPath
124
		 * @param string $pMethod
125
		 * @param array  $pParams
126
		 *
127
		 * @return object[]|object|null
128
		 */
129
		private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
130
			$pMethod = strtoupper( $pMethod );
131
132
			try {
133
				$result = $this->MakeRequest( $pPath, $pMethod, $pParams );
134
			} catch ( Freemius_Exception $e ) {
135
				// Map to error object.
136
				$result = (object) $e->getResult();
137
			} catch ( Exception $e ) {
138
				// Map to error object.
139
				$result = (object) array(
140
					'error' => array(
141
						'type'    => 'Unknown',
142
						'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
143
						'code'    => 'unknown',
144
						'http'    => 402
145
					)
146
				);
147
			}
148
149
			return $result;
150
		}
151
152
		public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
153
			return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
154
		}
155
156
		/**
157
		 * Base64 decoding that does not need to be urldecode()-ed.
158
		 *
159
		 * Exactly the same as PHP base64 encode except it uses
160
		 *   `-` instead of `+`
161
		 *   `_` instead of `/`
162
		 *   No padded =
163
		 *
164
		 * @param string $input Base64UrlEncoded() string
165
		 *
166
		 * @return string
167
		 */
168
		protected static function Base64UrlDecode( $input ) {
169
			/**
170
			 * IMPORTANT NOTE:
171
			 * This is a hack suggested by @otto42 and @greenshady from
172
			 * the theme's review team. The usage of base64 for API
173
			 * signature encoding was approved in a Slack meeting
174
			 * held on Tue (10/25 2016).
175
			 *
176
			 * @todo Remove this hack once the base64 error is removed from the Theme Check.
177
			 *
178
			 * @since 1.2.2
179
			 * @author Vova Feldman (@svovaf)
180
			 */
181
			$fn = 'base64' . '_decode';
182
			return $fn( strtr( $input, '-_', '+/' ) );
183
		}
184
185
		/**
186
		 * Base64 encoding that does not need to be urlencode()ed.
187
		 *
188
		 * Exactly the same as base64 encode except it uses
189
		 *   `-` instead of `+
190
		 *   `_` instead of `/`
191
		 *
192
		 * @param string $input string
193
		 *
194
		 * @return string Base64 encoded string
195
		 */
196
		protected static function Base64UrlEncode( $input ) {
197
			/**
198
			 * IMPORTANT NOTE:
199
			 * This is a hack suggested by @otto42 and @greenshady from
200
			 * the theme's review team. The usage of base64 for API
201
			 * signature encoding was approved in a Slack meeting
202
			 * held on Tue (10/25 2016).
203
			 *
204
			 * @todo Remove this hack once the base64 error is removed from the Theme Check.
205
			 *
206
			 * @since 1.2.2
207
			 * @author Vova Feldman (@svovaf)
208
			 */
209
			$fn = 'base64' . '_encode';
210
			$str = strtr( $fn( $input ), '+/', '-_' );
211
			$str = str_replace( '=', '', $str );
212
213
			return $str;
214
		}
215
	}
216