ApprovedDatePropertyAnnotator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 75
ccs 27
cts 30
cp 0.9
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A newDITime() 0 15 3
A newDIProperty() 0 2 1
A __construct() 0 2 1
A addAnnotation() 0 15 3
A setApprovedDate() 0 2 1
1
<?php
2
3
namespace SMW\ApprovedRevs\PropertyAnnotators;
4
5
use SMW\DIProperty;
6
use SMW\SemanticData;
7
use SMWDITime as DITime;;
8
use SMW\ApprovedRevs\DatabaseLogReader;
9
use SMW\ApprovedRevs\PropertyRegistry;
10
use User;
0 ignored issues
show
Bug introduced by
The type User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * @private
14
 *
15
 * @license GNU GPL v2+
16
 */
17
class ApprovedDatePropertyAnnotator {
18
19
	/**
20
	 * @var DatabaseLogReader
21
	 */
22
	private $databaseLogReader;
23
24
	/**
25
	 * @var Integer|null
26
	 */
27
	private $approvedDate;
28
29
	/**
30
	 * @param DatabaseLogReader $databaseLogReader
31
	 */
32 3
	public function __construct( DatabaseLogReader $databaseLogReader ) {
33 3
		$this->databaseLogReader = $databaseLogReader;
34 3
	}
35
36
	/**
37
	 * @since 1.0
38
	 *
39
	 * @param integer $approvedDate
40
	 */
41 2
	public function setApprovedDate( $approvedDate ) {
42 2
		$this->approvedDate = $approvedDate;
43 2
	}
44
45
	/**
46
	 * @since 1.0
47
	 *
48
	 * @return DIProperty
49
	 */
50 2
	public function newDIProperty() {
51 2
		return new DIProperty( PropertyRegistry::SAR_PROP_APPROVED_DATE );
52
	}
53
54
	/**
55
	 * @since 1.0
56
	 *
57
	 * @param SemanticData $semanticData
58
	 */
59 2
	public function addAnnotation( SemanticData $semanticData ) {
60
61 2
		if ( $this->approvedDate === null ) {
62
			$this->approvedDate = $this->databaseLogReader->getDateOfLogEntry(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->databaseLogReader...getTitle(), 'approval') of type SMW\ApprovedRevs\Timestamp is incompatible with the declared type integer|null of property $approvedDate.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63
				$semanticData->getSubject()->getTitle(),
64
				'approval'
65
			);
66
		}
67
68 2
		$property = $this->newDIProperty();
69 2
		$dataItem = $this->newDITime();
70 2
		$semanticData->removeProperty( $property );
71
72 2
		if ( $dataItem ) {
73 1
			$semanticData->addPropertyObjectValue( $property, $dataItem );
74
		}
75 2
	}
76
77 2
	private function newDITime() {
78
79 2
		if ( $this->approvedDate === null || is_bool( $this->approvedDate ) ) {
80 1
			return;
81
		}
82
83 1
		$date = $this->approvedDate;
84
85 1
		return new DITime(
86 1
			DITime::CM_GREGORIAN,
87 1
			$date->format( 'Y' ),
0 ignored issues
show
Bug introduced by
The method format() does not exist on integer. ( Ignorable by Annotation )

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

87
			$date->/** @scrutinizer ignore-call */ 
88
          format( 'Y' ),

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...
88 1
			$date->format( 'm' ),
89 1
			$date->format( 'd' ),
90 1
			$date->format( 'H' ),
91 1
			$date->format( 'i' )
92
		);
93
	}
94
95
}
96