From 4c0c5a758f85347d224546e67dcd3c9f30bfde0a Mon Sep 17 00:00:00 2001 From: Vitalii Bezsheiko Date: Wed, 15 May 2024 13:09:18 +0300 Subject: [PATCH] pkp/pkp-lib#8885 Code styling improvements --- classes/submission/maps/Schema.php | 45 ++++++++++-------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/classes/submission/maps/Schema.php b/classes/submission/maps/Schema.php index 92aa043ba16..8beea695429 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -91,9 +91,7 @@ protected function getSubmissionsListProps(): array 'urlPublished', ]; - if (!empty($additionalProps = $this->appSpecificProps())) { - $props = array_merge($props, $additionalProps); - } + $props = array_merge($props, $this->appSpecificProps()); Hook::call('Submission::getSubmissionsListProps', [&$props]); @@ -119,7 +117,7 @@ public function map( ): array { $this->userGroups = $userGroups; $this->genres = $genres; - $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany(); + $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember(); $this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]); return $this->mapByProperties($this->getProps(), $item); @@ -144,7 +142,7 @@ public function summarize( ): array { $this->userGroups = $userGroups; $this->genres = $genres; - $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany(); + $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember(); $this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]); return $this->mapByProperties($this->getSummaryProps(), $item); @@ -236,7 +234,7 @@ public function mapToSubmissionsList( ): array { $this->userGroups = $userGroups; $this->genres = $genres; - $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany(); + $this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember(); $this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]); return $this->mapByProperties($this->getSubmissionsListProps(), $item); @@ -309,7 +307,7 @@ public function summarizeWithoutPublication(Submission $item): array return $prop !== 'publications'; }); - $this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany(); + $this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember(); $this->stageAssignments = $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]); return $this->mapByProperties($props, $item); @@ -619,17 +617,10 @@ public function getPropertyStages(Submission $submission): array */ protected function getPropertyStageAssignments(Enumerable $stageAssignments): bool { - if ($stageAssignments->isEmpty()) { - return false; - } - - foreach ($stageAssignments as $stageAssignment) { - if (!$stageAssignment->recommendOnly) { - return true; - } - } - - return false; + return $stageAssignments->isNotEmpty() && $stageAssignments->contains( + fn (StageAssignment $stageAssignment) => + !$stageAssignment->recommendOnly + ); } protected function getUserGroup(int $userGroupId): ?UserGroup @@ -647,14 +638,14 @@ protected function getUserGroup(int $userGroupId): ?UserGroup * * @param Enumerable $submissions * - * @return Collection The collection of stage assignments associated with submissions + * @return LazyCollection The collection of stage assignments associated with submissions */ - protected function getStageAssignmentsBySubmissions(Enumerable $submissions, array $roleIds = []): Collection + protected function getStageAssignmentsBySubmissions(Enumerable $submissions, array $roleIds = []): LazyCollection { $submissionIds = $submissions->map(fn (Submission $submission) => $submission->getId())->toArray(); return StageAssignment::withSubmissionIds($submissionIds) ->withRoleIds($roleIds) - ->get(); + ->lazy(); } /** @@ -663,12 +654,9 @@ protected function getStageAssignmentsBySubmissions(Enumerable $submissions, arr protected function getReviewRoundsFromSubmission(Submission $submission): Collection { $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */ - $reviewRounds = collect(); - foreach ($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator() as $reviewRound) { - $reviewRounds->put($reviewRound->getData('round'), $reviewRound); - } - return $reviewRounds; + return collect($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator()) + ->keyBy(fn (ReviewRound $reviewRound) => $reviewRound->getData('round')); } /** @@ -678,11 +666,8 @@ protected function getReviewRoundsFromSubmission(Submission $submission): Collec protected function areRecommendationsIn(ReviewRound $currentReviewRound, Enumerable $stageAssignments): ?bool { $hasDecidingEditors = $stageAssignments->first(fn (StageAssignment $stageAssignment) => $stageAssignment->recommendOnly); - if (!$hasDecidingEditors) { - return null; - } - return $currentReviewRound->getData('status') == ReviewRound::REVIEW_ROUND_STATUS_RECOMMENDATIONS_READY; + return $hasDecidingEditors ? $currentReviewRound->getData('status') == ReviewRound::REVIEW_ROUND_STATUS_RECOMMENDATIONS_READY : null; } /**