Completed
Push — branch-3.8 ( ee324b...b1dba8 )
by
unknown
32:49 queued 16:32
created

result()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4286
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
3
class Jetpack_JSON_API_Maybe_Auto_Update_Endpoint extends Jetpack_JSON_API_Endpoint {
4
	// POST /sites/%s/maybe_auto_update
5
	protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' );
6
7
	protected $update_results = array();
8
9
	protected function result() {
10
		add_action( 'automatic_updates_complete', array( $this, 'get_update_results' ), 100, 1 );
11
12
		wp_maybe_auto_update();
13
14
		$result['log'] = $this->update_results;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = 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...
15
16
		if ( empty( $result['log'] ) ) {
17
			$possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures();
18
19
			if ( $possible_reasons_for_failure ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $possible_reasons_for_failure of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
20
				$result['log']['error'] = $possible_reasons_for_failure;
21
			}
22
23
		}
24
25
		return $result;
26
	}
27
28
	public function get_update_results( $results ) {
29
		$this->update_results = $results;
30
	}
31
32
}
1 ignored issue
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
33