ci: disallow the sizeof function in linter (#4134)

This commit is contained in:
Dag 2024-06-18 20:22:46 +02:00 committed by GitHub
parent 0eac7a0784
commit 206bebc7bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 28 additions and 20 deletions

View file

@ -47,7 +47,7 @@ class DiarioDoAlentejoBridge extends BridgeAbstract
}, self::PT_MONTH_NAMES),
array_map(function ($num) {
return sprintf('-%02d-', $num);
}, range(1, sizeof(self::PT_MONTH_NAMES))),
}, range(1, count(self::PT_MONTH_NAMES))),
$element->find('span.date', 0)->innertext
);

View file

@ -83,7 +83,7 @@ class GameBananaBridge extends BridgeAbstract
}
// Get updates from element[8], if applicable
if ($this->getInput('updates') && sizeof($element[8]) > 0) {
if ($this->getInput('updates') && count($element[8]) > 0) {
$update = $element[8][0];
$item['content'] .= '<br><strong>Update:</strong> ' . $update['_sTitle'];
if ($update['_sText'] != '') {

View file

@ -347,17 +347,17 @@ class ItakuBridge extends BridgeAbstract
$url = self::URI . "/api/galleries/images/?by_following=false&date_range={$opt['range']}&ordering={$opt['order']}&is_video={$opt['video_only']}";
$url .= "&text={$opt['text']}&visibility=PUBLIC&visibility=PROFILE_ONLY&page=1&page_size=30&format=json";
if (sizeof($opt['optional_tags']) > 0) {
if (count($opt['optional_tags']) > 0) {
foreach ($opt['optional_tags'] as $tag) {
$url .= "&optional_tags=$tag";
}
}
if (sizeof($opt['negative_tags']) > 0) {
if (count($opt['negative_tags']) > 0) {
foreach ($opt['negative_tags'] as $tag) {
$url .= "&negative_tags=$tag";
}
}
if (sizeof($opt['required_tags']) > 0) {
if (count($opt['required_tags']) > 0) {
foreach ($opt['required_tags'] as $tag) {
$url .= "&required_tags=$tag";
}
@ -381,17 +381,17 @@ class ItakuBridge extends BridgeAbstract
$url = self::URI . "/api/posts/?by_following=false&date_range={$opt['range']}&ordering={$opt['order']}";
$url .= '&visibility=PUBLIC&visibility=PROFILE_ONLY&page=1&page_size=30&format=json';
if (sizeof($opt['optional_tags']) > 0) {
if (count($opt['optional_tags']) > 0) {
foreach ($opt['optional_tags'] as $tag) {
$url .= "&optional_tags=$tag";
}
}
if (sizeof($opt['negative_tags']) > 0) {
if (count($opt['negative_tags']) > 0) {
foreach ($opt['negative_tags'] as $tag) {
$url .= "&negative_tags=$tag";
}
}
if (sizeof($opt['required_tags']) > 0) {
if (count($opt['required_tags']) > 0) {
foreach ($opt['required_tags'] as $tag) {
$url .= "&required_tags=$tag";
}
@ -446,7 +446,7 @@ class ItakuBridge extends BridgeAbstract
private function getPost($id, array $metadata = null)
{
if (isset($metadata) && sizeof($metadata['gallery_images']) < $metadata['num_images']) {
if (isset($metadata) && count($metadata['gallery_images']) < $metadata['num_images']) {
$metadata = null; //force re-fetch of metadata
}
$uri = self::URI . '/posts/' . $id;
@ -457,7 +457,7 @@ class ItakuBridge extends BridgeAbstract
$content_str = nl2br($data['content']);
$content = "<p>{$content_str}</p><br/>"; //TODO: Add link and itaku user mention detection and convert into links.
if (array_key_exists('tags', $data) && sizeof($data['tags']) > 0) {
if (array_key_exists('tags', $data) && count($data['tags']) > 0) {
$tag_types = [
'ARTIST' => '',
'COPYRIGHT' => '',
@ -479,7 +479,7 @@ class ItakuBridge extends BridgeAbstract
}
}
if (sizeof($data['folders']) > 0) {
if (count($data['folders']) > 0) {
$content .= '📁 In Folder(s): ';
foreach ($data['folders'] as $folder) {
$url = self::URI . '/profile/' . $data['owner_username'] . '/posts/' . $folder['id'];
@ -488,7 +488,7 @@ class ItakuBridge extends BridgeAbstract
}
$content .= '<hr/>';
if (sizeof($data['gallery_images']) > 0) {
if (count($data['gallery_images']) > 0) {
foreach ($data['gallery_images'] as $media) {
$title = $media['title'];
$url = self::URI . '/images/' . $media['id'];
@ -529,7 +529,7 @@ class ItakuBridge extends BridgeAbstract
$content_str = nl2br($data['description']);
$content = "<p>{$content_str}</p><br>"; //TODO: Add link and itaku user mention detection and convert into links.
if (array_key_exists('tags', $data) && sizeof($data['tags']) > 0) {
if (array_key_exists('tags', $data) && count($data['tags']) > 0) {
// $content .= "🏷 Tag(s): ";
$tag_types = [
'ARTIST' => '',
@ -552,7 +552,7 @@ class ItakuBridge extends BridgeAbstract
}
}
if (array_key_exists('reference_gallery_sections', $data) && sizeof($data['reference_gallery_sections']) > 0) {
if (array_key_exists('reference_gallery_sections', $data) && count($data['reference_gallery_sections']) > 0) {
$content .= '📁 Example folder(s): ';
foreach ($data['folders'] as $folder) {
$url = self::URI . '/profile/' . $data['owner_username'] . '/gallery/' . $folder['id'];
@ -601,7 +601,7 @@ class ItakuBridge extends BridgeAbstract
$content_str = nl2br($data['description']);
$content = "<p>{$content_str}</p><br/>"; //TODO: Add link and itaku user mention detection and convert into links.
if (array_key_exists('tags', $data) && sizeof($data['tags']) > 0) {
if (array_key_exists('tags', $data) && count($data['tags']) > 0) {
// $content .= "🏷 Tag(s): ";
$tag_types = [
'ARTIST' => '',
@ -624,7 +624,7 @@ class ItakuBridge extends BridgeAbstract
}
}
if (array_key_exists('sections', $data) && sizeof($data['sections']) > 0) {
if (array_key_exists('sections', $data) && count($data['sections']) > 0) {
$content .= '📁 In Folder(s): ';
foreach ($data['sections'] as $folder) {
$url = self::URI . '/profile/' . $data['owner_username'] . '/gallery/' . $folder['id'];

View file

@ -63,7 +63,7 @@ class MagellantvBridge extends BridgeAbstract
// Check whether items exists
$article_list = $dom->find('div.articlePreview_preview-card__mLMOm');
if (sizeof($article_list) == 0) {
if (count($article_list) == 0) {
throw new Exception(sprintf('Unable to find css selector on `%s`', $url));
}

View file

@ -228,7 +228,7 @@ class PatreonBridge extends BridgeAbstract
//post attachments
if (
isset($post->relationships->attachments->data) &&
sizeof($post->relationships->attachments->data) > 0
count($post->relationships->attachments->data) > 0
) {
$item['enclosures'] = [];
$item['content'] .= '<hr><p><b>Attachments:</b><ul>';

View file

@ -76,7 +76,7 @@ class PresidenciaPTBridge extends BridgeAbstract
}, self::PT_MONTH_NAMES),
array_map(function ($num) {
return sprintf('-%02d-', $num);
}, range(1, sizeof(self::PT_MONTH_NAMES))),
}, range(1, count(self::PT_MONTH_NAMES))),
$edt
);

View file

@ -26,7 +26,7 @@ class VieDeMerdeBridge extends BridgeAbstract
$html = getSimpleHTMLDOM(self::URI, []);
$quotes = $html->find('article.bg-white');
if (sizeof($quotes) === 0) {
if (count($quotes) === 0) {
return;
}

View file

@ -35,6 +35,14 @@
</properties>
</rule>
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
</property>
</properties>
</rule>
<!-- Duplicate class names are not allowed -->
<rule ref="Generic.Classes.DuplicateClassName"/>