Completed
Push — master ( 9cb597...d2d2ad )
by mw
13s
created

includes/export/SMW_Exporter.php (59 issues)

Upgrade to new PHP Analysis Engine

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\Localizer;
8
use SMW\NamespaceUriFinder;
9
use SMW\Exporter\DataItemByExpElementMatchFinder;
10
use SMW\Exporter\DataItemToElementEncoder;
11
use SMW\Exporter\DataItemToExpResourceEncoder;
12
use SMW\Exporter\Element\ExpElement;
13
use SMW\Exporter\Element\ExpLiteral;
14
use SMW\Exporter\Element\ExpNsResource;
15
use SMW\Exporter\Escaper;
16
use SMW\Exporter\ResourceBuilders\DispatchingResourceBuilder;
17
18
/**
19
 * SMWExporter is a class for converting internal page-based data (SMWSemanticData) into
20
 * a format for easy serialisation in OWL or RDF.
21
 *
22
 * @author Markus Krötzsch
23
 * @ingroup SMW
24
 */
25
class SMWExporter {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
27
	const POOLCACHE_ID = 'exporter.shared';
28
29
	/**
30
	 * @var SMWExporter
31
	 */
32
	private static $instance = null;
33
34
	/**
35
	 * @var DataItemToExpResourceEncoder
36
	 */
37
	private static $dataItemToExpResourceEncoder = null;
38
39
	/**
40
	 * @var DataItemToElementEncoder
41
	 */
42
	private static $dataItemToElementEncoder = null;
43
44
	/**
45
	 * @var DataItemByExpElementMatchFinder
46
	 */
47
	private static $dataItemByExpElementMatchFinder = null;
48
49
	/**
50
	 * @var DispatchingResourceBuilder
51
	 */
52
	private static $dispatchingResourceBuilder = null;
53
54
	static protected $m_exporturl = false;
55
	static protected $m_ent_wiki = false;
56
	static protected $m_ent_property = false;
57
	static protected $m_ent_category = false;
58
	static protected $m_ent_wikiurl = false;
59
60
	/**
61
	 * @since 2.0
62
	 *
63
	 * @return SMWExporter
64
	 */
65 291
	public static function getInstance() {
66
67 291
		if ( self::$instance === null ) {
68
69 269
			self::$instance = new self();
70 269
			self::$instance->initBaseURIs();
71
72 269
			$applicationFactory = ApplicationFactory::getInstance();
73
74 269
			$poolCache = $applicationFactory->getInMemoryPoolCache();
75 269
			$poolCache->resetPoolCacheFor( self::POOLCACHE_ID );
76
77
			// FIXME with 3.x
78
			// There is no better way of getting around the static use without BC
79 269
			self::$dataItemToElementEncoder = new DataItemToElementEncoder();
80
81 269
			self::$dispatchingResourceBuilder = new DispatchingResourceBuilder();
82
83 269
			self::$dataItemToExpResourceEncoder = new DataItemToExpResourceEncoder(
84 269
				$applicationFactory->getStore()
85
			);
86
87 269
			self::$dataItemToExpResourceEncoder->reset();
88
89 269
			self::$dataItemToExpResourceEncoder->setBCAuxiliaryUse(
90 269
				$applicationFactory->getSettings()->get( 'smwgExportBCAuxiliaryUse' )
91
			);
92
93 269
			self::$dataItemByExpElementMatchFinder = new DataItemByExpElementMatchFinder(
94 269
				$applicationFactory->getStore(),
95 269
				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...
96
			);
97
		}
98
99 291
		return self::$instance;
100
	}
101
102
	/**
103
	 * @since 2.0
104
	 */
105 270
	public static function clear() {
106 270
		self::$instance = null;
107 270
		self::$m_exporturl = false;
108 270
	}
109
110
	/**
111
	 * @since 2.2
112
	 */
113 140
	public function resetCacheBy( SMWDIWikiPage $diWikiPage ) {
114 140
		self::$dataItemToExpResourceEncoder->resetCacheBy( $diWikiPage );
115 140
	}
116
117
	/**
118
	 * Make sure that necessary base URIs are initialised properly.
119
	 */
120 286
	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...
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
121 286
		if ( self::$m_exporturl !== false ) {
122 33
			return;
123
		}
124 269
		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 global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
125
126 269
		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 global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
127
128 269
		$resolver = Title::makeTitle( NS_SPECIAL, 'URIResolver' );
129
130 269
		if ( '' == $smwgNamespace ) {
131
			$smwgNamespace = $resolver->getFullURL() . '/';
132 269
		} elseif ( $smwgNamespace[0] == '.' ) {
133
			$smwgNamespace = "http://" . substr( $smwgNamespace, 1 ) . $resolver->getLocalURL() . '/';
134
		}
135
136
		// The article name must be the last part of wiki URLs for proper OWL/RDF export:
137 269
		self::$m_ent_wikiurl  = $wgServer . str_replace( '$1', '', $wgArticlePath );
0 ignored issues
show
Documentation Bug introduced by
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...
138 269
		self::$m_ent_wiki     = $smwgNamespace;
0 ignored issues
show
Documentation Bug introduced by
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...
139
140 269
		$property = $GLOBALS['smwgExportBCNonCanonicalFormUse'] ? urlencode( str_replace( ' ', '_', $wgContLang->getNsText( SMW_NS_PROPERTY ) ) ) : 'Property';
141 269
		$category = $GLOBALS['smwgExportBCNonCanonicalFormUse'] ? urlencode( str_replace( ' ', '_', $wgContLang->getNsText( NS_CATEGORY ) ) ) : 'Category';
142
143 269
		self::$m_ent_property = self::$m_ent_wiki . Escaper::encodeUri( $property . ':' );
0 ignored issues
show
Documentation Bug introduced by
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...
144 269
		self::$m_ent_category = self::$m_ent_wiki . Escaper::encodeUri( $category . ':' );
0 ignored issues
show
Documentation Bug introduced by
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...
145
146 269
		$title = Title::makeTitle( NS_SPECIAL, 'ExportRDF' );
147 269
		self::$m_exporturl    = self::$m_ent_wikiurl . $title->getPrefixedURL();
0 ignored issues
show
Documentation Bug introduced by
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...
148
149
		// Canonical form, the title object always contains a wgContLang reference
150
		// therefore replace it
151 269
		if ( !$GLOBALS['smwgExportBCNonCanonicalFormUse'] ) {
152 269
			$localizer = Localizer::getInstance();
153
154 269
			self::$m_ent_property = $localizer->getCanonicalizedUrlByNamespace( NS_SPECIAL, self::$m_ent_property );
0 ignored issues
show
Documentation Bug introduced by
The property $m_ent_property was declared of type boolean, but $localizer->getCanonical... self::$m_ent_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...
155 269
			self::$m_ent_category = $localizer->getCanonicalizedUrlByNamespace( NS_SPECIAL, self::$m_ent_category );
0 ignored issues
show
Documentation Bug introduced by
The property $m_ent_category was declared of type boolean, but $localizer->getCanonical... self::$m_ent_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...
156 269
			self::$m_ent_wiki = $localizer->getCanonicalizedUrlByNamespace( NS_SPECIAL, self::$m_ent_wiki );
0 ignored issues
show
Documentation Bug introduced by
The property $m_ent_wiki was declared of type boolean, but $localizer->getCanonical...IAL, self::$m_ent_wiki) 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...
157 269
			self::$m_exporturl = $localizer->getCanonicalizedUrlByNamespace( NS_SPECIAL, self::$m_exporturl );
0 ignored issues
show
Documentation Bug introduced by
The property $m_exporturl was declared of type boolean, but $localizer->getCanonical...AL, self::$m_exporturl) 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...
158
		}
159 269
	}
160
161
	/**
162
	 * Create exportable data from a given semantic data record.
163
	 *
164
	 * @param $semdata SMWSemanticData
165
	 * @return SMWExpData
166
	 */
167 20
	static public function makeExportData( SMWSemanticData $semdata ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
168 20
		self::initBaseURIs();
169
170 20
		$subject = $semdata->getSubject();
171
172
		// Make sure to use the canonical form, a localized representation
173
		// should not carry a reference to a subject (e.g invoked as incoming
174
		// property caused by a different user language)
175 20
		if ( $subject->getNamespace() === SMW_NS_PROPERTY && $subject->getSubobjectName() === '' ) {
176 8
			$subject = DIProperty::newFromUserLabel( $subject->getDBKey() )->getCanonicalDiWikiPage();
177
		}
178
179
	       // #1690 Couldn't match a CanonicalDiWikiPage which is most likely caused
180
	       // by an outdated pre-defined property therefore use the original subject
181 20
	       if ( $subject->getDBKey() === '' ) {
182
	           $subject = $semdata->getSubject();
183
	       }
184
185
		// #649 Alwways make sure to have a least one valid sortkey
186 20
		if ( !$semdata->getPropertyValues( new DIProperty( '_SKEY' ) ) && $subject->getSortKey() !== '' ) {
187 12
			$semdata->addPropertyObjectValue(
188 12
				new DIProperty( '_SKEY' ),
189 12
				new SMWDIBlob( $subject->getSortKey() )
190
			);
191
		}
192
193 20
		$result = self::makeExportDataForSubject( $subject );
0 ignored issues
show
$subject is of type object<SMW\DIWikiPage>|null, but the function expects a object<SMWDIWikiPage>.

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
195 20
		foreach ( $semdata->getProperties() as $property ) {
196 20
			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 @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
197
		}
198
199 20
		return $result;
200
	}
201
202
	/**
203
	 * Make an SMWExpData object for the given page, and include the basic
204
	 * properties about this subject that are not directly represented by
205
	 * SMW property values. The optional parameter $typevalueforproperty
206
	 * can be used to pass a particular SMWTypesValue object that is used
207
	 * for determining the OWL type for property pages.
208
	 *
209
	 * @todo Take into account whether the wiki page belongs to a builtin property, and ensure URI alignment/type declaration in this case.
210
	 *
211
	 * @param $diWikiPage SMWDIWikiPage
212
	 * @param $addStubData boolean to indicate if additional data should be added to make a stub entry for this page
213
	 * @return SMWExpData
214
	 */
215 22
	static public function makeExportDataForSubject( SMWDIWikiPage $diWikiPage, $addStubData = false ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
216 22
		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 global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
217
218 22
		$wikiPageExpElement = self::getDataItemExpElement( $diWikiPage );
219 22
		$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...
220
221 22
		if ( $diWikiPage->getSubobjectName() !== '' ) {
222 7
			$result->addPropertyObjectValue(
223 7
				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...
224 7
				self::getSpecialNsResource( 'swivt', 'Subject' )
225
			);
226
227 7
			$masterPage = new SMWDIWikiPage(
228 7
				$diWikiPage->getDBkey(),
229 7
				$diWikiPage->getNamespace(),
230 7
				$diWikiPage->getInterwiki()
231
			);
232
233 7
			$result->addPropertyObjectValue(
234 7
				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...
235 7
				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...
236
			);
237
238
			// #649
239
			// Subobjects contain there individual sortkey's therefore
240
			// no need to add them twice
241
242
			// #520
243 7
			$result->addPropertyObjectValue(
244 7
				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...
245 7
				new ExpLiteral( strval( $diWikiPage->getNamespace() ), 'http://www.w3.org/2001/XMLSchema#integer' )
246
			);
247
248
		} else {
249
250
			// #1410 (use the display title as label when available)
251 21
			$displayTitle = DataValueFactory::getInstance()->newDataValueByItem( $diWikiPage )->getDisplayTitle();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SMWDataValue as the method getDisplayTitle() does only exist in the following sub-classes of SMWDataValue: SMWWikiPageValue. 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

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
252
253 21
			$pageTitle = str_replace( '_', ' ', $diWikiPage->getDBkey() );
254 21
			if ( $diWikiPage->getNamespace() !== 0 ) {
255 11
				$prefixedSubjectTitle = $wgContLang->getNsText( $diWikiPage->getNamespace()) . ":" . $pageTitle;
256
			} else {
257 13
				$prefixedSubjectTitle = $pageTitle;
258
			}
259 21
			$prefixedSubjectUrl = wfUrlencode( str_replace( ' ', '_', $prefixedSubjectTitle ) );
260
261 21
			switch ( $diWikiPage->getNamespace() ) {
262 21
				case NS_CATEGORY: case SMW_NS_CONCEPT:
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
263 3
					$maintype_pe = self::getSpecialNsResource( 'owl', 'Class' );
264 3
					$label = $pageTitle;
265 3
				break;
266 20
				case SMW_NS_PROPERTY:
267 9
					$property = new DIProperty( $diWikiPage->getDBKey() );
268 9
					$maintype_pe = self::getSpecialNsResource( 'owl', self::getOWLPropertyType( $property->findPropertyTypeID() ) );
269 9
					$label = $pageTitle;
270 9
				break;
271
				default:
272 14
					$label = $prefixedSubjectTitle;
273 14
					$maintype_pe = self::getSpecialNsResource( 'swivt', 'Subject' );
274
			}
275
276 21
			$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...
277
278 21
			if ( !$wikiPageExpElement->isBlankNode() ) {
279 21
				$ed = new ExpLiteral( $displayTitle !== '' ? $displayTitle : $label );
280 21
				$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...
281 21
				$ed = new SMWExpResource( self::getNamespaceUri( 'wikiurl' ) . $prefixedSubjectUrl );
282 21
				$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...
283 21
				$ed = new SMWExpResource( self::$m_exporturl . '/' . $prefixedSubjectUrl );
284 21
				$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...
285 21
				$ed = new ExpLiteral( strval( $diWikiPage->getNamespace() ), 'http://www.w3.org/2001/XMLSchema#integer' );
286 21
				$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...
287
288 21
				if ( $addStubData ) {
289
					// Add a default sort key; for pages that exist in the wiki,
290
					// this is set during parsing
291
					$defaultSortkey = new ExpLiteral( $diWikiPage->getSortKey() );
292
					$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...
293
				}
294
295 21
				if ( $diWikiPage->getPageLanguage() ) {
296 21
					$result->addPropertyObjectValue(
297 21
						self::getSpecialNsResource( 'swivt', 'wikiPageContentLanguage' ),
0 ignored issues
show
self::getSpecialNsResour...kiPageContentLanguage') 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...
298 21
						new ExpLiteral( strval( $diWikiPage->getPageLanguage() ), 'http://www.w3.org/2001/XMLSchema#string' )
299
					);
300
				}
301
302 21
				if ( $diWikiPage->getNamespace() === NS_FILE ) {
303
304 1
					$title = Title::makeTitle( $diWikiPage->getNamespace(), $diWikiPage->getDBkey() );
305 1
					$file = wfFindFile( $title );
306
307 1
					if ( $file !== false ) {
308 1
						$result->addPropertyObjectValue(
309 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...
310 1
							new SMWExpResource( $file->getFullURL() )
311
						);
312
					}
313
				}
314
			}
315
		}
316
317 22
		return $result;
318
	}
319
320
	/**
321
	 * Extend a given SMWExpData element by adding export data for the
322
	 * specified property data itme. This method is called when
323
	 * constructing export data structures from SMWSemanticData objects.
324
	 *
325
	 * @param $property SMWDIProperty
326
	 * @param $dataItems array of SMWDataItem objects for the given property
327
	 * @param $data SMWExpData to add the data to
328
	 */
329 21
	static public function addPropertyValues( SMWDIProperty $property, array $dataItems, SMWExpData &$expData ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
330
331 21
		$resourceBuilder = self::$dispatchingResourceBuilder->findResourceBuilder( $property );
332
333 21
		if ( $property->isUserDefined() ) {
334 12
			foreach ( $dataItems as $dataItem ) {
335 12
				$resourceBuilder->addResourceValue( $expData, $property, $dataItem );
336
			}
337
		} else { // pre-defined property, only exported if known
338 21
			$diSubject = $expData->getSubject()->getDataItem();
339
			// subject wikipage required for disambiguating special properties:
340 21
			if ( is_null( $diSubject ) ||
341 21
			     $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE ) {
342
				return;
343
			}
344
345 21
			$pe = self::getSpecialPropertyResource( $property->getKey(), $diSubject->getNamespace() );
346 21
			if ( is_null( $pe ) ) {
347
				return; // unknown special property, not exported
348
			}
349
			// have helper property ready before entering the for loop, even if not needed:
350 21
			$peHelper = self::getResourceElementForProperty( $property, true );
0 ignored issues
show
$peHelper is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
351
352 21
			$filterNamespace = ( $property->getKey() == '_REDI' || $property->getKey() == '_URI' );
353
354 21
			foreach ( $dataItems as $dataItem ) {
355
				// Basic namespace filtering to ensure that types match for redirects etc.
356
				/// TODO: currently no full check for avoiding OWL DL illegal redirects is done (OWL property type ignored)
357 21
				if ( $filterNamespace && !( $dataItem instanceof SMWDIUri ) &&
358 21
				     ( !( $dataItem instanceof SMWDIWikiPage ) ) ) {
359
					continue;
360
				}
361
362 21
				$resourceBuilder->addResourceValue( $expData, $property, $dataItem );
363
			}
364
		}
365 21
	}
366
367
	/**
368
	 * @see DataItemToExpResourceEncoder::mapPropertyToResourceElement
369
	 */
370 22
	static public function getResourceElementForProperty( SMWDIProperty $diProperty, $helperProperty = false ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
371 22
		return self::$dataItemToExpResourceEncoder->mapPropertyToResourceElement( $diProperty, $helperProperty );
372
	}
373
374
	/**
375
	 * @see DataItemToExpResourceEncoder::mapWikiPageToResourceElement
376
	 */
377 22
	static public function getResourceElementForWikiPage( SMWDIWikiPage $diWikiPage, $markForAuxiliaryUsage = false ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
378 22
		return self::$dataItemToExpResourceEncoder->mapWikiPageToResourceElement( $diWikiPage, $markForAuxiliaryUsage );
379
	}
380
381
	/**
382
	 * Try to find an SMWDataItem that the given ExpElement might
383
	 * represent. Returns null if this attempt failed.
384
	 *
385
	 * @param ExpElement $expElement
386
	 * @return SMWDataItem or null
387
	 */
388 8
	public function findDataItemForExpElement( ExpElement $expElement ) {
389 8
		return self::$dataItemByExpElementMatchFinder->tryToFindDataItemForExpElement( $expElement );
390
	}
391
392
	/**
393
	 * Determine what kind of OWL property some SMW property should be exported as.
394
	 * The input is an SMWTypesValue object, a typeid string, or empty (use default)
395
	 * @todo An improved mechanism for selecting property types here is needed.
396
	 */
397 9
	static public function getOWLPropertyType( $type = '' ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
398 9
		if ( $type instanceof SMWDIWikiPage ) {
399
			$type = DataTypeRegistry::getInstance()->findTypeId( str_replace( '_', ' ', $type->getDBkey() ) );
400 9
		} elseif ( $type == false ) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $type of type string to the boolean false. If you are specifically checking for an empty string, consider using the more explicit === '' instead.
Loading history...
401
			$type = '';
402
		}
403
404
		switch ( $type ) {
405 9
			case '_anu':
406 2
			return 'AnnotationProperty';
407 9
			case '': case '_wpg': case '_wpp': case '_wpc': case '_wpf':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
408 6
			case '_uri': case '_ema': case '_tel': case '_rec': case '__typ':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
409 5
			case '__red': case '__spf': case '__spu':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
410 8
			return 'ObjectProperty';
411
			default:
412 5
			return 'DatatypeProperty';
413
		}
414
	}
415
416
	/**
417
	 * Get an ExpNsResource for a special property of SMW, or null if
418
	 * no resource is assigned to the given property key. The optional
419
	 * namespace is used to select the proper resource for properties that
420
	 * must take the type of the annotated object into account for some
421
	 * reason.
422
	 *
423
	 * @param $propertyKey string the Id of the special property
424
	 * @param $forNamespace integer the namespace of the page which has a value for this property
425
	 * @return ExpNsResource|null
426
	 */
427 22
	static public function getSpecialPropertyResource( $propertyKey, $forNamespace = NS_MAIN ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
428
		switch ( $propertyKey ) {
429 22
			case '_INST':
430 4
				return self::getSpecialNsResource( 'rdf', 'type' );
431 22
			case '_SUBC':
432 3
				return self::getSpecialNsResource( 'rdfs', 'subClassOf' );
433 22
			case '_CONC':
434
				return self::getSpecialNsResource( 'owl', 'equivalentClass' );
435 22
			case '_URI':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
436 3
				if ( $forNamespace == NS_CATEGORY || $forNamespace == SMW_NS_CONCEPT ) {
437
					return self::getSpecialNsResource( 'owl', 'equivalentClass' );
438 3
				} elseif ( $forNamespace == SMW_NS_PROPERTY ) {
439 1
					return self::getSpecialNsResource( 'owl', 'equivalentProperty' );
440
				} else {
441 2
					return self::getSpecialNsResource( 'owl', 'sameAs' );
442
				}
443 22
			case '_REDI':
444 3
				return self::getSpecialNsResource( 'swivt', 'redirectsTo' );
445 22
			case '_SUBP':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
446 1
				if ( $forNamespace == SMW_NS_PROPERTY ) {
447 1
					return self::getSpecialNsResource( 'rdfs', 'subPropertyOf' );
448
				} else {
449
					return null;
450
				}
451 22
			case '_MDAT':
452 11
				return self::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' );
453 22
			case '_CDAT':
454
				return self::getSpecialNsResource( 'swivt', 'wikiPageCreationDate' );
455 22
			case '_LEDT':
456
				return self::getSpecialNsResource( 'swivt', 'wikiPageLastEditor' );
457 22
			case '_NEWP':
458
				return self::getSpecialNsResource( 'swivt', 'wikiPageIsNew' );
459 22
			case '_SKEY':
460 21
				return self::getSpecialNsResource( 'swivt', 'wikiPageSortKey' );
461 12
			case '_TYPE':
462 7
				return self::getSpecialNsResource( 'swivt', 'type' );
463 11
			case '_IMPO':
464 2
				return self::getSpecialNsResource( 'swivt', 'specialImportedFrom' );
465
			default:
466 10
				return self::getSpecialNsResource( 'swivt', 'specialProperty' . $propertyKey );
467
		}
468
	}
469
470
471
	/**
472
	 * Create an ExpNsResource for some special element that belongs to
473
	 * a known vocabulary. An exception is generated when given parameters
474
	 * that do not fit any known vocabulary.
475
	 *
476
	 * @param $namespaceId string (e.g. "rdf")
477
	 * @param $localName string (e.g. "type")
478
	 * @return ExpNsResource
479
	 */
480 25
	static public function getSpecialNsResource( $namespaceId, $localName ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
481 25
		$namespace = self::getNamespaceUri( $namespaceId );
482 25
		if ( $namespace !== '' ) {
483 25
			return new ExpNsResource( $localName, $namespace, $namespaceId );
0 ignored issues
show
It seems like $namespace defined by self::getNamespaceUri($namespaceId) on line 481 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...
484
		} else {
485
			throw new InvalidArgumentException( "The vocabulary '$namespaceId' is not a known special vocabulary." );
486
		}
487
	}
488
489
	/**
490
	 * This function expands standard XML entities used in some generated
491
	 * URIs. Given a string with such entities, it returns a string with
492
	 * all entities properly replaced.
493
	 *
494
	 * @note The function SMWExporter::getInstance()->getNamespaceUri() is often more
495
	 * suitable. This XML-specific method might become obsolete.
496
	 *
497
	 * @param $uri string of the URI to be expanded
498
	 * @return string of the expanded URI
499
	 */
500 14
	static public function expandURI( $uri ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
501 14
		self::initBaseURIs();
502 14
		$uri = str_replace( array( '&wiki;', '&wikiurl;', '&property;', '&category;', '&owl;', '&rdf;', '&rdfs;', '&swivt;', '&export;' ),
503 14
		                    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#',
504 14
		                    self::$m_exporturl ),
505
		                    $uri );
506 14
		return $uri;
507
	}
508
509
	/**
510
	 * @return string
511
	 */
512
	public function decodeURI( $uri ) {
513
		return Escaper::decodeUri( $uri );
514
	}
515
516
	/**
517
	 * Get the URI of a standard namespace prefix used in SMW, or the empty
518
	 * string if the prefix is not known.
519
	 *
520
	 * @param $shortName string id (prefix) of the namespace
521
	 * @return string of the expanded URI
522
	 */
523 33
	static public function getNamespaceUri( $shortName ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
524 33
		self::initBaseURIs();
525
526 33
		if ( ( $uri = NamespaceUriFinder::getUri( $shortName ) ) !== false ) {
527 25
			return $uri;
528
		}
529
530
		switch ( $shortName ) {
531 31
			case 'wiki':
532 28
			return self::$m_ent_wiki;
533 23
			case 'wikiurl':
534 21
			return self::$m_ent_wikiurl;
535 23
			case 'property':
536 22
			return self::$m_ent_property;
537 8
			case 'category':
538 8
			return self::$m_ent_category;
539
			case 'export':
540
			return self::$m_exporturl;
541
			case 'owl':
542
			return 'http://www.w3.org/2002/07/owl#';
543
			case 'rdf':
544
			return 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
545
			case 'rdfs':
546
			return 'http://www.w3.org/2000/01/rdf-schema#';
547
			case 'swivt':
548
			return 'http://semantic-mediawiki.org/swivt/1.0#';
549
			case 'xsd':
550
			return 'http://www.w3.org/2001/XMLSchema#';
551
			default:
552
			return '';
553
		}
554
	}
555
556
	/**
557
	 * Create an SMWExpData container that encodes the ontology header for an
558
	 * SMW exported OWL file.
559
	 *
560
	 * @param string $ontologyuri specifying the URI of the ontology, possibly
561
	 * empty
562
	 *
563
	 * @return SMWExpData
564
	 */
565 14
	static public function getOntologyExpData( $ontologyuri ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
566 14
		$data = new SMWExpData( new SMWExpResource( $ontologyuri ) );
567 14
		$ed = self::getSpecialNsResource( 'owl', 'Ontology' );
568 14
		$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...
569 14
		$ed = new ExpLiteral( date( DATE_W3C ), 'http://www.w3.org/2001/XMLSchema#dateTime' );
570 14
		$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...
571 14
		$ed = new SMWExpResource( 'http://semantic-mediawiki.org/swivt/1.0' );
572 14
		$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...
573 14
		return $data;
574
	}
575
576
	/**
577
	 * @see DataItemToElementEncoder::mapDataItemToElement
578
	 */
579 26
	static public function getDataItemExpElement( SMWDataItem $dataItem ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
580 26
		return self::$dataItemToElementEncoder->mapDataItemToElement( $dataItem );
581
	}
582
583
	/**
584
	 * Create an SWMExpElement that encodes auxiliary data for representing
585
	 * values of the specified dataitem object in a simplified fashion.
586
	 * This is done for types of dataitems that are not supported very well
587
	 * in current systems, or that do not match a standard datatype in RDF.
588
	 * For example, time points (DITime) are encoded as numbers. The number
589
	 * can replace the actual time for all query and ordering purposes (the
590
	 * order in either case is linear and maps to the real number line).
591
	 * Only data retrieval should better use the real values to avoid that
592
	 * rounding errors lead to unfaithful recovery of data. Note that the
593
	 * helper values do not maintain any association with their original
594
	 * values -- they are a fully redundant alternative representation, not
595
	 * an additional piece of information for the main values. Even if
596
	 * decoding is difficult, they must be in one-to-one correspondence to
597
	 * the original value.
598
	 *
599
	 * For dataitems that do not have such a simplification, the method
600
	 * returns null.
601
	 *
602
	 * @note If a helper element is used, then it must be the same as
603
	 * getDataItemHelperExpElement( $dataItem->getSortKeyDataItem() ).
604
	 * Query conditions like ">" use sortkeys for values, and helper
605
	 * elements are always preferred in query answering.
606
	 *
607
	 * @param $dataItem SMWDataItem
608
	 * @return ExpElement|null
609
	 */
610 21
	static public function getDataItemHelperExpElement( SMWDataItem $dataItem ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
611
612 21
		if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) {
613 12
			return new ExpLiteral( (string)$dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#double', '', $dataItem );
614
		}
615
616 21
		if ( $dataItem->getDIType() == SMWDataItem::TYPE_GEO ) {
617
			return new ExpLiteral( (string)$dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#string', '', $dataItem );
618
		}
619
620 21
		return null;
621
	}
622
623
	/**
624
	 * Check whether the values of a given type of dataitem have helper
625
	 * values in the sense of SMWExporter::getInstance()->getDataItemHelperExpElement().
626
	 *
627
	 * @param DIProperty $property
628
	 *
629
	 * @return boolean
630
	 */
631 2
	static public function hasHelperExpElement( DIProperty $property ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
632 2
		return ( $property->findPropertyTypeID() === '_dat' || $property->findPropertyTypeID() === '_geo' ) || ( !$property->isUserDefined() && !self::hasSpecialPropertyResource( $property ) );
633
	}
634
635 1
	static protected function hasSpecialPropertyResource( DIProperty $property ) {
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
636 1
		return $property->getKey() === '_SKEY' ||
637 1
			$property->getKey() === '_INST' ||
638 1
			$property->getKey() === '_MDAT' ||
639 1
			$property->getKey() === '_SUBC' ||
640 1
			$property->getKey() === '_SUBP' ||
641 1
			$property->getKey() === '_TYPE' ||
642 1
			$property->getKey() === '_IMPO' ||
643 1
			$property->getKey() === '_URI';
644
	}
645
646
}
647