phpcs: Always use long array syntax

Most of the code in RSS-Bridge uses the long array syntax.
This commit adds a check to enforce using this syntax over
the short array syntax.

All failures have been fixed.
This commit is contained in:
logmanoriginal 2019-11-01 18:06:38 +01:00
parent 1df3598a74
commit 3bc8c9468a
21 changed files with 66 additions and 60 deletions

View file

@ -134,11 +134,11 @@ EOT;
// data-asin="B00WTHJ5SU" data-asin-price="14.99" data-asin-shipping="0" // data-asin="B00WTHJ5SU" data-asin-price="14.99" data-asin-shipping="0"
// data-asin-currency-code="USD" data-substitute-count="-1" ... /> // data-asin-currency-code="USD" data-substitute-count="-1" ... />
if ($asinData) { if ($asinData) {
return [ return array(
'price' => $asinData->getAttribute('data-asin-price'), 'price' => $asinData->getAttribute('data-asin-price'),
'currency' => $asinData->getAttribute('data-asin-currency-code'), 'currency' => $asinData->getAttribute('data-asin-currency-code'),
'shipping' => $asinData->getAttribute('data-asin-shipping') 'shipping' => $asinData->getAttribute('data-asin-shipping')
]; );
} }
return false; return false;
@ -150,11 +150,11 @@ EOT;
preg_match('/^\s*([A-Z]{3}|£|\$)\s?([\d.,]+)\s*$/', $priceDiv->plaintext, $matches); preg_match('/^\s*([A-Z]{3}|£|\$)\s?([\d.,]+)\s*$/', $priceDiv->plaintext, $matches);
if (count($matches) === 3) { if (count($matches) === 3) {
return [ return array(
'price' => $matches[2], 'price' => $matches[2],
'currency' => $matches[1], 'currency' => $matches[1],
'shipping' => '0' 'shipping' => '0'
]; );
} }
return false; return false;

View file

@ -5,19 +5,19 @@ class AppleMusicBridge extends BridgeAbstract {
const URI = 'https://www.apple.com'; const URI = 'https://www.apple.com';
const DESCRIPTION = 'Fetches the latest releases from an artist'; const DESCRIPTION = 'Fetches the latest releases from an artist';
const MAINTAINER = 'Limero'; const MAINTAINER = 'Limero';
const PARAMETERS = [[ const PARAMETERS = array(array(
'url' => [ 'url' => array(
'name' => 'Artist URL', 'name' => 'Artist URL',
'exampleValue' => 'https://itunes.apple.com/us/artist/dunderpatrullen/329796274', 'exampleValue' => 'https://itunes.apple.com/us/artist/dunderpatrullen/329796274',
'required' => true, 'required' => true,
], ),
'imgSize' => [ 'imgSize' => array(
'name' => 'Image size for thumbnails (in px)', 'name' => 'Image size for thumbnails (in px)',
'type' => 'number', 'type' => 'number',
'defaultValue' => 512, 'defaultValue' => 512,
'required' => true, 'required' => true,
] )
]]; ));
const CACHE_TIMEOUT = 21600; // 6 hours const CACHE_TIMEOUT = 21600; // 6 hours
public function collectData() { public function collectData() {
@ -36,12 +36,12 @@ class AppleMusicBridge extends BridgeAbstract {
// Loop through each object // Loop through each object
foreach ($json->included as $obj) { foreach ($json->included as $obj) {
if ($obj->type === 'lockup/album') { if ($obj->type === 'lockup/album') {
$this->items[] = [ $this->items[] = array(
'title' => $obj->attributes->artistName . ' - ' . $obj->attributes->name, 'title' => $obj->attributes->artistName . ' - ' . $obj->attributes->name,
'uri' => $obj->attributes->url, 'uri' => $obj->attributes->url,
'timestamp' => $obj->attributes->releaseDate, 'timestamp' => $obj->attributes->releaseDate,
'enclosures' => $obj->relationships->artwork->data->id, 'enclosures' => $obj->relationships->artwork->data->id,
]; );
} elseif ($obj->type === 'image') { } elseif ($obj->type === 'image') {
$images[$obj->id] = $obj->attributes->url; $images[$obj->id] = $obj->attributes->url;
} }
@ -49,9 +49,9 @@ class AppleMusicBridge extends BridgeAbstract {
// Add the images to each item // Add the images to each item
foreach ($this->items as &$item) { foreach ($this->items as &$item) {
$item['enclosures'] = [ $item['enclosures'] = array(
str_replace('{w}x{h}bb.{f}', $imgSize . 'x0w.jpg', $images[$item['enclosures']]), str_replace('{w}x{h}bb.{f}', $imgSize . 'x0w.jpg', $images[$item['enclosures']]),
]; );
} }
// Sort the order to put the latest albums first // Sort the order to put the latest albums first

View file

@ -77,7 +77,7 @@ class AtmoNouvelleAquitaineBridge extends BridgeAbstract {
private function getLegendIndexes() { private function getLegendIndexes() {
$rawIndexes = $this->dom->find('.prevision-legend .prevision-legend-label'); $rawIndexes = $this->dom->find('.prevision-legend .prevision-legend-label');
$indexes = []; $indexes = array();
for ($i = 0; $i < count($rawIndexes); $i++) { for ($i = 0; $i < count($rawIndexes); $i++) {
if ($rawIndexes[$i]->hasAttribute('data-color')) { if ($rawIndexes[$i]->hasAttribute('data-color')) {
$indexes[$rawIndexes[$i]->getAttribute('data-color')] = $rawIndexes[$i]->innertext; $indexes[$rawIndexes[$i]->getAttribute('data-color')] = $rawIndexes[$i]->innertext;

View file

@ -92,7 +92,7 @@ class BingSearchBridge extends BridgeAbstract
or returnServerError('Could not request ' . self::NAME); or returnServerError('Could not request ' . self::NAME);
$sizeKey = $this->getInput('image_size'); $sizeKey = $this->getInput('image_size');
$items = []; $items = array();
foreach ($html->find('a.iusc') as $element) { foreach ($html->find('a.iusc') as $element) {
$data = json_decode(htmlspecialchars_decode($element->getAttribute('m')), true); $data = json_decode(htmlspecialchars_decode($element->getAttribute('m')), true);

View file

@ -23,8 +23,8 @@ class CNETFranceBridge extends FeedExpander
) )
); );
private $bannedTitle = []; private $bannedTitle = array();
private $bannedURL = []; private $bannedURL = array();
public function collectData() public function collectData()
{ {

View file

@ -22,7 +22,7 @@ class CachetBridge extends BridgeAbstract {
); );
const CACHE_TIMEOUT = 300; const CACHE_TIMEOUT = 300;
private $componentCache = []; private $componentCache = array();
public function getURI() { public function getURI() {
return $this->getInput('host') === null ? 'https://cachethq.io/' : $this->getInput('host'); return $this->getInput('host') === null ? 'https://cachethq.io/' : $this->getInput('host');
@ -114,13 +114,13 @@ class CachetBridge extends BridgeAbstract {
$uidOrig = $permalink . $incident->created_at; $uidOrig = $permalink . $incident->created_at;
$uid = hash('sha512', $uidOrig); $uid = hash('sha512', $uidOrig);
$timestamp = strtotime($incident->created_at); $timestamp = strtotime($incident->created_at);
$categories = []; $categories = array();
$categories[] = $incident->human_status; $categories[] = $incident->human_status;
if ($componentName !== '') { if ($componentName !== '') {
$categories[] = $componentName; $categories[] = $componentName;
} }
$item = []; $item = array();
$item['uri'] = $permalink; $item['uri'] = $permalink;
$item['title'] = $title; $item['title'] = $title;
$item['timestamp'] = $timestamp; $item['timestamp'] = $timestamp;

View file

@ -10,20 +10,20 @@ class ContainerLinuxReleasesBridge extends BridgeAbstract {
const BETA = 'beta'; const BETA = 'beta';
const ALPHA = 'alpha'; const ALPHA = 'alpha';
const PARAMETERS = [ const PARAMETERS = array(
[ array(
'channel' => [ 'channel' => array(
'name' => 'Release Channel', 'name' => 'Release Channel',
'type' => 'list', 'type' => 'list',
'defaultValue' => self::STABLE, 'defaultValue' => self::STABLE,
'values' => [ 'values' => array(
'Stable' => self::STABLE, 'Stable' => self::STABLE,
'Beta' => self::BETA, 'Beta' => self::BETA,
'Alpha' => self::ALPHA, 'Alpha' => self::ALPHA,
], ),
] )
] )
]; );
private function getReleaseFeed($jsonUrl) { private function getReleaseFeed($jsonUrl) {
$json = getContents($jsonUrl) $json = getContents($jsonUrl)
@ -39,7 +39,7 @@ class ContainerLinuxReleasesBridge extends BridgeAbstract {
$data = $this->getReleaseFeed($this->getJsonUri()); $data = $this->getReleaseFeed($this->getJsonUri());
foreach ($data as $releaseVersion => $release) { foreach ($data as $releaseVersion => $release) {
$item = []; $item = array();
$item['uri'] = "https://coreos.com/releases/#$releaseVersion"; $item['uri'] = "https://coreos.com/releases/#$releaseVersion";
$item['title'] = $releaseVersion; $item['title'] = $releaseVersion;

View file

@ -19,7 +19,7 @@ favicon-63b2904a073c89b52b19aa08cebc16a154bcf83fee8ecc6439968b1e6db569c7.ico';
$json = $this->loadEmbeddedJsonData($html); $json = $this->loadEmbeddedJsonData($html);
foreach($html->find('li[id^="screenshot-"]') as $shot) { foreach($html->find('li[id^="screenshot-"]') as $shot) {
$item = []; $item = array();
$additional_data = $this->findJsonForShot($shot, $json); $additional_data = $this->findJsonForShot($shot, $json);
if ($additional_data === null) { if ($additional_data === null) {
@ -38,14 +38,14 @@ favicon-63b2904a073c89b52b19aa08cebc16a154bcf83fee8ecc6439968b1e6db569c7.ico';
$preview_path = $shot->find('picture source', 0)->attr['srcset']; $preview_path = $shot->find('picture source', 0)->attr['srcset'];
$item['content'] .= $this->getImageTag($preview_path, $item['title']); $item['content'] .= $this->getImageTag($preview_path, $item['title']);
$item['enclosures'] = [$this->getFullSizeImagePath($preview_path)]; $item['enclosures'] = array($this->getFullSizeImagePath($preview_path));
$this->items[] = $item; $this->items[] = $item;
} }
} }
private function loadEmbeddedJsonData($html){ private function loadEmbeddedJsonData($html){
$json = []; $json = array();
$scripts = $html->find('script'); $scripts = $html->find('script');
foreach($scripts as $script) { foreach($scripts as $script) {

View file

@ -40,7 +40,7 @@ class EconomistBridge extends BridgeAbstract {
if ($nextprev) if ($nextprev)
$nextprev->outertext = ''; $nextprev->outertext = '';
$section = [ $article->find('h3[itemprop="articleSection"]', 0)->plaintext ]; $section = array( $article->find('h3[itemprop="articleSection"]', 0)->plaintext );
$item = array(); $item = array();
$item['title'] = $header->find('span', 0)->innertext . ': ' $item['title'] = $header->find('span', 0)->innertext . ': '

View file

@ -95,7 +95,7 @@ class ElloBridge extends BridgeAbstract {
private function getEnclosures($post, $postData) { private function getEnclosures($post, $postData) {
$assets = []; $assets = array();
foreach($post->links->assets as $asset) { foreach($post->links->assets as $asset) {
foreach($postData->linked->assets as $assetLink) { foreach($postData->linked->assets as $assetLink) {
if($asset == $assetLink->id) { if($asset == $assetLink->id) {
@ -124,7 +124,7 @@ class ElloBridge extends BridgeAbstract {
$cacheFac->setWorkingDir(PATH_LIB_CACHES); $cacheFac->setWorkingDir(PATH_LIB_CACHES);
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type')); $cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey(['key']); $cache->setKey(array('key'));
$key = $cache->loadData(); $key = $cache->loadData();
if($key == null) { if($key == null) {

View file

@ -112,7 +112,7 @@ EOD
//Decode images //Decode images
$imagecleaned = preg_replace_callback('/<i [^>]* style="[^"]*url\(\'(.*?)\'\).*?><\/i>/m', function ($matches) { $imagecleaned = preg_replace_callback('/<i [^>]* style="[^"]*url\(\'(.*?)\'\).*?><\/i>/m', function ($matches) {
return "<img src='" . str_replace(['\\3a ', '\\3d ', '\\26 '], [':', '=', '&'], $matches[1]) . "' />"; return "<img src='" . str_replace(array('\\3a ', '\\3d ', '\\26 '), array(':', '=', '&'), $matches[1]) . "' />";
}, $content); }, $content);
$content = str_get_html($imagecleaned); $content = str_get_html($imagecleaned);
@ -164,7 +164,11 @@ EOD
$content = preg_replace('/<img src=\'.*?safe_image\.php.*?\' \/>/m', '', $content); $content = preg_replace('/<img src=\'.*?safe_image\.php.*?\' \/>/m', '', $content);
//Remove the double section tags //Remove the double section tags
$content = str_replace(['<section><section>', '</section></section>'], ['<section>', '</section>'], $content); $content = str_replace(
array('<section><section>', '</section></section>'),
array('<section>', '</section>'),
$content
);
//Move the section tag link upper, if it is down //Move the section tag link upper, if it is down
$content = str_get_html($content); $content = str_get_html($content);

View file

@ -72,7 +72,7 @@ class HDWallpapersBridge extends BridgeAbstract {
public function getName(){ public function getName(){
if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))) { if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))) {
return 'HDWallpapers - ' return 'HDWallpapers - '
. str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')) . str_replace(array('__', '_'), array(' & ', ' '), $this->getInput('c'))
. ' [' . ' ['
. $this->getInput('r') . $this->getInput('r')
. ']'; . ']';

View file

@ -58,7 +58,7 @@ class InstagramBridge extends BridgeAbstract {
$cacheFac->setWorkingDir(PATH_LIB_CACHES); $cacheFac->setWorkingDir(PATH_LIB_CACHES);
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type')); $cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
$cache->setScope(get_called_class()); $cache->setScope(get_called_class());
$cache->setKey([$username]); $cache->setKey(array($username));
$key = $cache->loadData(); $key = $cache->loadData();
if($key == null) { if($key == null) {
@ -178,7 +178,7 @@ class InstagramBridge extends BridgeAbstract {
$caption = ''; $caption = '';
} }
$enclosures = [$mediaInfo->display_url]; $enclosures = array($mediaInfo->display_url);
$content = '<img src="' . htmlentities($mediaInfo->display_url) . '" alt="' . $caption . '" />'; $content = '<img src="' . htmlentities($mediaInfo->display_url) . '" alt="' . $caption . '" />';
foreach($mediaInfo->edge_sidecar_to_children->edges as $media) { foreach($mediaInfo->edge_sidecar_to_children->edges as $media) {
@ -189,7 +189,7 @@ class InstagramBridge extends BridgeAbstract {
} }
} }
return [$content, $enclosures]; return array($content, $enclosures);
} }

View file

@ -431,11 +431,11 @@ class LeBonCoinBridge extends BridgeAbstract {
); );
if($this->getInput('region') != '') { if($this->getInput('region') != '') {
$requestJson->filters->location['regions'] = [$this->getInput('region')]; $requestJson->filters->location['regions'] = array($this->getInput('region'));
} }
if($this->getInput('department') != '') { if($this->getInput('department') != '') {
$requestJson->filters->location['departments'] = [$this->getInput('department')]; $requestJson->filters->location['departments'] = array($this->getInput('department'));
} }
if($this->getInput('cities') != '') { if($this->getInput('cities') != '') {
@ -467,7 +467,7 @@ class LeBonCoinBridge extends BridgeAbstract {
} }
if($this->getInput('estate') != '') { if($this->getInput('estate') != '') {
$requestJson->filters->enums['real_estate_type'] = [$this->getInput('estate')]; $requestJson->filters->enums['real_estate_type'] = array($this->getInput('estate'));
} }
if($this->getInput('roomsmin') != '' if($this->getInput('roomsmin') != ''
@ -526,7 +526,7 @@ class LeBonCoinBridge extends BridgeAbstract {
} }
if($this->getInput('fuel') != '') { if($this->getInput('fuel') != '') {
$requestJson->filters->enums['fuel'] = [$this->getInput('fuel')]; $requestJson->filters->enums['fuel'] = array($this->getInput('fuel'));
} }
$requestJson->limit = 30; $requestJson->limit = 30;

View file

@ -19,7 +19,7 @@ class N26Bridge extends BridgeAbstract
or returnServerError('Error while downloading the website content'); or returnServerError('Error while downloading the website content');
foreach($html->find('div[class="ag ah ai aj bs bt dx ea fo gx ie if ih ii ij ik s"]') as $article) { foreach($html->find('div[class="ag ah ai aj bs bt dx ea fo gx ie if ih ii ij ik s"]') as $article) {
$item = []; $item = array();
$item['uri'] = self::URI . $article->find('h2 a', 0)->href; $item['uri'] = self::URI . $article->find('h2 a', 0)->href;
$item['title'] = $article->find('h2 a', 0)->plaintext; $item['title'] = $article->find('h2 a', 0)->plaintext;

View file

@ -30,7 +30,7 @@ class PinterestBridge extends FeedExpander {
private function fixLowRes() { private function fixLowRes() {
$newitems = []; $newitems = array();
$pattern = '/https\:\/\/i\.pinimg\.com\/[a-zA-Z0-9]*x\//'; $pattern = '/https\:\/\/i\.pinimg\.com\/[a-zA-Z0-9]*x\//';
foreach($this->items as $item) { foreach($this->items as $item) {

View file

@ -18,13 +18,13 @@ class RevolutBridge extends BridgeAbstract {
$articles = array_slice($articleOverview->find('url'), 0, 15); $articles = array_slice($articleOverview->find('url'), 0, 15);
foreach($articles as $article) { foreach($articles as $article) {
$item = []; $item = array();
$item['uri'] = $article->find('loc', 0)->plaintext; $item['uri'] = $article->find('loc', 0)->plaintext;
$item['timestamp'] = $article->find('lastmod', 0)->plaintext; $item['timestamp'] = $article->find('lastmod', 0)->plaintext;
$item['enclosures'] = [ $item['enclosures'] = array(
$article->find('image:loc', 0)->plaintext $article->find('image:loc', 0)->plaintext
]; );
$fullArticle = getSimpleHTMLDOMCached($item['uri']) $fullArticle = getSimpleHTMLDOMCached($item['uri'])
or returnServerError('Error while downloading the full article'); or returnServerError('Error while downloading the full article');

View file

@ -25,7 +25,7 @@ class RoadAndTrackBridge extends BridgeAbstract {
private function fixImages($content) { private function fixImages($content) {
$enclosures = []; $enclosures = array();
foreach($content->find('img') as $image) { foreach($content->find('img') as $image) {
$image->src = explode('?', $image->getAttribute('data-src'))[0]; $image->src = explode('?', $image->getAttribute('data-src'))[0];
$enclosures[] = $image->src; $enclosures[] = $image->src;

View file

@ -395,7 +395,7 @@ class XenForoBridge extends BridgeAbstract {
*/ */
private function fixDate($date, $lang = 'en-US') { private function fixDate($date, $lang = 'en-US') {
$mnamesen = [ $mnamesen = array(
'January', 'January',
'Feburary', 'Feburary',
'March', 'March',
@ -408,7 +408,7 @@ class XenForoBridge extends BridgeAbstract {
'October', 'October',
'November', 'November',
'December' 'December'
]; );
switch($lang) { switch($lang) {
case 'en-US': // example: Jun 9, 2018 at 11:46 PM case 'en-US': // example: Jun 9, 2018 at 11:46 PM
@ -418,7 +418,7 @@ class XenForoBridge extends BridgeAbstract {
case 'de-DE': // example: 19 Juli 2018 um 19:27 Uhr case 'de-DE': // example: 19 Juli 2018 um 19:27 Uhr
$mnamesde = [ $mnamesde = array(
'Januar', 'Januar',
'Februar', 'Februar',
'März', 'März',
@ -431,9 +431,9 @@ class XenForoBridge extends BridgeAbstract {
'Oktober', 'Oktober',
'November', 'November',
'Dezember' 'Dezember'
]; );
$mnamesdeshort = [ $mnamesdeshort = array(
'Jan.', 'Jan.',
'Feb.', 'Feb.',
'Mär.', 'Mär.',
@ -446,7 +446,7 @@ class XenForoBridge extends BridgeAbstract {
'Okt.', 'Okt.',
'Nov.', 'Nov.',
'Dez.' 'Dez.'
]; );
$date = str_ireplace($mnamesde, $mnamesen, $date); $date = str_ireplace($mnamesde, $mnamesen, $date);
$date = str_ireplace($mnamesdeshort, $mnamesen, $date); $date = str_ireplace($mnamesdeshort, $mnamesen, $date);

View file

@ -53,7 +53,7 @@ function getContents($url, $header = array(), $opts = array(), $returnHeader = f
$cache->setScope('server'); $cache->setScope('server');
$cache->purgeCache(86400); // 24 hours (forced) $cache->purgeCache(86400); // 24 hours (forced)
$params = [$url]; $params = array($url);
$cache->setKey($params); $cache->setKey($params);
$retVal = array( $retVal = array(
@ -304,7 +304,7 @@ function getSimpleHTMLDOMCached($url,
$cache->setScope('pages'); $cache->setScope('pages');
$cache->purgeCache(86400); // 24 hours (forced) $cache->purgeCache(86400); // 24 hours (forced)
$params = [$url]; $params = array($url);
$cache->setKey($params); $cache->setKey($params);
// Determine if cached file is within duration // Determine if cached file is within duration

View file

@ -100,4 +100,6 @@
<rule ref="Squiz.Strings.DoubleQuoteUsage"> <rule ref="Squiz.Strings.DoubleQuoteUsage">
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar" /> <exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar" />
</rule> </rule>
<!-- Always use the long array syntax -->
<rule ref="Generic.Arrays.DisallowShortArraySyntax" />
</ruleset> </ruleset>