Completed
Push — update/media-extractor-summary... ( 317788...ea9570 )
by Jeremy
34:42 queued 06:44
created

Jetpack_JSON_API_Jetpack_Log_Endpoint::result()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.2
cc 4
eloc 6
nc 8
nop 0
1
<?php
2
3
class Jetpack_JSON_API_Jetpack_Log_Endpoint extends Jetpack_JSON_API_Endpoint {
4
	// GET /sites/%s/jetpack-log
5
	protected $needed_capabilities = 'manage_options';
6
7
	protected function result() {
8
		$args = $this->input();
9
		$event = ( isset( $args['event'] ) && is_string( $args['event'] ) ) ? $code : false;
0 ignored issues
show
Bug introduced by
The variable $code does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
10
		$num  = ( isset( $args['num'] ) ) ? intval( $num ) : false;
0 ignored issues
show
Bug introduced by
The variable $num seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
11
12
		return array(
13
			'log' => Jetpack::get_log( $event, $num )
0 ignored issues
show
Bug introduced by
It seems like $num defined by isset($args['num']) ? intval($num) : false on line 10 can also be of type integer; however, Jetpack::get_log() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
14
		);
15
	}
16
}
17