@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | private array $pages; |
8 | 8 | |
9 | - public function __construct( Subject ...$subjects ) { |
|
9 | + public function __construct(Subject ...$subjects) { |
|
10 | 10 | $this->pages = $subjects; |
11 | 11 | } |
12 | 12 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @param Subject[] $subjects |
15 | 15 | * @return self |
16 | 16 | */ |
17 | - public static function newFromArray( array $subjects ): self { |
|
17 | + public static function newFromArray(array $subjects): self { |
|
18 | 18 | $instance = new self(); |
19 | 19 | $instance->pages = $subjects; |
20 | 20 | return $instance; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\ResultFacade; |
6 | 6 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function buildPresenter(): ResultPresenter { |
36 | - return call_user_func( $this->constructionFunction ); |
|
36 | + return call_user_func($this->constructionFunction); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\ResultFacade; |
6 | 6 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -19,32 +19,32 @@ discard block |
||
19 | 19 | * @param Event[] $events |
20 | 20 | * @return array |
21 | 21 | */ |
22 | - public function eventsToTimelineJson( array $events ): array { |
|
22 | + public function eventsToTimelineJson(array $events): array { |
|
23 | 23 | $jsonEvents = []; |
24 | 24 | |
25 | - foreach ( $events as $event ) { |
|
26 | - if ( $event->getSubject()->getWikiPage()->getTitle() !== null ) { |
|
27 | - $jsonEvents[] = $this->buildEvent( $event ); |
|
25 | + foreach ($events as $event) { |
|
26 | + if ($event->getSubject()->getWikiPage()->getTitle() !== null) { |
|
27 | + $jsonEvents[] = $this->buildEvent($event); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | - return [ 'events' => $jsonEvents ]; |
|
31 | + return ['events' => $jsonEvents]; |
|
32 | 32 | } |
33 | 33 | |
34 | - public function buildEvent( Event $event ): array { |
|
34 | + public function buildEvent(Event $event): array { |
|
35 | 35 | $jsonEvent = [ |
36 | 36 | 'text' => [ |
37 | - 'headline' => $this->newHeadline( $event->getSubject()->getWikiPage()->getTitle() ), |
|
38 | - 'text' => $this->slidePresenter->getText( $event->getSubject() ) |
|
37 | + 'headline' => $this->newHeadline($event->getSubject()->getWikiPage()->getTitle()), |
|
38 | + 'text' => $this->slidePresenter->getText($event->getSubject()) |
|
39 | 39 | ], |
40 | - 'start_date' => $this->timeToJson( $event->getStartDate() ), |
|
40 | + 'start_date' => $this->timeToJson($event->getStartDate()), |
|
41 | 41 | ]; |
42 | 42 | |
43 | - if ( $event->getEndDate() !== null ) { |
|
44 | - $jsonEvent['end_date'] = $this->timeToJson( $event->getEndDate() ); |
|
43 | + if ($event->getEndDate() !== null) { |
|
44 | + $jsonEvent['end_date'] = $this->timeToJson($event->getEndDate()); |
|
45 | 45 | } |
46 | 46 | |
47 | - if ( $event->hasImage() ) { |
|
47 | + if ($event->hasImage()) { |
|
48 | 48 | $jsonEvent['media'] = [ |
49 | 49 | 'url' => $event->getImageUrl(), |
50 | 50 | 'thumbnail' => $event->getImageUrl() |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | return $jsonEvent; |
55 | 55 | } |
56 | 56 | |
57 | - private function newHeadline( \Title $title ): string { |
|
57 | + private function newHeadline(\Title $title): string { |
|
58 | 58 | return \Html::element( |
59 | 59 | 'a', |
60 | - [ 'href' => $title->getFullURL() ], |
|
60 | + ['href' => $title->getFullURL()], |
|
61 | 61 | $title->getText() |
62 | 62 | ); |
63 | 63 | |
64 | 64 | // return DataValueFactory::getInstance()->newDataValueByItem( $subject->getWikiPage() )->getLongHTMLText( smwfGetLinker() ); |
65 | 65 | } |
66 | 66 | |
67 | - private function timeToJson( SMWDITime $time ): array { |
|
67 | + private function timeToJson(SMWDITime $time): array { |
|
68 | 68 | return [ |
69 | 69 | 'year' => $time->getYear(), |
70 | 70 | 'month' => $time->getMonth(), |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -24,43 +24,43 @@ discard block |
||
24 | 24 | return 'modern_timeline_' . ++$timelineNumber; |
25 | 25 | } |
26 | 26 | |
27 | - public function presentResult( SimpleQueryResult $result ): string { |
|
28 | - SMWOutputs::requireResource( 'ext.modern.timeline' ); |
|
27 | + public function presentResult(SimpleQueryResult $result): string { |
|
28 | + SMWOutputs::requireResource('ext.modern.timeline'); |
|
29 | 29 | |
30 | 30 | SMWOutputs::requireHeadItem( |
31 | 31 | $this->id, |
32 | - $this->createJs( $this->createJsonString( $result ) ) |
|
32 | + $this->createJs($this->createJsonString($result)) |
|
33 | 33 | ); |
34 | 34 | |
35 | - return $this->createDiv( $result->getParameters() ); |
|
35 | + return $this->createDiv($result->getParameters()); |
|
36 | 36 | } |
37 | 37 | |
38 | - private function createJsonString( SimpleQueryResult $result ): string { |
|
39 | - $preJson = $this->newJsonBuilder( $result ) |
|
40 | - ->eventsToTimelineJson( ( new EventExtractor( $result->getParameters() ) )->extractEvents( $result->getSubjects() ) ); |
|
38 | + private function createJsonString(SimpleQueryResult $result): string { |
|
39 | + $preJson = $this->newJsonBuilder($result) |
|
40 | + ->eventsToTimelineJson((new EventExtractor($result->getParameters()))->extractEvents($result->getSubjects())); |
|
41 | 41 | |
42 | - $preJson['options'] = TimelineOptions::processedParamsToJson( $result->getParameters() ); |
|
42 | + $preJson['options'] = TimelineOptions::processedParamsToJson($result->getParameters()); |
|
43 | 43 | |
44 | - return json_encode( $preJson ); |
|
44 | + return json_encode($preJson); |
|
45 | 45 | } |
46 | 46 | |
47 | - private function newJsonBuilder( SimpleQueryResult $result ): JsonBuilder { |
|
47 | + private function newJsonBuilder(SimpleQueryResult $result): JsonBuilder { |
|
48 | 48 | return new JsonBuilder( |
49 | - $this->getSlidePresenter( $result ) |
|
49 | + $this->getSlidePresenter($result) |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - private function getSlidePresenter( SimpleQueryResult $result ): SlidePresenter { |
|
53 | + private function getSlidePresenter(SimpleQueryResult $result): SlidePresenter { |
|
54 | 54 | $templateName = $result->getParameters()['template']; |
55 | 55 | |
56 | - if ( $templateName === '' ) { |
|
57 | - return new SimpleSlidePresenter( $result->getProcessingResult()->getParameterArray() ); |
|
56 | + if ($templateName === '') { |
|
57 | + return new SimpleSlidePresenter($result->getProcessingResult()->getParameterArray()); |
|
58 | 58 | } |
59 | 59 | |
60 | - return new TemplateSlidePresenter( $templateName ); |
|
60 | + return new TemplateSlidePresenter($templateName); |
|
61 | 61 | } |
62 | 62 | |
63 | - private function createJs( string $json ): string { |
|
63 | + private function createJs(string $json): string { |
|
64 | 64 | return \Html::rawElement( |
65 | 65 | 'script', |
66 | 66 | [ |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | ); |
72 | 72 | } |
73 | 73 | |
74 | - private function createDiv( array $parameters ): string { |
|
74 | + private function createDiv(array $parameters): string { |
|
75 | 75 | $width = $parameters[TimelineOptions::PARAM_WIDTH]; |
76 | 76 | $height = $parameters[TimelineOptions::PARAM_HEIGHT]; |
77 | 77 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\SlidePresenter; |
6 | 6 | |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | ) { |
17 | 17 | } |
18 | 18 | |
19 | - public function getText( Subject $subject ): string { |
|
19 | + public function getText(Subject $subject): string { |
|
20 | 20 | $parser = $this->getParser(); |
21 | 21 | |
22 | 22 | return $parser->recursiveTagParseFully( |
23 | - ( new TemplateSlidePresenter( $this->templateName ) )->getTemplateText( $subject ) |
|
23 | + (new TemplateSlidePresenter($this->templateName))->getTemplateText($subject) |
|
24 | 24 | ); |
25 | 25 | } |
26 | 26 | |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | return MediaWikiServices::getInstance()->getParser(); |
29 | 29 | } |
30 | 30 | |
31 | - public function getTemplateText( Subject $subject ): string { |
|
32 | - return '{{' . implode( '|', $this->getTemplateSegments( $subject ) ) . '}}'; |
|
31 | + public function getTemplateText(Subject $subject): string { |
|
32 | + return '{{' . implode('|', $this->getTemplateSegments($subject)) . '}}'; |
|
33 | 33 | } |
34 | 34 | |
35 | - private function getTemplateSegments( Subject $subject ): array { |
|
35 | + private function getTemplateSegments(Subject $subject): array { |
|
36 | 36 | return array_merge( |
37 | 37 | [ |
38 | 38 | $this->templateName, |
39 | - $this->parameter( 'title', $subject->getWikiPage()->getTitle()->getFullText() ) |
|
39 | + $this->parameter('title', $subject->getWikiPage()->getTitle()->getFullText()) |
|
40 | 40 | ], |
41 | 41 | array_map( |
42 | - function( PropertyValueCollection $pvc ) { |
|
42 | + function(PropertyValueCollection $pvc) { |
|
43 | 43 | return $this->parameter( |
44 | - $pvc->getPrintRequest()->getText( null ) ?? '', |
|
45 | - $pvc->getDataItems() === [] ? '' : $this->dataItemToText( $pvc->getDataItems()[0] ) |
|
44 | + $pvc->getPrintRequest()->getText(null) ?? '', |
|
45 | + $pvc->getDataItems() === [] ? '' : $this->dataItemToText($pvc->getDataItems()[0]) |
|
46 | 46 | ); |
47 | 47 | }, |
48 | 48 | $subject->getPropertyValueCollections()->toArray() |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - private function dataItemToText( \SMWDataItem $dataItem ): string { |
|
54 | - return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
|
53 | + private function dataItemToText(\SMWDataItem $dataItem): string { |
|
54 | + return DataValueFactory::getInstance()->newDataValueByItem($dataItem)->getLongHTMLText(); |
|
55 | 55 | } |
56 | 56 | |
57 | - private function parameter( string $name, string $value ): string { |
|
57 | + private function parameter(string $name, string $value): string { |
|
58 | 58 | return $name . '=' . $value; |
59 | 59 | } |
60 | 60 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline\SlidePresenter; |
6 | 6 | |
@@ -16,37 +16,37 @@ discard block |
||
16 | 16 | ) { |
17 | 17 | } |
18 | 18 | |
19 | - public function getText( Subject $subject ): string { |
|
20 | - return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) ); |
|
19 | + public function getText(Subject $subject): string { |
|
20 | + return implode('<br>', iterator_to_array($this->getDisplayValues($subject))); |
|
21 | 21 | } |
22 | 22 | |
23 | - private function getDisplayValues( Subject $subject ): Traversable { |
|
24 | - foreach ( $subject->getPropertyValueCollections()->toArray() as $propertyValues ) { |
|
25 | - foreach ( $propertyValues->getDataItems() as $dataItem ) { |
|
26 | - if ( !$this->isHiddenPrintRequest( $propertyValues->getPrintRequest() ) ) { |
|
27 | - yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem ); |
|
23 | + private function getDisplayValues(Subject $subject): Traversable { |
|
24 | + foreach ($subject->getPropertyValueCollections()->toArray() as $propertyValues) { |
|
25 | + foreach ($propertyValues->getDataItems() as $dataItem) { |
|
26 | + if (!$this->isHiddenPrintRequest($propertyValues->getPrintRequest())) { |
|
27 | + yield $this->getDisplayValue($propertyValues->getPrintRequest(), $dataItem); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | - private function isHiddenPrintRequest( PrintRequest $pr ): bool { |
|
34 | - return $pr->getText( null ) === $this->parameters['image property']; |
|
33 | + private function isHiddenPrintRequest(PrintRequest $pr): bool { |
|
34 | + return $pr->getText(null) === $this->parameters['image property']; |
|
35 | 35 | } |
36 | 36 | |
37 | - private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ): string { |
|
38 | - $property = $pr->getText( null ); |
|
39 | - $value = $this->dataItemToText( $dataItem ); |
|
37 | + private function getDisplayValue(PrintRequest $pr, \SMWDataItem $dataItem): string { |
|
38 | + $property = $pr->getText(null); |
|
39 | + $value = $this->dataItemToText($dataItem); |
|
40 | 40 | |
41 | - if ( $property === '' ) { |
|
41 | + if ($property === '') { |
|
42 | 42 | return $value; |
43 | 43 | } |
44 | 44 | |
45 | 45 | return $property . ': ' . $value; |
46 | 46 | } |
47 | 47 | |
48 | - private function dataItemToText( \SMWDataItem $dataItem ): string { |
|
49 | - return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
|
48 | + private function dataItemToText(\SMWDataItem $dataItem): string { |
|
49 | + return DataValueFactory::getInstance()->newDataValueByItem($dataItem)->getLongHTMLText(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | private static function doSmwCheck(): void { |
16 | - if ( !defined( 'SMW_VERSION' ) ) { |
|
16 | + if (!defined('SMW_VERSION')) { |
|
17 | 17 | |
18 | - if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
19 | - die( "\nThe 'Modern Timeline' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); |
|
18 | + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
19 | + die("\nThe 'Modern Timeline' extension requires 'Semantic MediaWiki' to be installed and enabled.\n"); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | die( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ModernTimeline; |
6 | 6 | |
@@ -25,23 +25,23 @@ discard block |
||
25 | 25 | $registry = new ResultFormatRegistry(); |
26 | 26 | |
27 | 27 | $registry->newFormat() |
28 | - ->withName( 'moderntimeline' ) |
|
29 | - ->andMessageKey( 'modern-timeline-format-name' ) |
|
30 | - ->andParameterDefinitions( TimelineOptions::getTimelineParameterDefinitions() ) |
|
31 | - ->andPresenterBuilder( function() { |
|
28 | + ->withName('moderntimeline') |
|
29 | + ->andMessageKey('modern-timeline-format-name') |
|
30 | + ->andParameterDefinitions(TimelineOptions::getTimelineParameterDefinitions()) |
|
31 | + ->andPresenterBuilder(function() { |
|
32 | 32 | return new TimelinePresenter(); |
33 | 33 | } ) |
34 | 34 | ->register(); |
35 | 35 | |
36 | - $this->format = $registry->getFormatByName( 'moderntimeline' ); |
|
36 | + $this->format = $registry->getFormatByName('moderntimeline'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function getName(): string { |
40 | - return wfMessage( $this->format->getNameMessageKey() )->text(); |
|
40 | + return wfMessage($this->format->getNameMessageKey())->text(); |
|
41 | 41 | } |
42 | 42 | |
43 | - public function getParamDefinitions( array $definitions ) { |
|
44 | - return array_merge( $definitions, $this->format->getParameterDefinitions() ); |
|
43 | + public function getParamDefinitions(array $definitions) { |
|
44 | + return array_merge($definitions, $this->format->getParameterDefinitions()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -51,36 +51,36 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - public function getResult( QueryResult $result, array $parameters, $outputMode ): string { |
|
54 | + public function getResult(QueryResult $result, array $parameters, $outputMode): string { |
|
55 | 55 | return $this->format->buildPresenter()->presentResult( |
56 | 56 | new SimpleQueryResult( |
57 | - $this->simplifyResult( $result ), |
|
58 | - $this->newProcessingResultFromParams( $parameters ) |
|
57 | + $this->simplifyResult($result), |
|
58 | + $this->newProcessingResultFromParams($parameters) |
|
59 | 59 | ) |
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
63 | - private function simplifyResult( QueryResult $result ): SubjectCollection { |
|
64 | - return ( new ResultSimplifier() )->newSubjectCollection( $result ); |
|
63 | + private function simplifyResult(QueryResult $result): SubjectCollection { |
|
64 | + return (new ResultSimplifier())->newSubjectCollection($result); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * This is code copied over from ParamProcessor to go from the deprecated Param[] to ProcessingResult. |
69 | 69 | * Once the main ResultPrinter interface has been migrated away from Param this can be removed. |
70 | 70 | */ |
71 | - private function newProcessingResultFromParams( array $params ): ProcessingResult { |
|
71 | + private function newProcessingResultFromParams(array $params): ProcessingResult { |
|
72 | 72 | $parameters = []; |
73 | 73 | |
74 | - foreach ( $params as $param ) { |
|
74 | + foreach ($params as $param) { |
|
75 | 75 | $processedParam = new ProcessedParam( |
76 | 76 | $param->getName(), |
77 | 77 | $param->getValue(), |
78 | 78 | $param->wasSetToDefault() |
79 | 79 | ); |
80 | 80 | |
81 | - if ( !$param->wasSetToDefault() ) { |
|
82 | - $processedParam->setOriginalName( $param->getOriginalName() ); |
|
83 | - $processedParam->setOriginalValue( $param->getOriginalValue() ); |
|
81 | + if (!$param->wasSetToDefault()) { |
|
82 | + $processedParam->setOriginalName($param->getOriginalName()); |
|
83 | + $processedParam->setOriginalValue($param->getOriginalValue()); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $parameters[$processedParam->getName()] = $processedParam; |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | ); |
93 | 93 | } |
94 | 94 | |
95 | - public function getQueryMode( $context ): int { |
|
95 | + public function getQueryMode($context): int { |
|
96 | 96 | return SMWQuery::MODE_INSTANCES; |
97 | 97 | } |
98 | 98 | |
99 | - public function setShowErrors( $show ): void { |
|
99 | + public function setShowErrors($show): void { |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function isExportFormat(): bool { |
@@ -115,6 +115,6 @@ discard block |
||
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - public function setRecursiveTextProcessor( RecursiveTextProcessor $recursiveTextProcessor ): void { |
|
118 | + public function setRecursiveTextProcessor(RecursiveTextProcessor $recursiveTextProcessor): void { |
|
119 | 119 | } |
120 | 120 | } |