Completed
Push — add/debugger-blog-token ( 149038...c1053a )
by
unknown
33:02 queued 25:29
created

Jetpack_IXR_ClientMulticall::addCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * IXR_ClientMulticall
4
 *
5
 * @package automattic/jetpack-connection
6
 *
7
 * @since 1.5
8
 * @since 7.7 Moved to the jetpack-connection package.
9
 */
10
11
/**
12
 * A Jetpack implementation of the WordPress core IXR client, capable of multiple calls in a single request.
13
 */
14
class Jetpack_IXR_ClientMulticall extends Jetpack_IXR_Client {
15
	/**
16
	 * Storage for the IXR calls.
17
	 *
18
	 * @var array
19
	 */
20
	public $calls = array();
21
22
	/**
23
	 * Add a IXR call to the client.
24
	 * First argument is the method name.
25
	 * The rest of the arguments are the params specified to the method.
26
	 *
27
	 * @param string[] ...$args IXR args.
28
	 */
0 ignored issues
show
Documentation introduced by
Should the type for parameter $args not be string[][]?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
	public function addCall( ...$args ) {
30
		$method_name   = array_shift( $args );
31
		$struct        = array(
32
			'methodName' => $method_name,
33
			'params'     => $args,
34
		);
35
		$this->calls[] = $struct;
36
	}
37
38
	/**
39
	 * Perform the IXR multicall request.
40
	 *
41
	 * @param string[] ...$args IXR args.
42
	 *
43
	 * @return bool True if request succeeded, false otherwise.
44
	 */
0 ignored issues
show
Documentation introduced by
Should the type for parameter $args not be string[][]?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
45
	public function query( ...$args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
		usort( $this->calls, array( $this, 'sort_calls' ) );
47
48
		// Prepare multicall, then call the parent::query() method.
49
		return parent::query( 'system.multicall', $this->calls );
50
	}
51
52
	/**
53
	 * Sort the IXR calls.
54
	 * Make sure syncs are always done first.
55
	 *
56
	 * @param array $a First call in the sorting iteration.
57
	 * @param array $b Second call in the sorting iteration.
58
	 * @return int Result of the sorting iteration.
59
	 */
60
	public function sort_calls( $a, $b ) {
61
		if ( 'jetpack.syncContent' === $a['methodName'] ) {
62
			return -1;
63
		}
64
65
		if ( 'jetpack.syncContent' === $b['methodName'] ) {
66
			return 1;
67
		}
68
69
		return 0;
70
	}
71
}
72