SemanticMediaWiki /
SemanticApprovedRevs
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 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; |
||
| 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
It seems like
$this->databaseLogReader...getTitle(), 'approval') can also be of type object<MWTimestamp>. However, the property $approvedDate is declared as type integer|null. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
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
|
|||
| 88 | 1 | $date->format( 'm' ), |
|
|
0 ignored issues
–
show
|
|||
| 89 | 1 | $date->format( 'd' ), |
|
|
0 ignored issues
–
show
|
|||
| 90 | 1 | $date->format( 'H' ), |
|
|
0 ignored issues
–
show
|
|||
| 91 | 1 | $date->format( 'i' ) |
|
|
0 ignored issues
–
show
|
|||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | } |
||
| 96 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.