Completed
Push — main ( 2daa48...b5d932 )
by
unknown
08:38
created

Parser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 34
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Addwiki\Mediawiki\Api\Service;
4
5
use Addwiki\Mediawiki\Api\Client\SimpleRequest;
6
use Addwiki\Mediawiki\DataModel\PageIdentifier;
7
use GuzzleHttp\Promise\PromiseInterface;
8
use RuntimeException;
9
10
/**
11
 * @access private
12
 *
13
 * @author Addshore
14
 */
15
class Parser extends Service {
16
17
	/**
18
	 * @param PageIdentifier $pageIdentifier
19
	 *
20
	 * @return array the parse result (raw from the api)
21
	 */
22
	public function parsePage( PageIdentifier $pageIdentifier ): array {
23
		return $this->parsePageAsync( $pageIdentifier )->wait();
24
	}
25
26
	/**
27
	 * @param PageIdentifier $pageIdentifier
28
	 *
29
	 * @return PromiseInterface of array the parse result (raw from the api)
30
	 */
31
	public function parsePageAsync( PageIdentifier $pageIdentifier ): \GuzzleHttp\Promise\PromiseInterface {
32
		$params = [];
33
		if ( $pageIdentifier->getId() !== null ) {
34
			$params['pageid'] = $pageIdentifier->getId();
35
		} elseif ( $pageIdentifier->getTitle() !== null ) {
36
			$params['page'] = $pageIdentifier->getTitle()->getText();
37
		} else {
38
			throw new RuntimeException( 'No way to identify page' );
39
		}
40
41
		$promise = $this->api->getRequestAsync( new SimpleRequest( 'parse', $params ) );
42
43
		return $promise->then( fn( $result ) => $result['parse'] );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ')'
Loading history...
44
	}
45
46
}
47