ImageRotator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 43
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A rotate() 0 30 5
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\Api\UsageException;
7
use Mediawiki\DataModel\File;
8
9
/**
10
 * @access private
11
 *
12
 * @author Addshore
13
 */
14
class ImageRotator extends Service {
15
16
	/**
17
	 * NOTE: This service has not been fully tested
18
	 *
19
	 * @param File $file
20
	 * @param int $rotation Degrees to rotate image clockwise, One value: 90, 180, 270
21
	 *
22
	 * @throws UsageException
23
	 * @return bool
24
	 */
25
	public function rotate( File $file, $rotation ) {
26
		$params = [
27
			'rotation' => $rotation,
28
			'token' => $this->api->getToken(),
29
		];
30
31
		if ( $file->getPageIdentifier()->getTitle() !== null ) {
32
			$params['titles'] = $file->getPageIdentifier()->getTitle()->getText();
33
		} else {
34
			$params['pageids'] = $file->getPageIdentifier()->getId();
35
		}
36
37
		$result = $this->api->postRequest( new SimpleRequest( 'imagerotate', $params ) );
38
39
		// This module sometimes gives odd errors so deal with them..
40
		if ( array_key_exists( 'imagerotate', $result ) ) {
41
			$imageRotate = array_pop( $result['imagerotate'] );
42
			if ( array_key_exists( 'result', $imageRotate ) &&
43
				$imageRotate['result'] == 'Failure'
44
			) {
45
				throw new UsageException(
46
					'imagerotate-Failure',
47
					$imageRotate['errormessage'],
48
					$result
49
				);
50
			}
51
		}
52
53
		return true;
54
	}
55
56
}
57