Skip to content

Commit

Permalink
Simplify return type of \VuFind\Controller\AbstractBase::getUser() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jun 13, 2024
1 parent 17888e6 commit 9488393
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
7 changes: 4 additions & 3 deletions module/VuFind/src/VuFind/Controller/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Laminas\Uri\Http;
use Laminas\View\Model\ViewModel;
use VuFind\Controller\Feature\AccessPermissionInterface;
use VuFind\Db\Entity\UserEntityInterface;
use VuFind\Exception\Auth as AuthException;
use VuFind\Exception\ILS as ILSException;
use VuFind\Http\PhpEnvironment\Request as HttpRequest;
Expand Down Expand Up @@ -316,11 +317,11 @@ protected function getILSAuthenticator()
/**
* Get the user object if logged in, false otherwise.
*
* @return \VuFind\Db\Row\User|bool
* @return ?UserEntityInterface
*/
protected function getUser()
protected function getUser(): ?UserEntityInterface
{
return $this->getAuthManager()->getUserObject() ?? false;
return $this->getAuthManager()->getUserObject();
}

/**
Expand Down
7 changes: 3 additions & 4 deletions module/VuFind/src/VuFind/Controller/AbstractSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ protected function getRedirectForRecord(
protected function retrieveSearchSecurely($searchId)
{
$sessId = $this->serviceLocator->get(SessionManager::class)->getId();
$user = $this->getUser() ?: null;
return $this->getDbService(SearchServiceInterface::class)->getSearchByIdAndOwner($searchId, $sessId, $user);
return $this->getDbService(SearchServiceInterface::class)
->getSearchByIdAndOwner($searchId, $sessId, $this->getUser());
}

/**
Expand All @@ -536,12 +536,11 @@ protected function retrieveSearchSecurely($searchId)
*/
protected function saveSearchToHistory($results)
{
$user = $this->getUser() ?: null;
$sessId = $this->serviceLocator->get(SessionManager::class)->getId();
$this->serviceLocator->get(\VuFind\Search\SearchNormalizer::class)->saveNormalizedSearch(
$results,
$sessId,
$user?->getId()
$this->getUser()?->getId()
);
}

Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Controller/FeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function formAction()
$formId = 'FeedbackSite';
}

$user = $this->getUser() ?: null;
$user = $this->getUser();

$form = $this->serviceLocator->get($this->formClass);
$prefill = $this->params()->fromQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ public function deletelistAction()
if ($confirm) {
try {
$list = $this->getDbService(UserListServiceInterface::class)->getUserListById($listID);
$this->serviceLocator->get(FavoritesService::class)->destroyList($list, $this->getUser() ?: null);
$this->serviceLocator->get(FavoritesService::class)->destroyList($list, $this->getUser());

// Success Message
$this->flashMessenger()->addMessage('fav_list_delete', 'success');
Expand Down
5 changes: 2 additions & 3 deletions module/VuFind/src/VuFind/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

use function array_slice;
use function count;
use function is_object;

/**
* Redirects the user to the appropriate default VuFind action.
Expand Down Expand Up @@ -195,7 +194,7 @@ public function historyAction()
? $this->redirect()->toRoute('search-history')
: $this->forceLogin();
}
$userId = is_object($user) ? $user->id : null;
$userId = $user?->getId();

$searchHistoryHelper = $this->serviceLocator
->get(\VuFind\Search\History::class);
Expand All @@ -216,7 +215,7 @@ public function historyAction()
unset($viewData['schedule']);
} else {
$viewData['scheduleOptions'] = $scheduleOptions;
$viewData['alertemail'] = is_object($user) ? $user->email : null;
$viewData['alertemail'] = $user?->getEmail();
}
return $this->createViewModel($viewData);
}
Expand Down

0 comments on commit 9488393

Please sign in to comment.