Completed
Push — master ( 3f5086...28f5b7 )
by mw
02:06
created

PropertyAnnotator::canAnnotate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 1
crap 4
1
<?php
2
3
namespace SMW\ApprovedRevs;
4
5
use Psr\Log\LoggerAwareTrait;
6
use SMW\DIProperty;
7
use SMW\SemanticData;
8
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedStatusPropertyAnnotator;
9
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedByPropertyAnnotator;
10
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedDatePropertyAnnotator;
11
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedRevPropertyAnnotator;
12
13
/**
14
 * @private
15
 *
16
 * @license GNU GPL v2+
17
 * @since 1.0
18
 *
19
 * @author mwjames
20
 */
21
class PropertyAnnotator {
22
23
	use LoggerAwareTrait;
24
25
	/**
26
	 * @var ServicesFactory
27
	 */
28
	private $servicesFactory;
29
30
	/**
31
	 * @var PropertyAnnotator[]
32
	 */
33
	private $propertyAnnotators = [];
34
35
	/**
36
	 * @since 1.0
37
	 *
38
	 * @param ServicesFactory $servicesFactory
39
	 */
40 3
	public function __construct( ServicesFactory $servicesFactory ) {
41 3
		$this->servicesFactory = $servicesFactory;
42 3
	}
43
44
	/**
45
	 * @since 1.0
46
	 *
47
	 * @param SemanticData $semanticData
48
	 */
49 2
	public function addAnnotation( SemanticData $semanticData ) {
50
51 2
		$time = microtime( true );
52
53 2
		if ( !$this->canAnnotate( $semanticData->getSubject() ) ) {
54 1
			return;
55
		}
56
57 1
		if ( $this->propertyAnnotators === [] ) {
58 1
			$this->initPropertyAnnotators();
59
		}
60
61 1
		foreach ( $this->propertyAnnotators as $propertyAnnotator ) {
62 1
			$propertyAnnotator->addAnnotation( $semanticData );
63
		}
64
65 1
		$this->logger->info(
66 1
			[ 'SemanticApprovedRevs', 'procTime:{procTime}' ],
0 ignored issues
show
Documentation introduced by
array('SemanticApprovedR... 'procTime:{procTime}') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67 1
			[ 'procTime' => round( ( microtime( true ) - $time ), 5 ) ]
68
		);
69 1
	}
70
71 2
	private function canAnnotate( $subject ) {
72
73 2
		if ( $subject === null || $subject->getTitle() === null || $subject->getTitle()->isSpecialPage() ) {
74 1
			return false;
75
		}
76
77 1
		return true;
78
	}
79
80 1
	private function initPropertyAnnotators() {
81 1
		$this->propertyAnnotators[] = $this->servicesFactory->newApprovedByPropertyAnnotator();
82 1
		$this->propertyAnnotators[] = $this->servicesFactory->newApprovedStatusPropertyAnnotator();
83 1
		$this->propertyAnnotators[] = $this->servicesFactory->newApprovedDatePropertyAnnotator();
84 1
		$this->propertyAnnotators[] = $this->servicesFactory->newApprovedRevPropertyAnnotator();
85 1
	}
86
87
}
88