TemplateSlidePresenter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline\SlidePresenter;
6
7
use MediaWiki\MediaWikiServices;
0 ignored issues
show
Bug introduced by
The type MediaWiki\MediaWikiServices 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...
8
use ModernTimeline\ResultFacade\PropertyValueCollection;
9
use ModernTimeline\ResultFacade\Subject;
10
use SMW\DataValueFactory;
0 ignored issues
show
Bug introduced by
The type SMW\DataValueFactory 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...
11
12
class TemplateSlidePresenter implements SlidePresenter {
13
14
	public function __construct(
15
		private string $templateName
16 2
	) {
17 2
	}
18 2
19
	public function getText( Subject $subject ): string {
20 1
		$parser = $this->getParser();
21 1
22
		return $parser->recursiveTagParseFully(
23 1
			( new TemplateSlidePresenter( $this->templateName ) )->getTemplateText( $subject )
24 1
		);
25
	}
26
27
	private function getParser(): \Parser {
0 ignored issues
show
Bug introduced by
The type Parser 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...
28 1
		return MediaWikiServices::getInstance()->getParser();
29 1
	}
30
31
	public function getTemplateText( Subject $subject ): string {
32 2
		return '{{' . implode( '|', $this->getTemplateSegments( $subject ) ) . '}}';
33 2
	}
34
35
	private function getTemplateSegments( Subject $subject ): array {
36 2
		return array_merge(
37 2
			[
38
				$this->templateName,
39 2
				$this->parameter( 'title', $subject->getWikiPage()->getTitle()->getFullText() )
40 2
			],
41
			array_map(
42 2
				function( PropertyValueCollection $pvc ) {
43 2
					return $this->parameter(
44 2
						$pvc->getPrintRequest()->getText( null ) ?? '',
45 2
						$pvc->getDataItems() === [] ? '' : $this->dataItemToText( $pvc->getDataItems()[0] )
46 2
					);
47
				},
48 2
				$subject->getPropertyValueCollections()->toArray()
49 2
			)
50
		);
51
	}
52
53
	private function dataItemToText( \SMWDataItem $dataItem ): string {
0 ignored issues
show
Bug introduced by
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. 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...
54 2
		return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText();
55 2
	}
56
57
	private function parameter( string $name, string $value ): string {
58 2
		return $name . '=' . $value;
59 2
	}
60
}
61