@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | class OutputTest extends \PHPUnit_Framework_TestCase { |
17 | 17 | |
18 | 18 | public function testCanConstruct() { |
19 | - $this->assertInstanceOf( '\SFS\Output', new Output() ); |
|
19 | + $this->assertInstanceOf('\SFS\Output', new Output()); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function testAddToHeadItem() { |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | $data['Foo'] = 'Bar'; |
25 | 25 | $data['Spam'] = 'Eggs'; |
26 | 26 | |
27 | - $ret = Output::addToHeadItem( $data ); |
|
27 | + $ret = Output::addToHeadItem($data); |
|
28 | 28 | |
29 | - $this->assertArrayHasKey( 'Foo', $ret ); |
|
30 | - $this->assertArrayHasKey( 'Spam', $ret ); |
|
29 | + $this->assertArrayHasKey('Foo', $ret); |
|
30 | + $this->assertArrayHasKey('Spam', $ret); |
|
31 | 31 | } |
32 | 32 | } |
@@ -1,23 +1,23 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( PHP_SAPI !== 'cli' ) { |
|
4 | - die( 'Not an entry point' ); |
|
3 | +if (PHP_SAPI !== 'cli') { |
|
4 | + die('Not an entry point'); |
|
5 | 5 | } |
6 | 6 | |
7 | -error_reporting( E_ALL | E_STRICT ); |
|
8 | -date_default_timezone_set( 'UTC' ); |
|
9 | -ini_set( 'display_errors', 1 ); |
|
7 | +error_reporting(E_ALL | E_STRICT); |
|
8 | +date_default_timezone_set('UTC'); |
|
9 | +ini_set('display_errors', 1); |
|
10 | 10 | |
11 | 11 | global $IP; |
12 | 12 | |
13 | 13 | //if ( !is_readable( $autoloaderClassPath = __DIR__ . '/../../SemanticMediaWiki/tests/autoloader.php' ) ) { |
14 | -if ( !is_readable( $autoloaderClassPath = $IP . '/extensions/SemanticMediaWiki/tests/autoloader.php' ) ) { |
|
15 | - die( "\nThe Semantic MediaWiki test autoloader is not available\n" ); |
|
14 | +if (!is_readable($autoloaderClassPath = $IP.'/extensions/SemanticMediaWiki/tests/autoloader.php')) { |
|
15 | + die("\nThe Semantic MediaWiki test autoloader is not available\n"); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | // if ( !class_exists( 'SemanticFormsSelect' ) || ( $version = SemanticFormsSelect::getVersion() ) === null ) { |
19 | -if ( ExtensionRegistry::getInstance()->isLoaded( 'SemanticFormsSelect' ) ) { |
|
20 | - die( "\nSemantic Forms Select is not available, please check your Composer or LocalSettings.\n" ); |
|
19 | +if (ExtensionRegistry::getInstance()->isLoaded('SemanticFormsSelect')) { |
|
20 | + die("\nSemantic Forms Select is not available, please check your Composer or LocalSettings.\n"); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | //print sprintf( "\n%-20s%s\n", "Semantic Forms Select: ", ExtensionRegistry::getInstance()->isLoaded( 'SemanticFormsSelect' ) ); |
@@ -26,4 +26,4 @@ discard block |
||
26 | 26 | $autoloader = require $autoloaderClassPath; |
27 | 27 | //$autoloader->addPsr4( 'SFS\\Tests\\', __DIR__ . '/phpunit/Unit' ); |
28 | 28 | //$autoloader->addPsr4( 'SFS\\Tests\\Integration\\', __DIR__ . '/phpunit/Integration' ); |
29 | -unset( $autoloader ); |
|
29 | +unset($autoloader); |
@@ -21,43 +21,43 @@ |
||
21 | 21 | |
22 | 22 | public function testCanConstruct() { |
23 | 23 | |
24 | - $parser = $this->getMockBuilder( '\Parser' ) |
|
24 | + $parser = $this->getMockBuilder('\Parser') |
|
25 | 25 | ->disableOriginalConstructor() |
26 | 26 | ->getMock(); |
27 | 27 | |
28 | 28 | $this->assertInstanceOf( |
29 | 29 | '\SFS\ApiRequestProcessor', |
30 | - new ApiRequestProcessor( $parser ) |
|
30 | + new ApiRequestProcessor($parser) |
|
31 | 31 | ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | public function testMissingParametersThrowsException() { |
35 | 35 | |
36 | - $parser = $this->getMockBuilder( '\Parser' ) |
|
36 | + $parser = $this->getMockBuilder('\Parser') |
|
37 | 37 | ->disableOriginalConstructor() |
38 | 38 | ->getMock(); |
39 | 39 | |
40 | - $instance = new ApiRequestProcessor( $parser ); |
|
40 | + $instance = new ApiRequestProcessor($parser); |
|
41 | 41 | |
42 | 42 | $parameters = array(); |
43 | 43 | |
44 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
45 | - $instance->getJsonDecodedResultValuesForRequestParameters( $parameters ); |
|
44 | + $this->setExpectedException('InvalidArgumentException'); |
|
45 | + $instance->getJsonDecodedResultValuesForRequestParameters($parameters); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function testJsonResultValuesFromRequestParameters() { |
49 | 49 | |
50 | - $parser = $this->getMockBuilder( '\Parser' ) |
|
50 | + $parser = $this->getMockBuilder('\Parser') |
|
51 | 51 | ->disableOriginalConstructor() |
52 | 52 | ->getMock(); |
53 | 53 | |
54 | - $instance = new ApiRequestProcessor( $parser ); |
|
54 | + $instance = new ApiRequestProcessor($parser); |
|
55 | 55 | |
56 | - $parameters = array( 'query' => 'foo', 'sep' => ',' ); |
|
56 | + $parameters = array('query' => 'foo', 'sep' => ','); |
|
57 | 57 | |
58 | 58 | $this->assertInternalType( |
59 | 59 | 'object', |
60 | - $instance->getJsonDecodedResultValuesForRequestParameters( $parameters ) |
|
60 | + $instance->getJsonDecodedResultValuesForRequestParameters($parameters) |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function testCanConstruct() { |
23 | 23 | |
24 | - $apiMain = new ApiMain( $this->newRequestContext( array() ), true ); |
|
24 | + $apiMain = new ApiMain($this->newRequestContext(array()), true); |
|
25 | 25 | |
26 | 26 | $instance = new ApiSemanticFormsSelect( |
27 | 27 | $apiMain, |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | 'sep' => ',' |
44 | 44 | ); |
45 | 45 | |
46 | - $apiMain = new ApiMain( $this->newRequestContext( $parameters ), true ); |
|
46 | + $apiMain = new ApiMain($this->newRequestContext($parameters), true); |
|
47 | 47 | |
48 | 48 | $instance = new ApiSemanticFormsSelect( |
49 | 49 | $apiMain, |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - private function newRequestContext( $request = array() ) { |
|
58 | + private function newRequestContext($request = array()) { |
|
59 | 59 | |
60 | 60 | $context = new RequestContext(); |
61 | 61 | |
62 | - if ( $request instanceof WebRequest ) { |
|
63 | - $context->setRequest( $request ); |
|
62 | + if ($request instanceof WebRequest) { |
|
63 | + $context->setRequest($request); |
|
64 | 64 | } else { |
65 | - $context->setRequest( new FauxRequest( $request, true ) ); |
|
65 | + $context->setRequest(new FauxRequest($request, true)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return $context; |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | |
18 | 18 | public function testCanConstruct() { |
19 | 19 | |
20 | - $parser = $this->getMockBuilder( '\Parser' ) |
|
20 | + $parser = $this->getMockBuilder('\Parser') |
|
21 | 21 | ->disableOriginalConstructor() |
22 | 22 | ->getMock(); |
23 | 23 | |
24 | 24 | $this->assertInstanceOf( |
25 | 25 | '\SFS\SemanticFormsSelect', |
26 | - new SemanticFormsSelect( $parser ) |
|
26 | + new SemanticFormsSelect($parser) |
|
27 | 27 | ); |
28 | 28 | } |
29 | 29 | |
@@ -41,23 +41,23 @@ discard block |
||
41 | 41 | 'is_list' => true |
42 | 42 | ); |
43 | 43 | |
44 | - $parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
|
44 | + $parserOutput = $this->getMockBuilder('\ParserOutput') |
|
45 | 45 | ->disableOriginalConstructor() |
46 | 46 | ->getMock(); |
47 | 47 | |
48 | - $parser = $this->getMockBuilder( '\Parser' ) |
|
48 | + $parser = $this->getMockBuilder('\Parser') |
|
49 | 49 | ->disableOriginalConstructor() |
50 | 50 | ->getMock(); |
51 | 51 | |
52 | - $parser->expects( $this->any() ) |
|
53 | - ->method( 'getOutput' ) |
|
54 | - ->will( $this->returnValue( $parserOutput ) ); |
|
52 | + $parser->expects($this->any()) |
|
53 | + ->method('getOutput') |
|
54 | + ->will($this->returnValue($parserOutput)); |
|
55 | 55 | |
56 | - $instance = new SemanticFormsSelect( $parser ); |
|
56 | + $instance = new SemanticFormsSelect($parser); |
|
57 | 57 | |
58 | 58 | $this->assertInternalType( |
59 | 59 | 'string', |
60 | - $instance->select( $value, $inputName, $isMandatory, $isDisabled, $otherArgs ) |
|
60 | + $instance->select($value, $inputName, $isMandatory, $isDisabled, $otherArgs) |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 |
@@ -14,14 +14,14 @@ |
||
14 | 14 | * @param $parser Parser |
15 | 15 | * @return bool |
16 | 16 | */ |
17 | - public static function onSemanticFormsSelectSetup ( & $parser ) { |
|
17 | + public static function onSemanticFormsSelectSetup(& $parser) { |
|
18 | 18 | |
19 | - if ( !defined( 'PF_VERSION' ) ) { |
|
20 | - die( '<b>Error:</b><a href="https://github.com/SemanticMediaWiki/SemanticFormsSelect/">Semantic Forms Select</a> requires the <a href="https://www.mediawiki.org/wiki/Extension:PageForms">Page Forms</a> extension. Please install and activate this extension first.' ); |
|
19 | + if (!defined('PF_VERSION')) { |
|
20 | + die('<b>Error:</b><a href="https://github.com/SemanticMediaWiki/SemanticFormsSelect/">Semantic Forms Select</a> requires the <a href="https://www.mediawiki.org/wiki/Extension:PageForms">Page Forms</a> extension. Please install and activate this extension first.'); |
|
21 | 21 | } |
22 | 22 | |
23 | - if ( isset( $GLOBALS['wgPageFormsFormPrinter'] )) { |
|
24 | - $GLOBALS['wgPageFormsFormPrinter']->registerInputType( '\SFS\SemanticFormsSelectInput' ); |
|
23 | + if (isset($GLOBALS['wgPageFormsFormPrinter'])) { |
|
24 | + $GLOBALS['wgPageFormsFormPrinter']->registerInputType('\SFS\SemanticFormsSelectInput'); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | return true; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param array $data |
27 | 27 | */ |
28 | - public static function addToHeadItem( Array $data = [] ) { |
|
28 | + public static function addToHeadItem(Array $data = []) { |
|
29 | 29 | return self::$headItems[] = $data; |
30 | 30 | } |
31 | 31 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // to be used in JS like: |
40 | 40 | // var SFSelect_fobjs = $.parseJSON( mw.config.get( 'sf_select' ) ); |
41 | - $wgOut->addJsConfigVars('sf_select', json_encode( self::$headItems )); |
|
41 | + $wgOut->addJsConfigVars('sf_select', json_encode(self::$headItems)); |
|
42 | 42 | |
43 | 43 | //self::$resourceModules = array(); |
44 | 44 | //self::$headItems = array(); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param Parser $parser |
34 | 34 | */ |
35 | - public function __construct( Parser $parser ) { |
|
35 | + public function __construct(Parser $parser) { |
|
36 | 36 | $this->parser = $parser; |
37 | 37 | } |
38 | 38 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param boolean $debugFlag |
43 | 43 | */ |
44 | - public function setDebugFlag( $debugFlag ) { |
|
44 | + public function setDebugFlag($debugFlag) { |
|
45 | 45 | $this->debugFlag = $debugFlag; |
46 | 46 | } |
47 | 47 | |
@@ -52,91 +52,91 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public function getJsonDecodedResultValuesForRequestParameters( array $parameters ) { |
|
55 | + public function getJsonDecodedResultValuesForRequestParameters(array $parameters) { |
|
56 | 56 | |
57 | - if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) { |
|
58 | - throw new InvalidArgumentException( 'Missing an query parameter' ); |
|
57 | + if (!isset($parameters['query']) || !isset($parameters['sep'])) { |
|
58 | + throw new InvalidArgumentException('Missing an query parameter'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $this->parser->firstCallInit(); |
62 | 62 | $json = array(); |
63 | 63 | |
64 | - if ( isset( $parameters['approach'] ) && $parameters['approach'] == 'smw' ) { |
|
65 | - $json = $this->doProcessQueryFor( $parameters['query'], $parameters['sep'] ); |
|
64 | + if (isset($parameters['approach']) && $parameters['approach'] == 'smw') { |
|
65 | + $json = $this->doProcessQueryFor($parameters['query'], $parameters['sep']); |
|
66 | 66 | } else { |
67 | - $json = $this->doProcessFunctionFor( $parameters['query'], $parameters['sep'] ); |
|
67 | + $json = $this->doProcessFunctionFor($parameters['query'], $parameters['sep']); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // I have no idea why we first encode and and then decode here?? |
71 | 71 | |
72 | - return json_decode( $json ); |
|
72 | + return json_decode($json); |
|
73 | 73 | } |
74 | 74 | |
75 | - private function doProcessQueryFor( $query, $sep = "," ) { |
|
75 | + private function doProcessQueryFor($query, $sep = ",") { |
|
76 | 76 | |
77 | 77 | $query = str_replace( |
78 | - array( "<", ">", "sep=;" ), |
|
79 | - array( "<", ">", "sep={$sep};" ), |
|
78 | + array("<", ">", "sep=;"), |
|
79 | + array("<", ">", "sep={$sep};"), |
|
80 | 80 | $query |
81 | 81 | ); |
82 | 82 | |
83 | - $params = explode( ";", $query ); |
|
84 | - $f = str_replace( ";", "|", $params[0] ); |
|
83 | + $params = explode(";", $query); |
|
84 | + $f = str_replace(";", "|", $params[0]); |
|
85 | 85 | |
86 | - $params[0] = $this->parser->replaceVariables( $f ); |
|
86 | + $params[0] = $this->parser->replaceVariables($f); |
|
87 | 87 | |
88 | - if ( $this->debugFlag ) { |
|
89 | - error_log( implode( "|", $params ) ); |
|
88 | + if ($this->debugFlag) { |
|
89 | + error_log(implode("|", $params)); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $values = $this->getFormattedValuesFrom( |
93 | 93 | $sep, |
94 | - QueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI ) |
|
94 | + QueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI) |
|
95 | 95 | ); |
96 | 96 | |
97 | - return json_encode( array( |
|
97 | + return json_encode(array( |
|
98 | 98 | "values" => $values, |
99 | - "count" => count( $values ) |
|
100 | - ) ); |
|
99 | + "count" => count($values) |
|
100 | + )); |
|
101 | 101 | } |
102 | 102 | |
103 | - private function doProcessFunctionFor( $query, $sep = "," ) { |
|
103 | + private function doProcessFunctionFor($query, $sep = ",") { |
|
104 | 104 | |
105 | 105 | $query = str_replace( |
106 | - array( "<", ">", "sep=;" ), |
|
107 | - array( "<", ">", "sep={$sep};" ), |
|
106 | + array("<", ">", "sep=;"), |
|
107 | + array("<", ">", "sep={$sep};"), |
|
108 | 108 | $query |
109 | 109 | ); |
110 | 110 | |
111 | - $f = str_replace( ";", "|", $query ); |
|
111 | + $f = str_replace(";", "|", $query); |
|
112 | 112 | |
113 | - if ( $this->debugFlag ) { |
|
114 | - error_log( $f ); |
|
113 | + if ($this->debugFlag) { |
|
114 | + error_log($f); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $values = $this->getFormattedValuesFrom( |
118 | 118 | $sep, |
119 | - $this->parser->replaceVariables( $f ) |
|
119 | + $this->parser->replaceVariables($f) |
|
120 | 120 | ); |
121 | 121 | |
122 | - return json_encode( array( |
|
122 | + return json_encode(array( |
|
123 | 123 | "values" => $values, |
124 | - "count" => count( $values ) |
|
125 | - ) ); |
|
124 | + "count" => count($values) |
|
125 | + )); |
|
126 | 126 | } |
127 | 127 | |
128 | - private function getFormattedValuesFrom( $sep, $values ) { |
|
128 | + private function getFormattedValuesFrom($sep, $values) { |
|
129 | 129 | |
130 | - if ( strpos( $values, $sep ) === false ) { |
|
131 | - return array( $values ); |
|
130 | + if (strpos($values, $sep) === false) { |
|
131 | + return array($values); |
|
132 | 132 | } |
133 | 133 | |
134 | - $values = explode( $sep, $values ); |
|
135 | - $values = array_map( "trim", $values ); |
|
136 | - $values = array_unique( $values ); |
|
134 | + $values = explode($sep, $values); |
|
135 | + $values = array_map("trim", $values); |
|
136 | + $values = array_unique($values); |
|
137 | 137 | |
138 | - sort( $values ); |
|
139 | - array_unshift( $values, "" ); |
|
138 | + sort($values); |
|
139 | + array_unshift($values, ""); |
|
140 | 140 | |
141 | 141 | return $values; |
142 | 142 | } |
@@ -24,22 +24,22 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function execute() { |
26 | 26 | |
27 | - $parser = new Parser( $GLOBALS['wgParserConf'] ); |
|
28 | - $parser->setTitle( Title::newFromText( 'NO TITLE' ) ); |
|
27 | + $parser = new Parser($GLOBALS['wgParserConf']); |
|
28 | + $parser->setTitle(Title::newFromText('NO TITLE')); |
|
29 | 29 | $parser->mOptions = new ParserOptions(); |
30 | 30 | $parser->mOutput = new ParserOutput(); |
31 | 31 | |
32 | - $apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor( $parser ); |
|
33 | - $apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] ); |
|
32 | + $apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor($parser); |
|
33 | + $apiRequestProcessor->setDebugFlag($GLOBALS['wgSF_Select_debug']); |
|
34 | 34 | |
35 | 35 | $resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters( |
36 | 36 | $this->extractRequestParams() |
37 | 37 | ); |
38 | 38 | |
39 | 39 | $result = $this->getResult(); |
40 | - $result->setIndexedTagName( $resultValues->values, 'value' ); |
|
41 | - $result->addValue( $this->getModuleName(), 'values', $resultValues->values ); |
|
42 | - $result->addValue( $this->getModuleName(), 'count', $resultValues->count ); |
|
40 | + $result->setIndexedTagName($resultValues->values, 'value'); |
|
41 | + $result->addValue($this->getModuleName(), 'values', $resultValues->values); |
|
42 | + $result->addValue($this->getModuleName(), 'count', $resultValues->count); |
|
43 | 43 | |
44 | 44 | return true; |
45 | 45 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @see ApiBase::getVersion |
88 | 88 | */ |
89 | 89 | public function getVersion() { |
90 | - return __CLASS__ . ': 1.1'; |
|
90 | + return __CLASS__.': 1.1'; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | } |