ProfessionalWiki /
ModernTimeline
| 1 | <?php |
||
| 2 | |||
| 3 | declare( strict_types = 1 ); |
||
| 4 | |||
| 5 | namespace ModernTimeline; |
||
| 6 | |||
| 7 | use MediaWiki\MediaWikiServices; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use ModernTimeline\ResultFacade\PropertyValueCollection; |
||
| 9 | use ModernTimeline\ResultFacade\Subject; |
||
| 10 | use ModernTimeline\ResultFacade\SubjectCollection; |
||
| 11 | use RepoGroup; |
||
|
0 ignored issues
–
show
The type
RepoGroup 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | use SMW\DIWikiPage; |
||
|
0 ignored issues
–
show
The type
SMW\DIWikiPage 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use SMWDITime; |
||
|
0 ignored issues
–
show
The type
SMWDITime 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | |||
| 15 | class EventExtractor { |
||
| 16 | |||
| 17 | public function __construct( |
||
| 18 | 7 | private array $parameters |
|
| 19 | 7 | ) { |
|
| 20 | 7 | } |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @param SubjectCollection $pages |
||
| 24 | * @return Event[] |
||
| 25 | */ |
||
| 26 | 7 | public function extractEvents( SubjectCollection $pages ): array { |
|
| 27 | 7 | $events = []; |
|
| 28 | |||
| 29 | 7 | foreach ( $pages->getSubjects() as $subject ) { |
|
| 30 | 5 | [ $startDate, $endDate ] = $this->getDates( $subject ); |
|
| 31 | |||
| 32 | 5 | if ( $startDate !== null ) { |
|
| 33 | 4 | $event = new Event( $subject, $startDate, $endDate ); |
|
| 34 | |||
| 35 | 4 | foreach ( $subject->getPropertyValueCollections() as $propertyValues ) { |
|
| 36 | 4 | if ( $propertyValues->getPrintRequest()->getText( null ) === $this->parameters['image property'] ) { |
|
| 37 | 3 | foreach ( $propertyValues->getDataItems() as $dataItem ) { |
|
| 38 | 3 | if ( $this->isImageValue( $dataItem ) ) { |
|
| 39 | $event->setImageUrl( $this->getUrlForFileTitle( $dataItem->getTitle() ) ); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 4 | $events[] = $event; |
|
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 7 | return $events; |
|
| 50 | } |
||
| 51 | |||
| 52 | 3 | private function isImageValue( \SMWDataItem $dataItem ): bool { |
|
|
0 ignored issues
–
show
The type
SMWDataItem 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 53 | 3 | return $dataItem instanceof DIWikiPage |
|
| 54 | 3 | && $dataItem->getTitle() instanceof \Title |
|
|
0 ignored issues
–
show
The type
Title 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 55 | 3 | && $dataItem->getTitle()->getNamespace() === NS_FILE |
|
|
0 ignored issues
–
show
|
|||
| 56 | 3 | && $dataItem->getTitle()->exists(); |
|
| 57 | } |
||
| 58 | |||
| 59 | public function getUrlForFileTitle( \Title $existingTitle ): string { |
||
| 60 | return MediaWikiServices::getInstance()->getRepoGroup()->findFile( $existingTitle )->getURL(); |
||
| 61 | } |
||
| 62 | |||
| 63 | 5 | private function getDates( Subject $subject ): array { |
|
| 64 | 5 | $startDate = null; |
|
| 65 | 5 | $endDate = null; |
|
| 66 | |||
| 67 | 5 | foreach ( $this->getPropertyValueCollectionsWithDates( $subject ) as $propertyValues ) { |
|
| 68 | 4 | $dataItem = $propertyValues->getDataItems()[0]; |
|
| 69 | |||
| 70 | 4 | if ( $dataItem instanceof SMWDITime ) { |
|
| 71 | 4 | if ( $startDate === null ) { |
|
| 72 | 4 | $startDate = $dataItem; |
|
| 73 | } |
||
| 74 | 1 | elseif ( $endDate === null ) { |
|
| 75 | 1 | $endDate = $dataItem; |
|
| 76 | 1 | break; |
|
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | 5 | return [ $startDate, $endDate ]; |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return PropertyValueCollection[] |
||
| 86 | */ |
||
| 87 | 5 | private function getPropertyValueCollectionsWithDates( Subject $subject ): array { |
|
| 88 | 5 | return array_filter( |
|
| 89 | 5 | $subject->getPropertyValueCollections()->toArray(), |
|
| 90 | 5 | function( PropertyValueCollection $pvc ) { |
|
| 91 | 4 | return $pvc->getPrintRequest()->getTypeID() === '_dat' |
|
| 92 | 4 | && $pvc->getDataItems() !== []; |
|
| 93 | 5 | } |
|
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 97 | } |
||
| 98 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths