Skip to content

Commit

Permalink
Use nullsafe operator
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed May 16, 2024
1 parent f626d71 commit 1d6e3ee
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
5 changes: 2 additions & 3 deletions lib/midcom/helper/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ public function is_locked() : bool
}

// Lock was created by the user, return "not locked"
if ( !empty(midcom::get()->auth->user->guid)
&& $this->get('locker') === midcom::get()->auth->user->guid) {
if ($this->get('locker') === midcom::get()->auth->user?->guid) {
return false;
}

Expand All @@ -454,7 +453,7 @@ public function lock() : bool
*/
public function can_unlock() : bool
{
return ( (midcom::get()->auth->user && midcom::get()->auth->user->guid == $this->__object->metadata->locker)
return ( midcom::get()->auth->user?->guid == $this->__object->metadata->locker
|| $this->__object->can_do('midcom:unlock')
|| midcom::get()->auth->can_user_do('midcom:unlock', class: midcom_services_auth::class));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/midgard/admin/asgard/handler/welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private function _list_revised(string $since, ?string $type = null, bool $only_m
$qb->add_constraint('metadata.revised', '>=', $since);

if ( $only_mine
&& midcom::get()->auth->user) {
$qb->add_constraint('metadata.authors', 'LIKE', '|' . midcom::get()->auth->user->guid . '|');
&& $guid = midcom::get()->auth->user?->guid) {
$qb->add_constraint('metadata.authors', 'LIKE', '|' . $guid . '|');
}

foreach ($qb->execute() as $object) {
Expand Down
4 changes: 2 additions & 2 deletions lib/midgard/admin/asgard/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public static function get_preference(string $preference, bool $fallback_to_conf
{
static $preferences = [];

if (midcom::get()->auth->user && !array_key_exists($preference, $preferences)) {
$person = midcom_db_person::get_cached(midcom::get()->auth->user->guid);
if ( !array_key_exists($preference, $preferences)
&& $person = midcom::get()->auth->user?->get_storage()) {
$preferences[$preference] = $person->get_parameter('midgard.admin.asgard:preferences', $preference);
}

Expand Down
9 changes: 4 additions & 5 deletions lib/net/nemein/wiki/wikipage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public function _on_creating() : bool

public function _on_updating() : bool
{
if (midcom::get()->auth->user) {
if ($guid = midcom::get()->auth->user?->guid) {
// Place current user in the page authors list
$authors = explode('|', substr($this->metadata->authors, 1, -1));
if (!in_array(midcom::get()->auth->user->guid, $authors)) {
$authors[] = midcom::get()->auth->user->guid;
if (!in_array($guid, $authors)) {
$authors[] = $guid;
$this->metadata->authors = '|' . implode('|', $authors) . '|';
}
}
Expand Down Expand Up @@ -136,8 +136,7 @@ private function update_watchers()
// Construct the message
$message = [];
$user_string = midcom::get()->i18n->get_string('anonymous', 'net.nemein.wiki');
if (midcom::get()->auth->user) {
$user = midcom::get()->auth->user->get_storage();
if ($user = midcom::get()->auth->user?->get_storage()) {
$user_string = $user->name;
}
// Title for long notifications
Expand Down
3 changes: 1 addition & 2 deletions lib/org/openpsa/calendar/handler/event/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function _handler_event(Request $request, string $handler_id, string $gui
MIDCOM_TOOLBAR_OPTIONS => ['rel' => 'directlink']
];

if (midcom::get()->auth->user) {
$user = midcom::get()->auth->user->get_storage();
if ($user = midcom::get()->auth->user?->get_storage()) {
$date = $this->_l10n->get_formatter()->date();
$relatedto_button_settings = [
'wikinote' => [
Expand Down
7 changes: 3 additions & 4 deletions themes/OpenPsa2/style/userinfo.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
$auth = midcom::get()->auth;
$logout_label = midcom::get()->i18n->get_string('logout', 'midcom');

if ($auth->user) {
if ($user = midcom::get()->auth->user) {
$siteconf = org_openpsa_core_siteconfig::get_instance();
if ($user_url = $siteconf->get_node_full_url('org.openpsa.user')) {
$person_string = '<a href="' . $user_url . 'view/' . $auth->user->guid . '/">' . $auth->user->name . "</a>";
$person_string = '<a href="' . $user_url . 'view/' . $user->guid . '/">' . $user->name . "</a>";
} else {
$person_string = $auth->user->name;
$person_string = $user->name;
} ?>
<ul>
<li class="user">&(person_string:h);</li>
Expand Down

0 comments on commit 1d6e3ee

Please sign in to comment.