PropertyAnnotator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 64
ccs 24
cts 24
cp 1
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A addAnnotation() 0 19 4
A canAnnotate() 0 7 4
A initPropertyAnnotators() 0 5 1
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(
0 ignored issues
show
Bug introduced by
The method info() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
		$this->logger->/** @scrutinizer ignore-call */ 
66
                 info(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66 1
			[ 'SemanticApprovedRevs', 'procTime:{procTime}' ],
0 ignored issues
show
Bug introduced by
array('SemanticApprovedR... 'procTime:{procTime}') of type array<integer,string> is incompatible with the type string expected by parameter $message of Psr\Log\LoggerInterface::info(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
			/** @scrutinizer ignore-type */ [ 'SemanticApprovedRevs', 'procTime:{procTime}' ],
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