@@ 139-179 (lines=41) @@ | ||
136 | $result instanceof NullResult; |
|
137 | } |
|
138 | ||
139 | public function checkResultToArray( CheckResult $checkResult ) { |
|
140 | if ( $checkResult instanceof NullResult ) { |
|
141 | return null; |
|
142 | } |
|
143 | ||
144 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
|
145 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
|
146 | $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
147 | ||
148 | $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
149 | $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
150 | // TODO link to the statement when possible (T169224) |
|
151 | $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
152 | ||
153 | $constraint = [ |
|
154 | 'id' => $constraintId, |
|
155 | 'type' => $typeItemId, |
|
156 | 'typeLabel' => $typeLabel, |
|
157 | 'link' => $link, |
|
158 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
|
159 | ]; |
|
160 | ||
161 | $result = [ |
|
162 | 'status' => $checkResult->getStatus(), |
|
163 | 'property' => $constraintPropertyId->getSerialization(), |
|
164 | 'constraint' => $constraint |
|
165 | ]; |
|
166 | $message = $checkResult->getMessage(); |
|
167 | if ( $message ) { |
|
168 | $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
169 | } |
|
170 | if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
171 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
|
172 | } |
|
173 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
|
174 | if ( $cachingMetadataArray !== null ) { |
|
175 | $result['cached'] = $cachingMetadataArray; |
|
176 | } |
|
177 | ||
178 | return $result; |
|
179 | } |
|
180 | ||
181 | } |
|
182 |
@@ 74-114 (lines=41) @@ | ||
71 | ); |
|
72 | } |
|
73 | ||
74 | public function checkResultToArray( CheckResult $checkResult ) { |
|
75 | if ( $checkResult instanceof NullResult ) { |
|
76 | return null; |
|
77 | } |
|
78 | ||
79 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
|
80 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
|
81 | $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
82 | ||
83 | $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
84 | $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
85 | // TODO link to the statement when possible (T169224) |
|
86 | $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
87 | ||
88 | $constraint = [ |
|
89 | 'id' => $constraintId, |
|
90 | 'type' => $typeItemId, |
|
91 | 'typeLabel' => $typeLabel, |
|
92 | 'link' => $link, |
|
93 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
|
94 | ]; |
|
95 | ||
96 | $result = [ |
|
97 | 'status' => $checkResult->getStatus(), |
|
98 | 'property' => $constraintPropertyId->getSerialization(), |
|
99 | 'constraint' => $constraint |
|
100 | ]; |
|
101 | $message = $checkResult->getMessage(); |
|
102 | if ( $message ) { |
|
103 | $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
104 | } |
|
105 | if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
106 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
|
107 | } |
|
108 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
|
109 | if ( $cachingMetadataArray !== null ) { |
|
110 | $result['cached'] = $cachingMetadataArray; |
|
111 | } |
|
112 | ||
113 | return $result; |
|
114 | } |
|
115 | ||
116 | } |
|
117 |