| Conditions | 4 |
| Paths | 5 |
| Total Lines | 30 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 52 | public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
||
| 53 | |||
| 54 | $title = $semanticData->getSubject()->getTitle(); |
||
| 55 | |||
| 56 | if ( !$title->inNamespace( NS_USER ) ) { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $user = $this->appFactory->newUserFromTitle( $title ); |
||
|
|
|||
| 61 | $dataItem = null; |
||
| 62 | |||
| 63 | if ( $user instanceof User ) { |
||
| 64 | |||
| 65 | $timestamp = wfTimestamp( TS_ISO_8601, $user->getRegistration() ); |
||
| 66 | $date = new \DateTime( $timestamp ); |
||
| 67 | |||
| 68 | $dataItem = new DITime( |
||
| 69 | DITime::CM_GREGORIAN, |
||
| 70 | $date->format('Y'), |
||
| 71 | $date->format('m'), |
||
| 72 | $date->format('d'), |
||
| 73 | $date->format('H'), |
||
| 74 | $date->format('i') |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ( $dataItem instanceof DataItem ) { |
||
| 79 | $semanticData->addPropertyObjectValue( $property, $dataItem ); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 84 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: