Skip to content

Commit

Permalink
Introduce typehinting and general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Jun 14, 2024
1 parent 4cc2a60 commit 8f5667c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
24 changes: 10 additions & 14 deletions classes/issue/IssueAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace APP\issue;

use APP\facades\Repo;
use APP\journal\Journal;
use APP\subscription\IndividualSubscriptionDAO;
use APP\subscription\InstitutionalSubscriptionDAO;
use APP\subscription\Subscription;
Expand All @@ -37,22 +38,17 @@ class IssueAction
/**
* Checks if subscription is required for viewing the issue
*
* @param Issue $issue
* @param \APP\journal\Journal $journal
*
* @return bool
*
* @hook IssueAction::subscriptionRequired [[&$journal, &$issue, &$result]]
*/
public function subscriptionRequired($issue, $journal)
public function subscriptionRequired(Issue $issue, Journal $journal): bool
{
assert($issue instanceof \APP\issue\Issue);
assert($journal instanceof \APP\journal\Journal);
assert($journal->getId() == $issue->getJournalId());
if ($journal->getId() != $issue->getJournalId()) {
throw new Exception('Issue does not match journal!');
}

// Check subscription state.
$result = $journal->getData('publishingMode') == \APP\journal\Journal::PUBLISHING_MODE_SUBSCRIPTION &&
$issue->getAccessStatus() != \APP\issue\Issue::ISSUE_ACCESS_OPEN && (
$result = $journal->getData('publishingMode') == Journal::PUBLISHING_MODE_SUBSCRIPTION &&
$issue->getAccessStatus() != Issue::ISSUE_ACCESS_OPEN && (
is_null($issue->getOpenAccessDate()) ||
strtotime($issue->getOpenAccessDate()) > time()
);
Expand All @@ -64,7 +60,7 @@ public function subscriptionRequired($issue, $journal)
* Checks if this user is granted access to pre-publication issue galleys
* based on their roles in the journal (i.e. Manager, Editor, etc).
*
* @param \APP\journal\Journal $journal
* @param Journal $journal
*
* @return bool
*/
Expand Down Expand Up @@ -96,7 +92,7 @@ public function allowedIssuePrePublicationAccess($journal, $user)
* Checks if user has subscription
*
* @param \PKP\user\User $user
* @param \APP\journal\Journal $journal
* @param Journal $journal
* @param int $issueId Issue ID (optional)
* @param int $articleId Article ID (optional)
*
Expand Down Expand Up @@ -143,7 +139,7 @@ public function subscribedUser($user, $journal, $issueId = null, $articleId = nu
* Checks if remote client domain or ip is allowed
*
* @param \APP\core\Request $request
* @param \APP\journal\Journal $journal
* @param Journal $journal
* @param int $issueId Issue ID (optional)
* @param int $articleId Article ID (optional)
*
Expand Down
4 changes: 1 addition & 3 deletions classes/journal/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public function getAssocType()

/**
* @copydoc \PKP\core\DataObject::getDAO()
*
* @return JournalDAO
*/
public function getDAO()
public function getDAO(): JournalDAO
{
return DAORegistry::getDAO('JournalDAO');
}
Expand Down
4 changes: 3 additions & 1 deletion classes/plugins/PubObjectCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public function add($object, $parent)
$this->_insertInternally($object, 'articlesByIssue', $object->getCurrentPublication()->getData('issueId'), $object->getId());
}
if ($object instanceof Galley) {
assert($parent instanceof Submission);
if (!$parent instanceof Submission) {
throw new Exception('Parent object of galley is unexpected type!');
}
$this->_insertInternally($object, 'galleys', $object->getId());
$this->_insertInternally($object, 'galleysByArticle', $object->getData('submissionId'), $object->getId());
$this->_insertInternally($object, 'galleysByIssue', $parent->getCurrentPublication()->getData('issueId'), $object->getId());
Expand Down

0 comments on commit 8f5667c

Please sign in to comment.