Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: ?? didn't work here as bool won't be seen as null #11673

Merged
merged 4 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Content/Text/BBCode.php
Expand Up @@ -111,7 +111,7 @@ private static function getOldAttachmentData($body)

$picturedata = Images::getInfoFromURLCached($matches[1]);

if ($picturedata) {
if (!empty($picturedata)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty array gets casted as false in a condition, what is the purpose of empty() here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally don't like this "magic casting" thing and try to make it clean (with no casting). Plus also in other occurrences I found the empty($array) calls. Should I then rewrite all to one way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not wrong, just superfluous regarding the basic capabilities of the language. I'd say leave existing instances alone but don't add any more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to make each handling of returned variables from Imagess::getInfoFromURL[Cached]() the same way, that we know this is everywhere the same and don't have to check each case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now removed empty() from each check to make it be the same on all such occurrences.

if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) {
$post['image'] = $matches[1];
} else {
Expand Down Expand Up @@ -320,7 +320,7 @@ public static function getAttachedData($body, $item = [])
$post['text'] = trim(str_replace($pictures[0][0], '', $body));
} else {
$imgdata = Images::getInfoFromURLCached($pictures[0][1]);
if ($imgdata && substr($imgdata['mime'], 0, 6) == 'image/') {
if (!empty($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') {
$post['type'] = 'photo';
$post['image'] = $pictures[0][1];
$post['preview'] = $pictures[0][2];
Expand Down
7 changes: 5 additions & 2 deletions src/Protocol/OStatus.php
Expand Up @@ -1377,7 +1377,7 @@ public static function getAttachment(DOMDocument $doc, DOMElement $root, array $
case 'photo':
if (!empty($siteinfo['image'])) {
$imgdata = Images::getInfoFromURLCached($siteinfo['image']);
if ($imgdata) {
if (!empty($imgdata)) {
$attributes = [
'rel' => 'enclosure',
'href' => $siteinfo['image'],
Expand All @@ -1388,6 +1388,7 @@ public static function getAttachment(DOMDocument $doc, DOMElement $root, array $
}
}
break;

case 'video':
$attributes = [
'rel' => 'enclosure',
Expand All @@ -1398,13 +1399,15 @@ public static function getAttachment(DOMDocument $doc, DOMElement $root, array $
];
XML::addElement($doc, $root, 'link', '', $attributes);
break;

default:
Logger::warning('Unsupported type', ['type' => $siteinfo['type'], 'url' => $siteinfo['url']]);
break;
}

if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) {
$imgdata = Images::getInfoFromURLCached($siteinfo['image']);
if ($imgdata) {
if (!empty($imgdata)) {
$attributes = [
'rel' => 'enclosure',
'href' => $siteinfo['image'],
Expand Down