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

refactor: Use the elvis operator + fix: Handle null checks with the ?? operator #48042

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Sep 15, 2024

  • Resolves: #

Summary

Makes code easier to read.

TODO

  • ...

Checklist

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/files_sharing/lib/External/Manager.php Fixed Show resolved Hide resolved
@@ -646,8 +646,7 @@
try {
$accountProperty = $account->getProperty($property);
$currentValue = $accountProperty->getValue();
$scope = ($accountProperty->getScope() ? $accountProperty->getScope()
: $defaultScopes[$property]);
$scope = ($accountProperty->getScope() ?: $defaultScopes[$property]);

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Operand of type 'v2-federated'|'v2-local'|'v2-private'|'v2-published' is always truthy
@@ -121,7 +121,7 @@
$this->config->setUserValue($this->userId, Application::APP_ID, 'lon', strval($lon));
// resolve and store formatted address
$address = $this->resolveLocation($lat, $lon);
$address = $address ? $address : $this->l10n->t('Unknown address');
$address = $address ?: $this->l10n->t('Unknown address');

Check notice

Code scanning / Psalm

RiskyTruthyFalsyComparison Note

Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.
Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

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

🧹

@miaulalala
Copy link
Contributor

tenor

@@ -37,7 +37,7 @@ public function logDetails(string $app, $message, int $level): array {
$url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--';
$method = is_string($request->getMethod()) ? $request->getMethod() : '--';
if ($this->config->getValue('installed', false)) {
$user = \OC_User::getUser() ? \OC_User::getUser() : '--';
$user = \OC_User::getUser() ?: '--';
Copy link
Contributor

Choose a reason for hiding this comment

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

Uid "0" would also evaluate to '--'

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, same as with the ternary operator

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed :)

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst changed the title refactor: Use the elvis operator refactor: Use the elvis operator + fix: Handle null checks with the ?? operator Sep 15, 2024
@ChristophWurst ChristophWurst merged commit 0a7b4b5 into master Sep 16, 2024
176 checks passed
@ChristophWurst ChristophWurst deleted the refactor/elvis branch September 16, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

6 participants