for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SESP\PropertyAnnotators;
use SMW\DIProperty;
use SMW\SemanticData;
use SMWDataItem as DataItem;
use SMWDIUri as DIUri;
use SESP\PropertyAnnotator;
use SESP\AppFactory;
use RuntimeException;
/**
* @private
* @ingroup SESP
*
* @license GNU GPL v2+
* @since 2.0
* @author mwjames
* @author rotsee
*/
class ShortUrlPropertyAnnotator implements PropertyAnnotator {
* @var AppFactory
private $appFactory;
* @param AppFactory $appFactory
public function __construct( AppFactory $appFactory ) {
$this->appFactory = $appFactory;
}
* {@inheritDoc}
public function isAnnotatorFor( DIProperty $property ) {
return $property->getKey() === '___SHORTURL' ;
public function addAnnotation( DIProperty $property, SemanticData $semanticData ) {
if ( !$this->hasShortUrlUtils() ) {
throw new RuntimeException( 'Class ShortUrlUtils is not available' );
$dataItem = null;
$title = $semanticData->getSubject()->getTitle();
if ( \ShortUrlUtils::needsShortUrl( $title ) ) {
$dataItem = new DIUri( 'http', $this->getUrlPrefix() . \ShortUrlUtils::encodeTitle( $title ), '', '' );
if ( $dataItem instanceof DataItem ) {
$semanticData->addPropertyObjectValue( $property, $dataItem );
protected function getUrlPrefix() {
$shortUrlPrefix = $this->appFactory->getOption( 'wgShortUrlPrefix', '' );
''
string
boolean
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);
if ( $shortUrlPrefix === '' ) {
return SpecialPage::getTitleFor( 'ShortUrl' )->getFullUrl() . '/';
return $shortUrlPrefix;
protected function hasShortUrlUtils() {
return class_exists( 'ShortUrlUtils' );
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: