These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use SMW\ApplicationFactory; |
||
4 | use SMW\DataTypeRegistry; |
||
5 | use SMW\DataValueFactory; |
||
6 | use SMW\DIProperty; |
||
7 | use SMW\Exporter\DataItemByExpElementMatchFinder; |
||
8 | use SMW\Exporter\DataItemToElementEncoder; |
||
9 | use SMW\Exporter\DataItemToExpResourceEncoder; |
||
10 | use SMW\Exporter\Element\ExpNsResource; |
||
11 | use SMW\Exporter\Escaper; |
||
12 | |||
13 | /** |
||
14 | * SMWExporter is a class for converting internal page-based data (SMWSemanticData) into |
||
15 | * a format for easy serialisation in OWL or RDF. |
||
16 | * |
||
17 | * @author Markus Krötzsch |
||
18 | * @ingroup SMW |
||
19 | */ |
||
20 | class SMWExporter { |
||
0 ignored issues
–
show
|
|||
21 | |||
22 | /** |
||
23 | * @var SMWExporter |
||
24 | */ |
||
25 | private static $instance = null; |
||
26 | |||
27 | /** |
||
28 | * @var DataItemToExpResourceEncoder |
||
29 | */ |
||
30 | private static $dataItemToExpResourceEncoder = null; |
||
31 | |||
32 | /** |
||
33 | * @var DataItemToElementEncoder |
||
34 | */ |
||
35 | private static $dataItemToElementEncoder = null; |
||
36 | |||
37 | /** |
||
38 | * @var DataItemByExpElementMatchFinder |
||
39 | */ |
||
40 | private static $dataItemByExpElementMatchFinder = null; |
||
41 | |||
42 | static protected $m_exporturl = false; |
||
43 | static protected $m_ent_wiki = false; |
||
44 | static protected $m_ent_property = false; |
||
45 | static protected $m_ent_category = false; |
||
46 | static protected $m_ent_wikiurl = false; |
||
47 | |||
48 | /** |
||
49 | * @since 2.0 |
||
50 | * |
||
51 | * @return SMWExporter |
||
52 | */ |
||
53 | 248 | public static function getInstance() { |
|
54 | |||
55 | 248 | if ( self::$instance === null ) { |
|
56 | |||
57 | 226 | self::$instance = new self(); |
|
58 | 226 | self::$instance->initBaseURIs(); |
|
59 | |||
60 | 226 | $applicationFactory = ApplicationFactory::getInstance(); |
|
61 | |||
62 | // FIXME with 3.x |
||
63 | // There is no better way of getting around the static use without BC |
||
64 | 226 | self::$dataItemToElementEncoder = new DataItemToElementEncoder(); |
|
65 | |||
66 | 226 | self::$dataItemToExpResourceEncoder = new DataItemToExpResourceEncoder( |
|
67 | 226 | $applicationFactory->getStore() |
|
68 | ); |
||
69 | |||
70 | 226 | self::$dataItemToExpResourceEncoder->reset(); |
|
71 | |||
72 | 226 | self::$dataItemToExpResourceEncoder->setBCAuxiliaryUse( |
|
73 | 226 | $applicationFactory->getSettings()->get( 'smwgExportBCAuxiliaryUse' ) |
|
74 | ); |
||
75 | |||
76 | 226 | self::$dataItemByExpElementMatchFinder = new DataItemByExpElementMatchFinder( |
|
77 | 226 | $applicationFactory->getStore(), |
|
78 | 226 | self::$m_ent_wiki |
|
0 ignored issues
–
show
self::$m_ent_wiki is of type boolean , but the function expects a string .
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...
|
|||
79 | ); |
||
80 | } |
||
81 | |||
82 | 248 | return self::$instance; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @since 2.0 |
||
87 | */ |
||
88 | 227 | public static function clear() { |
|
89 | 227 | self::$instance = null; |
|
90 | 227 | self::$m_exporturl = false; |
|
91 | 227 | } |
|
92 | |||
93 | /** |
||
94 | * @since 2.2 |
||
95 | */ |
||
96 | 110 | public function resetCacheFor( SMWDIWikiPage $diWikiPage ) { |
|
97 | 110 | self::$dataItemToExpResourceEncoder->resetCacheFor( $diWikiPage ); |
|
98 | 110 | } |
|
99 | |||
100 | /** |
||
101 | * Make sure that necessary base URIs are initialised properly. |
||
102 | */ |
||
103 | 243 | static public function initBaseURIs() { |
|
0 ignored issues
–
show
initBaseURIs uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
104 | 243 | if ( self::$m_exporturl !== false ) { |
|
105 | 29 | return; |
|
106 | } |
||
107 | 226 | global $wgContLang, $wgServer, $wgArticlePath; |
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
108 | |||
109 | 226 | global $smwgNamespace; // complete namespace for URIs (with protocol, usually http://) |
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
110 | |||
111 | 226 | if ( '' == $smwgNamespace ) { |
|
112 | $resolver = SpecialPage::getTitleFor( 'URIResolver' ); |
||
113 | $smwgNamespace = $resolver->getFullURL() . '/'; |
||
114 | 226 | } elseif ( $smwgNamespace[0] == '.' ) { |
|
115 | $resolver = SpecialPage::getTitleFor( 'URIResolver' ); |
||
116 | $smwgNamespace = "http://" . substr( $smwgNamespace, 1 ) . $resolver->getLocalURL() . '/'; |
||
117 | } |
||
118 | |||
119 | // The article name must be the last part of wiki URLs for proper OWL/RDF export: |
||
120 | 226 | self::$m_ent_wikiurl = $wgServer . str_replace( '$1', '', $wgArticlePath ); |
|
0 ignored issues
–
show
The property
$m_ent_wikiurl was declared of type boolean , but $wgServer . str_replace('$1', '', $wgArticlePath) is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
121 | 226 | self::$m_ent_wiki = $smwgNamespace; |
|
0 ignored issues
–
show
The property
$m_ent_wiki was declared of type boolean , but $smwgNamespace is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
122 | |||
123 | 226 | $property = $GLOBALS['smwgExportBCNonCanonicalFormUse'] ? urlencode( str_replace( ' ', '_', $wgContLang->getNsText( SMW_NS_PROPERTY ) ) ) : 'Property'; |
|
124 | 226 | $category = $GLOBALS['smwgExportBCNonCanonicalFormUse'] ? urlencode( str_replace( ' ', '_', $wgContLang->getNsText( NS_CATEGORY ) ) ) : 'Category'; |
|
125 | |||
126 | 226 | self::$m_ent_property = self::$m_ent_wiki . Escaper::encodeUri( $property . ':' ); |
|
0 ignored issues
–
show
The property
$m_ent_property was declared of type boolean , but self::$m_ent_wiki . \SMW...odeUri($property . ':') is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
127 | 226 | self::$m_ent_category = self::$m_ent_wiki . Escaper::encodeUri( $category . ':' ); |
|
0 ignored issues
–
show
The property
$m_ent_category was declared of type boolean , but self::$m_ent_wiki . \SMW...odeUri($category . ':') is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
128 | |||
129 | 226 | $title = SpecialPage::getTitleFor( 'ExportRDF' ); |
|
130 | 226 | self::$m_exporturl = self::$m_ent_wikiurl . $title->getPrefixedURL(); |
|
0 ignored issues
–
show
The property
$m_exporturl was declared of type boolean , but self::$m_ent_wikiurl . $title->getPrefixedURL() is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
131 | 226 | } |
|
132 | |||
133 | /** |
||
134 | * Create exportable data from a given semantic data record. |
||
135 | * |
||
136 | * @param $semdata SMWSemanticData |
||
137 | * @return SMWExpData |
||
138 | */ |
||
139 | 16 | static public function makeExportData( SMWSemanticData $semdata ) { |
|
140 | 16 | self::initBaseURIs(); |
|
141 | |||
142 | 16 | $subject = $semdata->getSubject(); |
|
143 | |||
144 | // #649 Alwways make sure to have a least one valid sortkey |
||
145 | 16 | if ( !$semdata->getPropertyValues( new DIProperty( '_SKEY' ) ) && $subject->getSortKey() !== '' ) { |
|
146 | 11 | $semdata->addPropertyObjectValue( |
|
147 | 11 | new DIProperty( '_SKEY' ), |
|
148 | 11 | new SMWDIBlob( $subject->getSortKey() ) |
|
149 | ); |
||
150 | } |
||
151 | |||
152 | 16 | $result = self::makeExportDataForSubject( $subject ); |
|
0 ignored issues
–
show
$subject 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...
|
|||
153 | |||
154 | 16 | foreach ( $semdata->getProperties() as $property ) { |
|
155 | 16 | self::addPropertyValues( $property, $semdata->getPropertyValues( $property ), $result, $subject ); |
|
0 ignored issues
–
show
The call to
SMWExporter::addPropertyValues() has too many arguments starting with $subject .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
156 | } |
||
157 | |||
158 | 16 | return $result; |
|
159 | } |
||
160 | |||
161 | /** |
||
162 | * Make an SMWExpData object for the given page, and include the basic |
||
163 | * properties about this subject that are not directly represented by |
||
164 | * SMW property values. The optional parameter $typevalueforproperty |
||
165 | * can be used to pass a particular SMWTypesValue object that is used |
||
166 | * for determining the OWL type for property pages. |
||
167 | * |
||
168 | * @todo Take into account whether the wiki page belongs to a builtin property, and ensure URI alignment/type declaration in this case. |
||
169 | * |
||
170 | * @param $diWikiPage SMWDIWikiPage |
||
171 | * @param $addStubData boolean to indicate if additional data should be added to make a stub entry for this page |
||
172 | * @return SMWExpData |
||
173 | */ |
||
174 | 18 | static public function makeExportDataForSubject( SMWDIWikiPage $diWikiPage, $addStubData = false ) { |
|
175 | 18 | global $wgContLang; |
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
176 | |||
177 | 18 | $wikiPageExpElement = self::getDataItemExpElement( $diWikiPage ); |
|
178 | 18 | $result = new SMWExpData( $wikiPageExpElement ); |
|
0 ignored issues
–
show
$wikiPageExpElement is of type object<SMW\Exporter\Element>|null , 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...
|
|||
179 | |||
180 | 18 | if ( $diWikiPage->getSubobjectName() !== '' ) { |
|
181 | 4 | $result->addPropertyObjectValue( |
|
182 | 4 | self::getSpecialNsResource( 'rdf', 'type' ), |
|
0 ignored issues
–
show
self::getSpecialNsResource('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...
|
|||
183 | 4 | self::getSpecialNsResource( 'swivt', 'Subject' ) |
|
184 | ); |
||
185 | |||
186 | 4 | $masterPage = new SMWDIWikiPage( |
|
187 | 4 | $diWikiPage->getDBkey(), |
|
188 | 4 | $diWikiPage->getNamespace(), |
|
189 | 4 | $diWikiPage->getInterwiki() |
|
190 | ); |
||
191 | |||
192 | 4 | $result->addPropertyObjectValue( |
|
193 | 4 | self::getSpecialNsResource( 'swivt', 'masterPage' ), |
|
0 ignored issues
–
show
self::getSpecialNsResource('swivt', 'masterPage') 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...
|
|||
194 | 4 | self::getDataItemExpElement( $masterPage ) |
|
0 ignored issues
–
show
It seems like
self::getDataItemExpElement($masterPage) can be null ; however, 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...
|
|||
195 | ); |
||
196 | |||
197 | // #649 |
||
198 | // Subobjects contain there individual sortkey's therefore |
||
199 | // no need to add them twice |
||
200 | |||
201 | // #520 |
||
202 | 4 | $result->addPropertyObjectValue( |
|
203 | 4 | self::getSpecialNsResource( 'swivt', 'wikiNamespace' ), |
|
0 ignored issues
–
show
self::getSpecialNsResour...wivt', 'wikiNamespace') 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...
|
|||
204 | 4 | new SMWExpLiteral( strval( $diWikiPage->getNamespace() ), 'http://www.w3.org/2001/XMLSchema#integer' ) |
|
205 | ); |
||
206 | |||
207 | } else { |
||
208 | |||
209 | 17 | $pageTitle = str_replace( '_', ' ', $diWikiPage->getDBkey() ); |
|
210 | 17 | if ( $diWikiPage->getNamespace() !== 0 ) { |
|
211 | 8 | $prefixedSubjectTitle = $wgContLang->getNsText( $diWikiPage->getNamespace()) . ":" . $pageTitle; |
|
212 | } else { |
||
213 | 12 | $prefixedSubjectTitle = $pageTitle; |
|
214 | } |
||
215 | 17 | $prefixedSubjectUrl = wfUrlencode( str_replace( ' ', '_', $prefixedSubjectTitle ) ); |
|
216 | |||
217 | 17 | switch ( $diWikiPage->getNamespace() ) { |
|
218 | 17 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
|
219 | 3 | $maintype_pe = self::getSpecialNsResource( 'owl', 'Class' ); |
|
220 | 3 | $label = $pageTitle; |
|
221 | 3 | break; |
|
222 | 16 | case SMW_NS_PROPERTY: |
|
223 | 6 | $property = new DIProperty( $diWikiPage->getDBKey() ); |
|
224 | 6 | $maintype_pe = self::getSpecialNsResource( 'owl', self::getOWLPropertyType( $property->findPropertyTypeID() ) ); |
|
225 | 6 | $label = $pageTitle; |
|
226 | 6 | break; |
|
227 | default: |
||
228 | 13 | $label = $prefixedSubjectTitle; |
|
229 | 13 | $maintype_pe = self::getSpecialNsResource( 'swivt', 'Subject' ); |
|
230 | } |
||
231 | |||
232 | 17 | $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdf', 'type' ), $maintype_pe ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('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...
|
|||
233 | |||
234 | 17 | if ( !$wikiPageExpElement->isBlankNode() ) { |
|
235 | 17 | $ed = new SMWExpLiteral( $label ); |
|
236 | 17 | $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'label' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('rdfs', 'label') 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...
|
|||
237 | 17 | $ed = new SMWExpResource( self::getNamespaceUri( 'wikiurl' ) . $prefixedSubjectUrl ); |
|
238 | 17 | $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'page' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('swivt', 'page') 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...
|
|||
239 | 17 | $ed = new SMWExpResource( self::$m_exporturl . '/' . $prefixedSubjectUrl ); |
|
240 | 17 | $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('rdfs', 'isDefinedBy') 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...
|
|||
241 | 17 | $ed = new SMWExpLiteral( strval( $diWikiPage->getNamespace() ), 'http://www.w3.org/2001/XMLSchema#integer' ); |
|
242 | 17 | $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'wikiNamespace' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResour...wivt', 'wikiNamespace') 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...
|
|||
243 | |||
244 | 17 | if ( $addStubData ) { |
|
245 | // Add a default sort key; for pages that exist in the wiki, |
||
246 | // this is set during parsing |
||
247 | $defaultSortkey = new SMWExpLiteral( $diWikiPage->getSortKey() ); |
||
248 | $result->addPropertyObjectValue( self::getSpecialPropertyResource( '_SKEY' ), $defaultSortkey ); |
||
0 ignored issues
–
show
self::getSpecialPropertyResource('_SKEY') is of type object<SMW\Exporter\Element\ExpNsResource>|null , 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...
|
|||
249 | } |
||
250 | |||
251 | 17 | if ( $diWikiPage->getNamespace() === NS_FILE ) { |
|
252 | |||
253 | 1 | $title = Title::makeTitle( $diWikiPage->getNamespace(), $diWikiPage->getDBkey() ); |
|
254 | 1 | $file = wfFindFile( $title ); |
|
255 | |||
256 | 1 | if ( $file !== false ) { |
|
257 | 1 | $result->addPropertyObjectValue( |
|
258 | 1 | self::getSpecialNsResource( 'swivt', 'file' ), |
|
0 ignored issues
–
show
self::getSpecialNsResource('swivt', 'file') 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...
|
|||
259 | 1 | new SMWExpResource( $file->getFullURL() ) |
|
260 | ); |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | } |
||
265 | |||
266 | 18 | return $result; |
|
267 | } |
||
268 | |||
269 | /** |
||
270 | * Extend a given SMWExpData element by adding export data for the |
||
271 | * specified property data itme. This method is called when |
||
272 | * constructing export data structures from SMWSemanticData objects. |
||
273 | * |
||
274 | * @param $property SMWDIProperty |
||
275 | * @param $dataItems array of SMWDataItem objects for the given property |
||
276 | * @param $data SMWExpData to add the data to |
||
277 | */ |
||
278 | 17 | static public function addPropertyValues( SMWDIProperty $property, array $dataItems, SMWExpData &$expData ) { |
|
279 | |||
280 | 17 | if ( $property->isUserDefined() ) { |
|
281 | 11 | $pe = self::getResourceElementForProperty( $property ); |
|
282 | 11 | $peHelper = self::getResourceElementForProperty( $property, true ); |
|
283 | |||
284 | 11 | foreach ( $dataItems as $dataItem ) { |
|
285 | 11 | $ed = self::getDataItemExpElement( $dataItem ); |
|
286 | 11 | if ( !is_null( $ed ) ) { |
|
287 | 11 | $expData->addPropertyObjectValue( $pe, $ed ); |
|
0 ignored issues
–
show
$pe is of type object<SMW\Exporter\Element\ExpResource> , 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...
|
|||
288 | } |
||
289 | |||
290 | 11 | $edHelper = self::getDataItemHelperExpElement( $dataItem ); |
|
291 | 11 | if ( !is_null( $edHelper ) ) { |
|
292 | 11 | $expData->addPropertyObjectValue( $peHelper, $edHelper ); |
|
0 ignored issues
–
show
$peHelper is of type object<SMW\Exporter\Element\ExpResource> , 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...
|
|||
293 | } |
||
294 | } |
||
295 | } else { // pre-defined property, only exported if known |
||
296 | 17 | $diSubject = $expData->getSubject()->getDataItem(); |
|
297 | // subject wikipage required for disambiguating special properties: |
||
298 | 17 | if ( is_null( $diSubject ) || |
|
299 | 17 | $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE ) { |
|
300 | return; |
||
301 | } |
||
302 | |||
303 | 17 | $pe = self::getSpecialPropertyResource( $property->getKey(), $diSubject->getNamespace() ); |
|
304 | 17 | if ( is_null( $pe ) ) { |
|
305 | return; // unknown special property, not exported |
||
306 | } |
||
307 | // have helper property ready before entering the for loop, even if not needed: |
||
308 | 17 | $peHelper = self::getResourceElementForProperty( $property, true ); |
|
309 | |||
310 | 17 | $filterNamespace = ( $property->getKey() == '_REDI' || $property->getKey() == '_URI' ); |
|
311 | |||
312 | 17 | foreach ( $dataItems as $dataItem ) { |
|
313 | // Basic namespace filtering to ensure that types match for redirects etc. |
||
314 | /// TODO: currently no full check for avoiding OWL DL illegal redirects is done (OWL property type ignored) |
||
315 | 17 | if ( $filterNamespace && !( $dataItem instanceof SMWDIUri ) && |
|
316 | 17 | ( !( $dataItem instanceof SMWDIWikiPage ) ) ) { |
|
317 | continue; |
||
318 | } |
||
319 | |||
320 | 17 | $ed = self::getDataItemExpElement( $dataItem ); |
|
321 | |||
322 | 17 | if ( !is_null( $ed ) ) { |
|
323 | 17 | if ( $property->getKey() == '_CONC' && |
|
324 | 17 | $expData->getSubject()->getUri() !== '' ) { |
|
325 | // equivalent to anonymous class -> simplify description |
||
326 | foreach ( $ed->getProperties() as $subp ) { |
||
327 | if ( $subp->getUri() != self::getSpecialNsResource( 'rdf', 'type' )->getUri() ) { |
||
328 | foreach ( $ed->getValues( $subp ) as $subval ) { |
||
329 | $expData->addPropertyObjectValue( $subp, $subval ); |
||
330 | } |
||
331 | } |
||
332 | } |
||
333 | 17 | } elseif ( $property->getKey() == '_IMPO' ) { |
|
334 | |||
335 | 1 | $dataValue = DataValueFactory::getInstance()->newDataItemValue( |
|
336 | $dataItem, |
||
337 | $property |
||
338 | ); |
||
339 | |||
340 | 1 | if ( !$dataValue instanceof \SMWImportValue ) { |
|
341 | continue; |
||
342 | } |
||
343 | |||
344 | 1 | $expData->addPropertyObjectValue( |
|
345 | $pe, |
||
0 ignored issues
–
show
$pe 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...
|
|||
346 | 1 | self::getDataItemExpElement( new SMWDIBlob( $dataValue->getImportReference() ) ) |
|
0 ignored issues
–
show
It seems like
self::getDataItemExpElem...>getImportReference())) can be null ; however, 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...
|
|||
347 | ); |
||
348 | |||
349 | 17 | } elseif ( $property->getKey() == '_REDI' ) { |
|
350 | 2 | $expData->addPropertyObjectValue( $pe, $ed ); |
|
0 ignored issues
–
show
$pe 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...
|
|||
351 | |||
352 | 2 | $expData->addPropertyObjectValue( |
|
353 | 2 | self::getSpecialPropertyResource( '_URI' ), |
|
0 ignored issues
–
show
self::getSpecialPropertyResource('_URI') is of type object<SMW\Exporter\Element\ExpNsResource>|null , 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...
|
|||
354 | $ed |
||
355 | ); |
||
356 | 17 | } elseif ( !$property->isUserDefined() && !self::hasSpecialPropertyResource( $property ) ) { |
|
357 | 6 | $expData->addPropertyObjectValue( |
|
358 | 6 | self::getResourceElementForProperty( $property, true ), |
|
0 ignored issues
–
show
self::getResourceElement...operty($property, true) is of type object<SMW\Exporter\Element\ExpResource> , 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...
|
|||
359 | $ed |
||
360 | ); |
||
361 | } else { |
||
362 | 17 | $expData->addPropertyObjectValue( $pe, $ed ); |
|
0 ignored issues
–
show
$pe 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...
|
|||
363 | } |
||
364 | } |
||
365 | |||
366 | 17 | $edHelper = self::getDataItemHelperExpElement( $dataItem ); |
|
367 | |||
368 | 17 | if ( $edHelper !== null ) { |
|
369 | 17 | $expData->addPropertyObjectValue( $peHelper, $edHelper ); |
|
0 ignored issues
–
show
$peHelper is of type object<SMW\Exporter\Element\ExpResource> , 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...
|
|||
370 | } |
||
371 | } |
||
372 | } |
||
373 | 17 | } |
|
374 | |||
375 | /** |
||
376 | * @see DataItemToExpResourceEncoder::mapPropertyToResourceElement |
||
377 | */ |
||
378 | 18 | static public function getResourceElementForProperty( SMWDIProperty $diProperty, $helperProperty = false ) { |
|
379 | 18 | return self::$dataItemToExpResourceEncoder->mapPropertyToResourceElement( $diProperty, $helperProperty ); |
|
380 | } |
||
381 | |||
382 | /** |
||
383 | * @see DataItemToExpResourceEncoder::mapWikiPageToResourceElement |
||
384 | */ |
||
385 | 18 | static public function getResourceElementForWikiPage( SMWDIWikiPage $diWikiPage, $markForAuxiliaryUsage = false ) { |
|
386 | 18 | return self::$dataItemToExpResourceEncoder->mapWikiPageToResourceElement( $diWikiPage, $markForAuxiliaryUsage ); |
|
387 | } |
||
388 | |||
389 | /** |
||
390 | * Try to find an SMWDataItem that the given SMWExpElement might |
||
391 | * represent. Returns null if this attempt failed. |
||
392 | * |
||
393 | * @param SMWExpElement $expElement |
||
394 | * @return SMWDataItem or null |
||
395 | */ |
||
396 | 8 | public function findDataItemForExpElement( SMWExpElement $expElement ) { |
|
397 | 8 | return self::$dataItemByExpElementMatchFinder->tryToFindDataItemForExpElement( $expElement ); |
|
398 | } |
||
399 | |||
400 | /** |
||
401 | * Determine what kind of OWL property some SMW property should be exported as. |
||
402 | * The input is an SMWTypesValue object, a typeid string, or empty (use default) |
||
403 | * @todo An improved mechanism for selecting property types here is needed. |
||
404 | */ |
||
405 | 6 | static public function getOWLPropertyType( $type = '' ) { |
|
406 | 6 | if ( $type instanceof SMWDIWikiPage ) { |
|
407 | $type = DataTypeRegistry::getInstance()->findTypeId( str_replace( '_', ' ', $type->getDBkey() ) ); |
||
408 | 6 | } elseif ( $type == false ) { |
|
409 | $type = ''; |
||
410 | } |
||
411 | |||
412 | switch ( $type ) { |
||
413 | 6 | case '_anu': |
|
414 | 1 | return 'AnnotationProperty'; |
|
415 | 6 | case '': case '_wpg': case '_wpp': case '_wpc': case '_wpf': |
|
416 | 3 | case '_uri': case '_ema': case '_tel': case '_rec': case '__typ': |
|
417 | 2 | case '__red': case '__spf': case '__spu': |
|
418 | 6 | return 'ObjectProperty'; |
|
419 | default: |
||
420 | 2 | return 'DatatypeProperty'; |
|
421 | } |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Get an ExpNsResource for a special property of SMW, or null if |
||
426 | * no resource is assigned to the given property key. The optional |
||
427 | * namespace is used to select the proper resource for properties that |
||
428 | * must take the type of the annotated object into account for some |
||
429 | * reason. |
||
430 | * |
||
431 | * @param $propertyKey string the Id of the special property |
||
432 | * @param $forNamespace integer the namespace of the page which has a value for this property |
||
433 | * @return ExpNsResource|null |
||
434 | */ |
||
435 | 18 | static public function getSpecialPropertyResource( $propertyKey, $forNamespace = NS_MAIN ) { |
|
436 | switch ( $propertyKey ) { |
||
437 | 18 | case '_INST': |
|
438 | 3 | return self::getSpecialNsResource( 'rdf', 'type' ); |
|
439 | 18 | case '_SUBC': |
|
440 | 3 | return self::getSpecialNsResource( 'rdfs', 'subClassOf' ); |
|
441 | 18 | case '_CONC': |
|
442 | return self::getSpecialNsResource( 'owl', 'equivalentClass' ); |
||
443 | 18 | case '_URI': |
|
444 | 2 | if ( $forNamespace == NS_CATEGORY || $forNamespace == SMW_NS_CONCEPT ) { |
|
445 | return self::getSpecialNsResource( 'owl', 'equivalentClass' ); |
||
446 | 2 | } elseif ( $forNamespace == SMW_NS_PROPERTY ) { |
|
447 | return self::getSpecialNsResource( 'owl', 'equivalentProperty' ); |
||
448 | } else { |
||
449 | 2 | return self::getSpecialNsResource( 'owl', 'sameAs' ); |
|
450 | } |
||
451 | 18 | case '_REDI': |
|
452 | 3 | return self::getSpecialNsResource( 'swivt', 'redirectsTo' ); |
|
453 | 18 | case '_SUBP': |
|
454 | 1 | if ( $forNamespace == SMW_NS_PROPERTY ) { |
|
455 | 1 | return self::getSpecialNsResource( 'rdfs', 'subPropertyOf' ); |
|
456 | } else { |
||
457 | return null; |
||
458 | } |
||
459 | 18 | case '_MDAT': |
|
460 | 7 | return self::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' ); |
|
461 | 18 | case '_CDAT': |
|
462 | return self::getSpecialNsResource( 'swivt', 'wikiPageCreationDate' ); |
||
463 | 18 | case '_LEDT': |
|
464 | return self::getSpecialNsResource( 'swivt', 'wikiPageLastEditor' ); |
||
465 | 18 | case '_NEWP': |
|
466 | return self::getSpecialNsResource( 'swivt', 'wikiPageIsNew' ); |
||
467 | 18 | case '_SKEY': |
|
468 | 17 | return self::getSpecialNsResource( 'swivt', 'wikiPageSortKey' ); |
|
469 | 8 | case '_TYPE': |
|
470 | 4 | return self::getSpecialNsResource( 'swivt', 'type' ); |
|
471 | 7 | case '_IMPO': |
|
472 | 1 | return self::getSpecialNsResource( 'swivt', 'specialImportedFrom' ); |
|
473 | default: |
||
474 | 6 | return self::getSpecialNsResource( 'swivt', 'specialProperty' . $propertyKey ); |
|
475 | } |
||
476 | } |
||
477 | |||
478 | |||
479 | /** |
||
480 | * Create an ExpNsResource for some special element that belongs to |
||
481 | * a known vocabulary. An exception is generated when given parameters |
||
482 | * that do not fit any known vocabulary. |
||
483 | * |
||
484 | * @param $namespaceId string (e.g. "rdf") |
||
485 | * @param $localName string (e.g. "type") |
||
486 | * @return ExpNsResource |
||
487 | */ |
||
488 | 21 | static public function getSpecialNsResource( $namespaceId, $localName ) { |
|
489 | 21 | $namespace = self::getNamespaceUri( $namespaceId ); |
|
490 | 21 | if ( $namespace !== '' ) { |
|
491 | 21 | return new ExpNsResource( $localName, $namespace, $namespaceId ); |
|
0 ignored issues
–
show
It seems like
$namespace defined by self::getNamespaceUri($namespaceId) on line 489 can also be of type boolean ; however, SMW\Exporter\Element\ExpNsResource::__construct() does only seem to accept string , 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...
|
|||
492 | } else { |
||
493 | throw new InvalidArgumentException( "The vocabulary '$namespaceId' is not a known special vocabulary." ); |
||
494 | } |
||
495 | } |
||
496 | |||
497 | /** |
||
498 | * This function expands standard XML entities used in some generated |
||
499 | * URIs. Given a string with such entities, it returns a string with |
||
500 | * all entities properly replaced. |
||
501 | * |
||
502 | * @note The function SMWExporter::getInstance()->getNamespaceUri() is often more |
||
503 | * suitable. This XML-specific method might become obsolete. |
||
504 | * |
||
505 | * @param $uri string of the URI to be expanded |
||
506 | * @return string of the expanded URI |
||
507 | */ |
||
508 | 10 | static public function expandURI( $uri ) { |
|
509 | 10 | self::initBaseURIs(); |
|
510 | 10 | $uri = str_replace( array( '&wiki;', '&wikiurl;', '&property;', '&category;', '&owl;', '&rdf;', '&rdfs;', '&swivt;', '&export;' ), |
|
511 | 10 | array( self::$m_ent_wiki, self::$m_ent_wikiurl, self::$m_ent_property, self::$m_ent_category, 'http://www.w3.org/2002/07/owl#', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'http://www.w3.org/2000/01/rdf-schema#', 'http://semantic-mediawiki.org/swivt/1.0#', |
|
512 | 10 | self::$m_exporturl ), |
|
513 | $uri ); |
||
514 | 10 | return $uri; |
|
515 | } |
||
516 | |||
517 | /** |
||
518 | * @return string |
||
519 | */ |
||
520 | public function decodeURI( $uri ) { |
||
521 | return Escaper::decodeUri( $uri ); |
||
522 | } |
||
523 | |||
524 | /** |
||
525 | * Get the URI of a standard namespace prefix used in SMW, or the empty |
||
526 | * string if the prefix is not known. |
||
527 | * |
||
528 | * @param $shortName string id (prefix) of the namespace |
||
529 | * @return string of the expanded URI |
||
530 | */ |
||
531 | 29 | static public function getNamespaceUri( $shortName ) { |
|
532 | 29 | self::initBaseURIs(); |
|
533 | switch ( $shortName ) { |
||
534 | 29 | case 'wiki': |
|
535 | 24 | return self::$m_ent_wiki; |
|
536 | 21 | case 'wikiurl': |
|
537 | 17 | return self::$m_ent_wikiurl; |
|
538 | 21 | case 'property': |
|
539 | 18 | return self::$m_ent_property; |
|
540 | 21 | case 'category': |
|
541 | 7 | return self::$m_ent_category; |
|
542 | 21 | case 'export': |
|
543 | return self::$m_exporturl; |
||
544 | 21 | case 'owl': |
|
545 | 16 | return 'http://www.w3.org/2002/07/owl#'; |
|
546 | 20 | case 'rdf': |
|
547 | 20 | return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; |
|
548 | 20 | case 'rdfs': |
|
549 | 19 | return 'http://www.w3.org/2000/01/rdf-schema#'; |
|
550 | 20 | case 'swivt': |
|
551 | 20 | return 'http://semantic-mediawiki.org/swivt/1.0#'; |
|
552 | 1 | case 'xsd': |
|
553 | 1 | return 'http://www.w3.org/2001/XMLSchema#'; |
|
554 | default: |
||
555 | return ''; |
||
556 | } |
||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Create an SMWExpData container that encodes the ontology header for an |
||
561 | * SMW exported OWL file. |
||
562 | * |
||
563 | * @param string $ontologyuri specifying the URI of the ontology, possibly |
||
564 | * empty |
||
565 | * |
||
566 | * @return SMWExpData |
||
567 | */ |
||
568 | 10 | static public function getOntologyExpData( $ontologyuri ) { |
|
569 | 10 | $data = new SMWExpData( new SMWExpResource( $ontologyuri ) ); |
|
570 | 10 | $ed = self::getSpecialNsResource( 'owl', 'Ontology' ); |
|
571 | 10 | $data->addPropertyObjectValue( self::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('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...
|
|||
572 | 10 | $ed = new SMWExpLiteral( date( DATE_W3C ), 'http://www.w3.org/2001/XMLSchema#dateTime' ); |
|
573 | 10 | $data->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'creationDate' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResour...swivt', 'creationDate') 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...
|
|||
574 | 10 | $ed = new SMWExpResource( 'http://semantic-mediawiki.org/swivt/1.0' ); |
|
575 | 10 | $data->addPropertyObjectValue( self::getSpecialNsResource( 'owl', 'imports' ), $ed ); |
|
0 ignored issues
–
show
self::getSpecialNsResource('owl', 'imports') 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...
|
|||
576 | 10 | return $data; |
|
577 | } |
||
578 | |||
579 | /** |
||
580 | * @see DataItemToElementEncoder::mapDataItemToElement |
||
581 | */ |
||
582 | 22 | static public function getDataItemExpElement( SMWDataItem $dataItem ) { |
|
583 | 22 | return self::$dataItemToElementEncoder->mapDataItemToElement( $dataItem ); |
|
584 | } |
||
585 | |||
586 | /** |
||
587 | * Create an SWMExpElement that encodes auxiliary data for representing |
||
588 | * values of the specified dataitem object in a simplified fashion. |
||
589 | * This is done for types of dataitems that are not supported very well |
||
590 | * in current systems, or that do not match a standard datatype in RDF. |
||
591 | * For example, time points (DITime) are encoded as numbers. The number |
||
592 | * can replace the actual time for all query and ordering purposes (the |
||
593 | * order in either case is linear and maps to the real number line). |
||
594 | * Only data retrieval should better use the real values to avoid that |
||
595 | * rounding errors lead to unfaithful recovery of data. Note that the |
||
596 | * helper values do not maintain any association with their original |
||
597 | * values -- they are a fully redundant alternative representation, not |
||
598 | * an additional piece of information for the main values. Even if |
||
599 | * decoding is difficult, they must be in one-to-one correspondence to |
||
600 | * the original value. |
||
601 | * |
||
602 | * For dataitems that do not have such a simplification, the method |
||
603 | * returns null. |
||
604 | * |
||
605 | * @note If a helper element is used, then it must be the same as |
||
606 | * getDataItemHelperExpElement( $dataItem->getSortKeyDataItem() ). |
||
607 | * Query conditions like ">" use sortkeys for values, and helper |
||
608 | * elements are always preferred in query answering. |
||
609 | * |
||
610 | * @param $dataItem SMWDataItem |
||
611 | * @return SMWExpElement or null |
||
612 | */ |
||
613 | 17 | static public function getDataItemHelperExpElement( SMWDataItem $dataItem ) { |
|
614 | |||
615 | 17 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) { |
|
616 | 8 | return new SMWExpLiteral( (string)$dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#double', '', $dataItem ); |
|
617 | } |
||
618 | |||
619 | 17 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_GEO ) { |
|
620 | return new SMWExpLiteral( (string)$dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#string', '', $dataItem ); |
||
621 | } |
||
622 | |||
623 | 17 | return null; |
|
624 | } |
||
625 | |||
626 | /** |
||
627 | * Check whether the values of a given type of dataitem have helper |
||
628 | * values in the sense of SMWExporter::getInstance()->getDataItemHelperExpElement(). |
||
629 | * |
||
630 | * @param DIProperty $property |
||
631 | * |
||
632 | * @return boolean |
||
633 | */ |
||
634 | 2 | static public function hasHelperExpElement( DIProperty $property ) { |
|
635 | 2 | return ( $property->findPropertyTypeID() === '_dat' || $property->findPropertyTypeID() === '_geo' ) || ( !$property->isUserDefined() && !self::hasSpecialPropertyResource( $property ) ); |
|
636 | } |
||
637 | |||
638 | 17 | static protected function hasSpecialPropertyResource( DIProperty $property ) { |
|
639 | 17 | return $property->getKey() === '_SKEY' || |
|
640 | 14 | $property->getKey() === '_INST' || |
|
641 | 13 | $property->getKey() === '_MDAT' || |
|
642 | 11 | $property->getKey() === '_SUBC' || |
|
643 | 9 | $property->getKey() === '_SUBP' || |
|
644 | 8 | $property->getKey() === '_TYPE' || |
|
645 | 6 | $property->getKey() === '_IMPO' || |
|
646 | 17 | $property->getKey() === '_URI'; |
|
647 | } |
||
648 | |||
649 | } |
||
650 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.