HtmlResponseParserRenderer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Test Coverage

Coverage 89.13%

Importance

Changes 0
Metric Value
wmc 7
eloc 46
c 0
b 0
f 0
dl 0
loc 121
ccs 41
cts 46
cp 0.8913
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A isReadOnly() 0 2 1
A getRawResponse() 0 7 2
A renderTextFor() 0 72 3
1
<?php
2
3
namespace SCI\Specials\CitableMetadata;
4
5
use Onoi\Remi\ResponseParser;
6
use Html;
0 ignored issues
show
Bug introduced by
The type Html 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...
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class HtmlResponseParserRenderer {
15
16
	/**
17
	 * @var ResponseParser
18
	 */
19
	private $responseParser;
20
21
	/**
22
	 * @var boolean
23
	 */
24
	private $isReadOnly = false;
25
26
	/**
27
	 * @since 1.0
28
	 *
29
	 * @param ResponseParser $responseParser
30
	 */
31 3
	public function __construct( ResponseParser $responseParser ) {
32 3
		$this->responseParser = $responseParser;
33 3
	}
34
35
	/**
36
	 * @since 1.4
37
	 *
38
	 * @param boolean $isReadOnly
39
	 */
40
	public function isReadOnly( $isReadOnly ) {
41
		$this->isReadOnly = (bool)$isReadOnly;
42
	}
43
44
	/**
45
	 * @since 1.0
46
	 *
47
	 * @return string
48
	 */
49 1
	public function getRawResponse( $id ) {
50
51 1
		if ( $id === '' ) {
52
			return '';
53
		}
54
55 1
		return $this->responseParser->getRawResponse( $id );
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * @return string
62
	 */
63 1
	public function renderTextFor( $id ) {
64
65 1
		$html = '';
66
67 1
		$this->responseParser->doFilterResponseFor( $id );
68
69 1
		$html .= Html::rawElement(
70 1
			'div',
71
			[
72 1
				'id' => 'scite-status',
73
			],
74 1
			''
75
		);
76
77 1
		if ( $this->responseParser->getMessages() !== [] ) {
78
			return '';
79
		}
80
81 1
		$create = '';
82
83
		// Only display the create button for when the DB can be actually
84
		// accessed
85 1
		if ( $this->isReadOnly === false ) {
86 1
			$create = Html::element(
87 1
				'a',
88
				[
89 1
					'href' => '#',
90 1
					'class' => 'scite-create scite-action-button',
91 1
					'data-content-selector' => '#scite-record-content',
92 1
					'data-title' => $this->responseParser->getFilteredRecord()->getTitleForPageCreation()
0 ignored issues
show
introduced by
The method getTitleForPageCreation() does not exist on Onoi\Remi\FilteredRecord. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

92
					'data-title' => $this->responseParser->getFilteredRecord()->/** @scrutinizer ignore-call */ getTitleForPageCreation()
Loading history...
93
				],
94 1
				wfMessage( 'sci-metadata-search-action-create' )->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

94
				/** @scrutinizer ignore-call */ 
95
    wfMessage( 'sci-metadata-search-action-create' )->text()
Loading history...
95
			);
96
		}
97
98 1
		$html .= Html::rawElement(
99 1
			'div',
100
			[
101 1
				'class' => 'scite-metadata-search-action'
102
			],
103 1
			Html::element(
104 1
				'a',
105
				[
106 1
					'href' => '#',
107
					'class' => 'scite-highlight scite-action-button',
108
					'data-content-selector' => '#scite-record-content'
109
				],
110 1
				wfMessage( 'sci-metadata-search-action-highlight' )->text()
111 1
			) . '&nbsp;' . $create
112
		);
113
114
		// To display the #scite on the generated page
115 1
		$this->responseParser->getFilteredRecord()->set( '@show', 'true' );
116
117 1
		$html .= Html::rawElement(
118 1
			'div',
119
			[
120 1
				'id' => 'scite-record-content',
121
				'class' => 'scite-pre'
122
			],
123 1
			$this->responseParser->getFilteredRecord()->asSciteTransclusion()
0 ignored issues
show
introduced by
The method asSciteTransclusion() does not exist on Onoi\Remi\FilteredRecord. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

123
			$this->responseParser->getFilteredRecord()->/** @scrutinizer ignore-call */ asSciteTransclusion()
Loading history...
124
		);
125
126 1
		$html .= Html::rawElement(
127 1
			'div',
128
			[
129 1
				'class' => 'visualClear'
130
			],
131 1
			''
132
		);
133
134 1
		return $html;
135
	}
136
137
}
138