These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SMW\Exporter; |
||
4 | |||
5 | use SMW\ApplicationFactory; |
||
6 | use SMW\DataValueFactory; |
||
7 | use SMW\DIConcept; |
||
8 | use SMW\DIProperty; |
||
9 | use SMW\Exporter\Element\ExpResource; |
||
10 | use SMW\Query\Language\ClassDescription; |
||
11 | use SMW\Query\Language\ConceptDescription; |
||
12 | use SMW\Query\Language\Conjunction; |
||
13 | use SMW\Query\Language\Description; |
||
14 | use SMW\Query\Language\Disjunction; |
||
15 | use SMW\Query\Language\SomeProperty; |
||
16 | use SMW\Query\Language\ThingDescription; |
||
17 | use SMW\Query\Language\ValueDescription; |
||
18 | use SMWDataItem as DataItem; |
||
19 | use SMWExpData as ExpData; |
||
20 | use SMWExporter as Exporter; |
||
21 | |||
22 | /** |
||
23 | * @license GNU GPL v2+ |
||
24 | * @since 2.4 |
||
25 | * |
||
26 | * @author Markus Krötzsch |
||
27 | * @author mwjames |
||
28 | */ |
||
29 | class ConceptToExpDataMapper { |
||
30 | |||
31 | /** |
||
32 | * @var Exporter |
||
33 | */ |
||
34 | private $exporter; |
||
35 | |||
36 | /** |
||
37 | * @since 2.4 |
||
38 | * |
||
39 | * @param Exporter|null $exporter |
||
40 | */ |
||
41 | 14 | public function __construct( Exporter $exporter = null ) { |
|
42 | 14 | $this->exporter = $exporter; |
|
43 | |||
44 | 14 | if ( $this->exporter === null ) { |
|
45 | 14 | $this->exporter = Exporter::getInstance(); |
|
46 | } |
||
47 | 14 | } |
|
48 | |||
49 | /** |
||
50 | * @since 2.4 |
||
51 | * |
||
52 | * @param DataItem $dataItem |
||
53 | * |
||
54 | * @return boolean |
||
55 | */ |
||
56 | 10 | public function isMapperFor( DataItem $dataItem ) { |
|
57 | 10 | return $dataItem instanceOf DIConcept; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @since 2.4 |
||
62 | * |
||
63 | * @param DIConcept $concept |
||
64 | * |
||
65 | * @return ExpData|null |
||
66 | */ |
||
67 | public function getElementFor( DIConcept $concept ) { |
||
68 | |||
69 | $dataValue = DataValueFactory::getInstance()->newDataItemValue( |
||
70 | $concept |
||
71 | ); |
||
72 | |||
73 | if ( !$dataValue->isValid() ) { |
||
74 | return null; |
||
75 | } |
||
76 | |||
77 | $description = ApplicationFactory::getInstance()->newQueryParser()->getQueryDescription( |
||
78 | $dataValue->getWikiValue() |
||
79 | ); |
||
80 | |||
81 | $exact = true; |
||
82 | $owldesc = $this->getExpDataFromDescription( $description, $exact ); |
||
83 | |||
84 | if ( $owldesc === false ) { |
||
85 | $result = new ExpData( |
||
86 | $this->exporter->getSpecialNsResource( 'owl','Thing' ) |
||
0 ignored issues
–
show
|
|||
87 | ); |
||
88 | |||
89 | return $result; |
||
90 | } |
||
91 | |||
92 | if ( !$exact ) { |
||
93 | $result = new ExpData( |
||
94 | new ExpResource( '' ) |
||
0 ignored issues
–
show
new \SMW\Exporter\Element\ExpResource('') is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
95 | ); |
||
96 | |||
97 | $result->addPropertyObjectValue( |
||
98 | $this->exporter->getSpecialNsResource( 'rdf', 'type' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...Resource('rdf', 'type') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
99 | new ExpData( $this->exporter->getSpecialNsResource( 'owl', 'Class' ) ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Class') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
100 | ); |
||
101 | |||
102 | $result->addPropertyObjectValue( |
||
103 | $this->exporter->getSpecialNsResource( 'rdfs', 'subClassOf' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...e('rdfs', 'subClassOf') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
104 | $owldesc |
||
0 ignored issues
–
show
It seems like
$owldesc defined by $this->getExpDataFromDes...n($description, $exact) on line 82 can be null ; however, SMWExpData::addPropertyObjectValue() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
|
|||
105 | ); |
||
106 | |||
107 | return $result; |
||
108 | } else { |
||
109 | return $owldesc; |
||
110 | } |
||
111 | |||
112 | return null; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @since 2.4 |
||
117 | * |
||
118 | * @param Description $description |
||
119 | * |
||
120 | * @param string &$exact |
||
121 | * |
||
122 | * @return Element|false |
||
123 | */ |
||
124 | 3 | public function getExpDataFromDescription( Description $description, &$exact ) { |
|
125 | |||
126 | 3 | if ( ( $description instanceof Conjunction ) || ( $description instanceof Disjunction ) ) { |
|
127 | $result = $this->doMapConjunctionDisjunction( $description, $exact ); |
||
128 | } elseif ( $description instanceof ClassDescription ) { |
||
129 | 2 | $result = $this->doMapClassDescription( $description, $exact ); |
|
130 | } elseif ( $description instanceof ConceptDescription ) { |
||
131 | $result = $this->doMapConceptDescription( $description, $exact ); |
||
132 | } elseif ( $description instanceof SomeProperty ) { |
||
133 | $result = $this->doMapSomeProperty( $description, $exact ); |
||
134 | } elseif ( $description instanceof ValueDescription ) { |
||
135 | $result = $this->doMapValueDescription( $description, $exact ); |
||
136 | } elseif ( $description instanceof ThingDescription ) { |
||
137 | 1 | $result = false; |
|
138 | } else { |
||
139 | $result = false; |
||
140 | $exact = false; |
||
141 | } |
||
142 | |||
143 | 3 | return $result; |
|
144 | } |
||
145 | |||
146 | private function doMapValueDescription( ValueDescription $description, &$exact ) { |
||
147 | |||
148 | if ( $description->getComparator() === SMW_CMP_EQ ) { |
||
149 | $result = $this->exporter->getDataItemExpElement( $description->getDataItem() ); |
||
150 | } else { |
||
151 | // OWL cannot represent <= and >= ... |
||
152 | $exact = false; |
||
153 | $result = false; |
||
154 | } |
||
155 | |||
156 | return $result; |
||
157 | } |
||
158 | |||
159 | private function doMapConceptDescription( ConceptDescription $description, &$exact ) { |
||
0 ignored issues
–
show
|
|||
160 | |||
161 | $result = new ExpData( |
||
162 | $this->exporter->getResourceElementForWikiPage( $description->getConcept() ) |
||
0 ignored issues
–
show
$description->getConcept() of type object<SMW\DIWikiPage> is not a sub-type of object<SMWDIWikiPage> . It seems like you assume a child class of the class SMW\DIWikiPage to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.
Loading history...
$this->exporter->getReso...cription->getConcept()) is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
163 | ); |
||
164 | |||
165 | return $result; |
||
166 | } |
||
167 | |||
168 | private function doMapSomeProperty( SomeProperty $description, &$exact ) { |
||
169 | |||
170 | $result = new ExpData( |
||
171 | new ExpResource( '' ) |
||
0 ignored issues
–
show
new \SMW\Exporter\Element\ExpResource('') is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
172 | ); |
||
173 | |||
174 | $result->addPropertyObjectValue( |
||
175 | $this->exporter->getSpecialNsResource( 'rdf', 'type' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...Resource('rdf', 'type') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
176 | new ExpData( $this->exporter->getSpecialNsResource( 'owl', 'Restriction' ) ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...e('owl', 'Restriction') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
177 | ); |
||
178 | |||
179 | $property = $description->getProperty(); |
||
180 | |||
181 | if ( $property->isInverse() ) { |
||
182 | $property = new DIProperty( $property->getKey() ); |
||
183 | } |
||
184 | |||
185 | $result->addPropertyObjectValue( |
||
186 | $this->exporter->getSpecialNsResource( 'owl', 'onProperty' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...ce('owl', 'onProperty') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
187 | new ExpData( |
||
188 | $this->exporter->getResourceElementForProperty( $property ) |
||
0 ignored issues
–
show
$property of type object<SMW\DIProperty> is not a sub-type of object<SMWDIProperty> . It seems like you assume a child class of the class SMW\DIProperty to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.
Loading history...
$this->exporter->getReso...tForProperty($property) is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
189 | ) |
||
190 | ); |
||
191 | |||
192 | $subdata = $this->getExpDataFromDescription( |
||
193 | $description->getDescription(), |
||
194 | $exact |
||
195 | ); |
||
196 | |||
197 | if ( ( $description->getDescription() instanceof ValueDescription ) && |
||
198 | ( $description->getDescription()->getComparator() === SMW_CMP_EQ ) ) { |
||
199 | $result->addPropertyObjectValue( |
||
200 | $this->exporter->getSpecialNsResource( 'owl', 'hasValue' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...urce('owl', 'hasValue') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
201 | $subdata |
||
0 ignored issues
–
show
It seems like
$subdata defined by $this->getExpDataFromDes...tDescription(), $exact) on line 192 can also be of type false or null ; however, SMWExpData::addPropertyObjectValue() does only seem to accept object<SMW\Exporter\Element> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
202 | ); |
||
203 | } else { |
||
204 | if ( $subdata === false ) { |
||
205 | |||
206 | $owltype = $this->exporter->getOWLPropertyType( |
||
207 | $description->getProperty()->findPropertyTypeID() |
||
208 | ); |
||
209 | |||
210 | if ( $owltype == 'ObjectProperty' ) { |
||
211 | $subdata = new ExpData( |
||
212 | $this->exporter->getSpecialNsResource( 'owl', 'Thing' ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Thing') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
213 | ); |
||
214 | } elseif ( $owltype == 'DatatypeProperty' ) { |
||
215 | $subdata = new ExpData( |
||
216 | $this->exporter->getSpecialNsResource( 'rdfs', 'Literal' ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...urce('rdfs', 'Literal') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
217 | ); |
||
218 | } else { // no restrictions at all with annotation properties ... |
||
219 | return new ExpData( |
||
220 | $this->exporter->getSpecialNsResource( 'owl', 'Thing' ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Thing') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
221 | ); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | $result->addPropertyObjectValue( |
||
226 | $this->exporter->getSpecialNsResource( 'owl', 'someValuesFrom' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...owl', 'someValuesFrom') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
227 | $subdata |
||
0 ignored issues
–
show
It seems like
$subdata defined by $this->getExpDataFromDes...tDescription(), $exact) on line 192 can be null ; however, SMWExpData::addPropertyObjectValue() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
|
|||
228 | ); |
||
229 | } |
||
230 | |||
231 | return $result; |
||
232 | } |
||
233 | |||
234 | 2 | private function doMapClassDescription( ClassDescription $description, &$exact ) { |
|
0 ignored issues
–
show
|
|||
235 | |||
236 | 2 | if ( count( $description->getCategories() ) == 1 ) { // single category |
|
237 | 1 | $categories = $description->getCategories(); |
|
238 | 1 | $result = new ExpData( |
|
239 | 1 | $this->exporter->getResourceElementForWikiPage( end( $categories ) ) |
|
0 ignored issues
–
show
$this->exporter->getReso...iPage(end($categories)) is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
240 | ); |
||
241 | } else { // disjunction of categories |
||
242 | |||
243 | 1 | $result = new ExpData( |
|
244 | 1 | new ExpResource( '' ) |
|
0 ignored issues
–
show
new \SMW\Exporter\Element\ExpResource('') is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
245 | ); |
||
246 | |||
247 | 1 | $elements = array(); |
|
248 | |||
249 | 1 | foreach ( $description->getCategories() as $cat ) { |
|
250 | 1 | $elements[] = new ExpData( |
|
251 | 1 | $this->exporter->getResourceElementForWikiPage( $cat ) |
|
0 ignored issues
–
show
$this->exporter->getReso...lementForWikiPage($cat) is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
252 | ); |
||
253 | } |
||
254 | |||
255 | 1 | $result->addPropertyObjectValue( |
|
256 | 1 | $this->exporter->getSpecialNsResource( 'owl', 'unionOf' ), |
|
0 ignored issues
–
show
$this->exporter->getSpec...ource('owl', 'unionOf') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
257 | 1 | ExpData::makeCollection( $elements ) |
|
258 | ); |
||
259 | } |
||
260 | |||
261 | 2 | $result->addPropertyObjectValue( |
|
262 | 2 | $this->exporter->getSpecialNsResource( 'rdf', 'type' ), |
|
0 ignored issues
–
show
$this->exporter->getSpec...Resource('rdf', 'type') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
263 | 2 | new ExpData( |
|
264 | 2 | $this->exporter->getSpecialNsResource( 'owl', 'Class' ) |
|
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Class') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
265 | ) |
||
266 | ); |
||
267 | |||
268 | 2 | return $result; |
|
269 | } |
||
270 | |||
271 | private function doMapConjunctionDisjunction( Description $description, &$exact ) { |
||
272 | |||
273 | $result = new ExpData( |
||
274 | new ExpResource( '' ) |
||
0 ignored issues
–
show
new \SMW\Exporter\Element\ExpResource('') is of type object<SMW\Exporter\Element\ExpResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
275 | ); |
||
276 | |||
277 | $result->addPropertyObjectValue( |
||
278 | $this->exporter->getSpecialNsResource( 'rdf', 'type' ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...Resource('rdf', 'type') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
279 | new ExpData( |
||
280 | $this->exporter->getSpecialNsResource( 'owl', 'Class' ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Class') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
281 | ) |
||
282 | ); |
||
283 | |||
284 | $elements = array(); |
||
285 | |||
286 | foreach ( $description->getDescriptions() as $subdesc ) { |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
SMW\Query\Language\Description as the method getDescriptions() does only exist in the following sub-classes of SMW\Query\Language\Description : SMW\Query\Language\Conjunction , SMW\Query\Language\Disjunction . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
287 | $element = $this->getExpDataFromDescription( $subdesc, $exact ); |
||
288 | |||
289 | if ( $element === false ) { |
||
290 | $element = new ExpData( |
||
291 | $this->exporter->getSpecialNsResource( 'owl', 'Thing' ) |
||
0 ignored issues
–
show
$this->exporter->getSpec...esource('owl', 'Thing') is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
292 | ); |
||
293 | } |
||
294 | |||
295 | $elements[] = $element; |
||
296 | } |
||
297 | |||
298 | $prop = $description instanceof Conjunction ? 'intersectionOf' : 'unionOf'; |
||
299 | |||
300 | $result->addPropertyObjectValue( |
||
301 | $this->exporter->getSpecialNsResource( 'owl', $prop ), |
||
0 ignored issues
–
show
$this->exporter->getSpec...sResource('owl', $prop) is of type object<SMW\Exporter\Element\ExpNsResource> , but the function expects a object<SMWExpNsResource> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
302 | ExpData::makeCollection( $elements ) |
||
303 | ); |
||
304 | |||
305 | return $result; |
||
306 | } |
||
307 | |||
308 | } |
||
309 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: