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

View File

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

View File

@ -77,7 +77,7 @@ class AtmoNouvelleAquitaineBridge extends BridgeAbstract {
private function getLegendIndexes() {
$rawIndexes = $this->dom->find('.prevision-legend .prevision-legend-label');
$indexes = [];
$indexes = array();
for ($i = 0; $i < count($rawIndexes); $i++) {
if ($rawIndexes[$i]->hasAttribute('data-color')) {
$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);
$sizeKey = $this->getInput('image_size');
$items = [];
$items = array();
foreach ($html->find('a.iusc') as $element) {
$data = json_decode(htmlspecialchars_decode($element->getAttribute('m')), true);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -112,7 +112,7 @@ EOD
//Decode images
$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 = str_get_html($imagecleaned);
@ -164,7 +164,11 @@ EOD
$content = preg_replace('/<img src=\'.*?safe_image\.php.*?\' \/>/m', '', $content);
//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
$content = str_get_html($content);

View File

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

View File

@ -58,7 +58,7 @@ class InstagramBridge extends BridgeAbstract {
$cacheFac->setWorkingDir(PATH_LIB_CACHES);
$cache = $cacheFac->create(Configuration::getConfig('cache', 'type'));
$cache->setScope(get_called_class());
$cache->setKey([$username]);
$cache->setKey(array($username));
$key = $cache->loadData();
if($key == null) {
@ -178,7 +178,7 @@ class InstagramBridge extends BridgeAbstract {
$caption = '';
}
$enclosures = [$mediaInfo->display_url];
$enclosures = array($mediaInfo->display_url);
$content = '<img src="' . htmlentities($mediaInfo->display_url) . '" alt="' . $caption . '" />';
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') != '') {
$requestJson->filters->location['regions'] = [$this->getInput('region')];
$requestJson->filters->location['regions'] = array($this->getInput('region'));
}
if($this->getInput('department') != '') {
$requestJson->filters->location['departments'] = [$this->getInput('department')];
$requestJson->filters->location['departments'] = array($this->getInput('department'));
}
if($this->getInput('cities') != '') {
@ -467,7 +467,7 @@ class LeBonCoinBridge extends BridgeAbstract {
}
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') != ''
@ -526,7 +526,7 @@ class LeBonCoinBridge extends BridgeAbstract {
}
if($this->getInput('fuel') != '') {
$requestJson->filters->enums['fuel'] = [$this->getInput('fuel')];
$requestJson->filters->enums['fuel'] = array($this->getInput('fuel'));
}
$requestJson->limit = 30;

View File

@ -19,7 +19,7 @@ class N26Bridge extends BridgeAbstract
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) {
$item = [];
$item = array();
$item['uri'] = self::URI . $article->find('h2 a', 0)->href;
$item['title'] = $article->find('h2 a', 0)->plaintext;

View File

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

View File

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

View File

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

View File

@ -395,7 +395,7 @@ class XenForoBridge extends BridgeAbstract {
*/
private function fixDate($date, $lang = 'en-US') {
$mnamesen = [
$mnamesen = array(
'January',
'Feburary',
'March',
@ -408,7 +408,7 @@ class XenForoBridge extends BridgeAbstract {
'October',
'November',
'December'
];
);
switch($lang) {
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
$mnamesde = [
$mnamesde = array(
'Januar',
'Februar',
'März',
@ -431,9 +431,9 @@ class XenForoBridge extends BridgeAbstract {
'Oktober',
'November',
'Dezember'
];
);
$mnamesdeshort = [
$mnamesdeshort = array(
'Jan.',
'Feb.',
'Mär.',
@ -446,7 +446,7 @@ class XenForoBridge extends BridgeAbstract {
'Okt.',
'Nov.',
'Dez.'
];
);
$date = str_ireplace($mnamesde, $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->purgeCache(86400); // 24 hours (forced)
$params = [$url];
$params = array($url);
$cache->setKey($params);
$retVal = array(
@ -304,7 +304,7 @@ function getSimpleHTMLDOMCached($url,
$cache->setScope('pages');
$cache->purgeCache(86400); // 24 hours (forced)
$params = [$url];
$params = array($url);
$cache->setKey($params);
// Determine if cached file is within duration

View File

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