ModernTimelinePrinter   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 87.76%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 35
c 5
b 0
f 0
dl 0
loc 99
ccs 43
cts 49
cp 0.8776
rs 10
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setShowErrors() 0 1 1
A newProcessingResultFromParams() 0 21 3
A isDeferrable() 0 2 1
A getParamDefinitions() 0 2 1
A getName() 0 2 1
A __construct() 0 13 1
A getQueryMode() 0 2 1
A getResult() 0 5 1
A getDefaultSort() 0 2 1
A supportsRecursiveAnnotation() 0 2 1
A setRecursiveTextProcessor() 0 1 1
A simplifyResult() 0 2 1
A isExportFormat() 0 2 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline;
6
7
use ModernTimeline\ResultFacade\ResultFormat;
8
use ModernTimeline\ResultFacade\ResultSimplifier;
9
use ModernTimeline\ResultFacade\ResultFormatRegistry;
10
use ModernTimeline\ResultFacade\SimpleQueryResult;
11
use ModernTimeline\ResultFacade\SubjectCollection;
12
use ParamProcessor\Param;
13
use ParamProcessor\ProcessedParam;
14
use ParamProcessor\ProcessingResult;
15
use SMW\Parser\RecursiveTextProcessor;
0 ignored issues
show
Bug introduced by
The type SMW\Parser\RecursiveTextProcessor 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...
16
use SMW\Query\QueryResult;
0 ignored issues
show
Bug introduced by
The type SMW\Query\QueryResult 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...
17
use SMW\Query\ResultPrinter;
0 ignored issues
show
Bug introduced by
The type SMW\Query\ResultPrinter 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...
18
use SMWQuery;
0 ignored issues
show
Bug introduced by
The type SMWQuery 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...
19
20
class ModernTimelinePrinter implements ResultPrinter {
21
22
	private ResultFormat $format;
23
24
	public function __construct() {
25
		$registry = new ResultFormatRegistry();
26
27 5
		$registry->newFormat()
28 5
			->withName( 'moderntimeline' )
29
			->andMessageKey( 'modern-timeline-format-name' )
30 5
			->andParameterDefinitions( TimelineOptions::getTimelineParameterDefinitions() )
31 5
			->andPresenterBuilder( function() {
32 5
				return new TimelinePresenter();
33 5
			} )
34 5
			->register();
35 4
36 5
		$this->format = $registry->getFormatByName( 'moderntimeline' );
37 5
	}
38
39 5
	public function getName(): string {
40 5
		return wfMessage( $this->format->getNameMessageKey() )->text();
0 ignored issues
show
Bug introduced by
The function wfMessage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

40
		return /** @scrutinizer ignore-call */ wfMessage( $this->format->getNameMessageKey() )->text();
Loading history...
41
	}
42
43
	public function getParamDefinitions( array $definitions ) {
44
		return array_merge( $definitions, $this->format->getParameterDefinitions() );
45
	}
46 5
47 5
	/**
48
	 * @param QueryResult $result
49
	 * @param Param[] $parameters
50
	 * @param int $outputMode
51
	 *
52
	 * @return string
53
	 */
54
	public function getResult( QueryResult $result, array $parameters, $outputMode ): string {
55
		return $this->format->buildPresenter()->presentResult(
56
			new SimpleQueryResult(
57 4
				$this->simplifyResult( $result ),
58 4
				$this->newProcessingResultFromParams( $parameters )
59 4
			)
60 4
		);
61 4
	}
62
63
	private function simplifyResult( QueryResult $result ): SubjectCollection {
64
		return ( new ResultSimplifier() )->newSubjectCollection( $result );
65
	}
66 4
67 4
	/**
68
	 * This is code copied over from ParamProcessor to go from the deprecated Param[] to ProcessingResult.
69
	 * Once the main ResultPrinter interface has been migrated away from Param this can be removed.
70
	 */
71
	private function newProcessingResultFromParams( array $params ): ProcessingResult {
72
		$parameters = [];
73
74 4
		foreach ( $params as $param ) {
75 4
			$processedParam = new ProcessedParam(
76
				$param->getName(),
77 4
				$param->getValue(),
78 4
				$param->wasSetToDefault()
79 4
			);
80 4
81 4
			if ( !$param->wasSetToDefault() ) {
82
				$processedParam->setOriginalName( $param->getOriginalName() );
83
				$processedParam->setOriginalValue( $param->getOriginalValue() );
84 4
			}
85 4
86 4
			$parameters[$processedParam->getName()] = $processedParam;
87
		}
88
89 4
		return new ProcessingResult(
90
			$parameters,
91
			[]
92 4
		);
93 4
	}
94 4
95
	public function getQueryMode( $context ): int {
96
		return SMWQuery::MODE_INSTANCES;
97
	}
98 4
99 4
	public function setShowErrors( $show ): void {
100
	}
101
102
	public function isExportFormat(): bool {
103
		return false;
104
	}
105
106
	public function getDefaultSort(): string {
107
		return 'ASC';
108
	}
109 4
110 4
	public function isDeferrable(): bool {
111
		return false;
112
	}
113 4
114 4
	public function supportsRecursiveAnnotation(): bool {
115
		return false;
116
	}
117 1
118 1
	public function setRecursiveTextProcessor( RecursiveTextProcessor $recursiveTextProcessor ): void {
119
	}
120
}
121