From 3e76f6d8aeea4fc7b487cb3f0167a4035f653e18 Mon Sep 17 00:00:00 2001 From: Alec Smecher Date: Fri, 21 Jun 2024 09:31:29 -0700 Subject: [PATCH] Coding standards --- classes/issue/IssueGalley.php | 80 ++++++-------------- classes/issue/IssueGalleyDAO.php | 124 ++++++++++--------------------- 2 files changed, 61 insertions(+), 143 deletions(-) diff --git a/classes/issue/IssueGalley.php b/classes/issue/IssueGalley.php index 43eaa8d1826..abadd5f7467 100644 --- a/classes/issue/IssueGalley.php +++ b/classes/issue/IssueGalley.php @@ -1,21 +1,14 @@ getFileType()) { case 'application/pdf': @@ -54,10 +44,8 @@ public function isPdfGalley() // /** * Get the localized value of the galley label. - * - * @return string */ - public function getGalleyLabel() + public function getGalleyLabel(): string { $label = $this->getLabel(); if (($locale = $this->getLocale()) && $locale !== Locale::getLocale()) { @@ -68,94 +56,76 @@ public function getGalleyLabel() /** * Get label/title. - * - * @return string */ - public function getLabel() + public function getLabel(): string { return $this->getData('label'); } /** * Set label/title. - * - * @param string $label */ - public function setLabel($label) + public function setLabel(string $label): void { - return $this->setData('label', $label); + $this->setData('label', $label); } /** * Get locale. - * - * @return string */ - public function getLocale() + public function getLocale(): string { return $this->getData('locale'); } /** * Set locale. - * - * @param string $locale */ - public function setLocale($locale) + public function setLocale(string $locale): void { - return $this->setData('locale', $locale); + $this->setData('locale', $locale); } /** * Get sequence order. - * - * @return float */ - public function getSequence() + public function getSequence(): ?float { return $this->getData('sequence'); } /** * Set sequence order. - * - * @param float $sequence */ - public function setSequence($sequence) + public function setSequence(float $sequence): void { - return $this->setData('sequence', $sequence); + $this->setData('sequence', $sequence); } /** * Get file ID. - * - * @return int */ - public function getFileId() + public function getFileId(): int { return $this->getData('fileId'); } /** * Set file ID. - * - * @param int $fileId */ - public function setFileId($fileId) + public function setFileId(int $fileId): void { - return $this->setData('fileId', $fileId); + $this->setData('fileId', $fileId); } /** * Get stored public ID of the galley. * - * @param string $pubIdType One of the NLM pub-id-type values or + * @param $pubIdType One of the NLM pub-id-type values or * 'other::something' if not part of the official NLM list * (see ). - * - * @return string */ - public function getStoredPubId($pubIdType) + public function getStoredPubId(string $pubIdType): null|int|string { return $this->getData('pub-id::' . $pubIdType); } @@ -168,28 +138,24 @@ public function getStoredPubId($pubIdType) * (see ). * @param string $pubId */ - public function setStoredPubId($pubIdType, $pubId) + public function setStoredPubId(string $pubIdType, null|int|string $pubId): void { - return $this->setData('pub-id::' . $pubIdType, $pubId); + $this->setData('pub-id::' . $pubIdType, $pubId); } /** * Return the "best" issue galley ID -- If a urlPath is set, * use it; otherwise use the internal article Id. - * - * @return string */ - public function getBestGalleyId() + public function getBestGalleyId(): string|int { return strlen($urlPath = (string) $this->getData('urlPath')) ? $urlPath : $this->getId(); } /** * Get the file corresponding to this galley. - * - * @return IssueFile */ - public function getFile() + public function getFile(): ?IssueFile { if (!isset($this->_issueFile)) { $issueFileDao = DAORegistry::getDAO('IssueFileDAO'); /** @var IssueFileDAO $issueFileDao */ diff --git a/classes/issue/IssueGalleyDAO.php b/classes/issue/IssueGalleyDAO.php index 0f4ccf560ce..bc042a6aeb9 100644 --- a/classes/issue/IssueGalleyDAO.php +++ b/classes/issue/IssueGalleyDAO.php @@ -3,14 +3,12 @@ /** * @file classes/issue/IssueGalleyDAO.php * - * Copyright (c) 2014-2021 Simon Fraser University - * Copyright (c) 2003-2021 John Willinsky + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2003-2024 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class IssueGalleyDAO * - * @ingroup issue_galley - * * @see IssueGalley * * @brief Operations for retrieving and modifying IssueGalley objects. @@ -26,18 +24,13 @@ class IssueGalleyDAO extends \PKP\db\DAO /** * Retrieve a galley by ID. * - * @param int $galleyId - * @param int $issueId optional - * - * @return IssueGalley - * * @hook IssueGalleyDAO::getById [[&$galleyId, &$issueId, &$returner]] */ - public function getById($galleyId, $issueId = null) + public function getById(int $galleyId, ?int $issueId = null): ?IssueGalley { - $params = [(int) $galleyId]; + $params = [$galleyId]; if ($issueId !== null) { - $params[] = (int) $issueId; + $params[] = $issueId; } $result = $this->retrieve( 'SELECT @@ -72,13 +65,8 @@ public function getById($galleyId, $issueId = null) * @param string $pubIdType One of the NLM pub-id-type values or * 'other::something' if not part of the official NLM list * (see ). - * @param string $pubId - * @param int $galleyId An ID to be excluded from the search. - * @param int $journalId - * - * @return bool */ - public function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) + public function pubIdExists(string $pubIdType, string $pubId, int $excludeGalleyId, int $journalId): bool { $result = $this->retrieve( 'SELECT COUNT(*) AS row_count @@ -89,8 +77,8 @@ public function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) [ 'pub-id::' . $pubIdType, $pubId, - (int) $galleyId, - (int) $journalId + $excludeGalleyId, + $journalId ] ); $row = $result->current(); @@ -103,14 +91,10 @@ public function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) * @param string $pubIdType One of the NLM pub-id-type values or * 'other::something' if not part of the official NLM list * (see ). - * @param string $pubId - * @param int $issueId - * - * @return IssueGalley * * @hook IssueGalleyDAO::getByPubId [[&$pubIdType, &$pubId, &$issueId, &$returner]] */ - public function getByPubId($pubIdType, $pubId, $issueId) + public function getByPubId(string $pubIdType, string $pubId, int $issueId): ?IssueGalley { $result = $this->retrieve( 'SELECT @@ -141,15 +125,11 @@ public function getByPubId($pubIdType, $pubId, $issueId) } /** - * Retrieve all galleys for an issue. - * - * @param int $issueId - * - * @return array IssueGalleys + * Retrieve an associative array of galleys for an issue by issue ID. * * @hook IssueGalleyDAO::getGalleysByIssue [[&$galleys, &$issueId]] */ - public function getByIssueId($issueId) + public function getByIssueId(int $issueId): array { $result = $this->retrieve( 'SELECT @@ -164,7 +144,7 @@ public function getByIssueId($issueId) FROM issue_galleys g LEFT JOIN issue_files f ON (g.file_id = f.file_id) WHERE g.issue_id = ? ORDER BY g.seq', - [(int) $issueId] + [$issueId] ); $galleys = []; @@ -180,12 +160,9 @@ public function getByIssueId($issueId) * Retrieve issue galley by urlPath or, failing that, * internal galley ID; urlPath takes precedence. * - * @param string $galleyId - * @param int $issueId - * * @return IssueGalley object */ - public function getByBestId($galleyId, $issueId) + public function getByBestId(int|string $galleyId, int $issueId) { $result = $this->retrieve( 'SELECT @@ -201,15 +178,14 @@ public function getByBestId($galleyId, $issueId) LEFT JOIN issue_files f ON (g.file_id = f.file_id) WHERE g.url_path = ? AND g.issue_id = ?', - [ - $galleyId, - (int) $issueId, - ] + [$galleyId, $issueId] ); if ($row = $result->current()) { return $this->_fromRow((array) $row); + } elseif (($galleyId = filter_var($galleyId, FILTER_VALIDATE_INT)) !== false) { + return $this->getById($galleyId, $issueId); } - return $this->getById($galleyId, $issueId); + return null; } /** @@ -234,10 +210,8 @@ public function getAdditionalFieldNames(): array /** * Update the localized fields for this galley. - * - * @param IssueGalley $galley */ - public function updateLocaleFields($galley) + public function updateLocaleFields(IssueGalley $galley): void { $this->updateDataObjectSettings('issue_galley_settings', $galley, [ 'galley_id' => $galley->getId() @@ -246,10 +220,8 @@ public function updateLocaleFields($galley) /** * Construct a new issue galley. - * - * @return IssueGalley */ - public function newDataObject() + public function newDataObject(): IssueGalley { return new IssueGalley(); } @@ -257,13 +229,9 @@ public function newDataObject() /** * Internal function to return an IssueGalley object from a row. * - * @param array $row - * - * @return IssueGalley - * * @hook IssueGalleyDAO::_fromRow [[&$galley, &$row]] */ - public function _fromRow($row) + public function _fromRow(array $row): IssueGalley { $galley = $this->newDataObject(); @@ -294,11 +262,9 @@ public function _fromRow($row) /** * Insert a new IssueGalley. * - * @param IssueGalley $galley - * * @hook IssueGalleyDAO::insertObject [[&$galley, $galley->getId()]] */ - public function insertObject($galley) + public function insertObject(IssueGalley $galley): int { $this->update( 'INSERT INTO issue_galleys @@ -311,8 +277,8 @@ public function insertObject($galley) VALUES (?, ?, ?, ?, ?, ?)', [ - (int) $galley->getIssueId(), - (int) $galley->getFileId(), + $galley->getIssueId(), + $galley->getFileId(), $galley->getLabel(), $galley->getLocale(), $galley->getSequence() == null ? $this->getNextGalleySequence($galley->getIssueId()) : $galley->getSequence(), @@ -329,10 +295,8 @@ public function insertObject($galley) /** * Update an existing IssueGalley. - * - * @param IssueGalley $galley */ - public function updateObject($galley) + public function updateObject(IssueGalley $galley): void { $this->update( 'UPDATE issue_galleys @@ -344,12 +308,12 @@ public function updateObject($galley) url_path = ? WHERE galley_id = ?', [ - (int) $galley->getFileId(), + $galley->getFileId(), $galley->getLabel(), $galley->getLocale(), $galley->getSequence(), $galley->getData('urlPath'), - (int) $galley->getId() + $galley->getId() ] ); $this->updateLocaleFields($galley); @@ -357,27 +321,22 @@ public function updateObject($galley) /** * Delete an IssueGalley. - * - * @param IssueGalley $galley */ - public function deleteObject($galley) + public function deleteObject(IssueGalley $galley): void { - return $this->deleteById($galley->getId(), $galley->getIssueId()); + $this->deleteById($galley->getId(), $galley->getIssueId()); } /** * Delete a galley by ID. * - * @param int $galleyId - * @param int $issueId optional - * * @hook IssueGalleyDAO::deleteById [[&$galleyId, &$issueId]] */ - public function deleteById($galleyId, $issueId = null) + public function deleteById(int $galleyId, ?int $issueId = null): void { Hook::call('IssueGalleyDAO::deleteById', [&$galleyId, &$issueId]); - if (isset($issueId)) { + if ($issueId !== null) { // Delete the file $issueGalley = $this->getById($galleyId); $issueFileManager = new IssueFileManager($issueId); @@ -385,16 +344,16 @@ public function deleteById($galleyId, $issueId = null) $affectedRows = $this->update( 'DELETE FROM issue_galleys WHERE galley_id = ? AND issue_id = ?', - [(int) $galleyId, (int) $issueId] + [$galleyId, $issueId] ); } else { $affectedRows = $this->update( 'DELETE FROM issue_galleys WHERE galley_id = ?', - [(int) $galleyId] + [$galleyId] ); } if ($affectedRows) { - $this->update('DELETE FROM issue_galley_settings WHERE galley_id = ?', [(int) $galleyId]); + $this->update('DELETE FROM issue_galley_settings WHERE galley_id = ?', [$galleyId]); } } @@ -402,9 +361,8 @@ public function deleteById($galleyId, $issueId = null) * Delete galleys by issue. * NOTE that this will not delete issue_file entities or the respective files. * - * @param int $issueId */ - public function deleteByIssueId($issueId) + public function deleteByIssueId(int $issueId): void { $galleys = $this->getByIssueId($issueId); foreach ($galleys as $galley) { @@ -414,12 +372,10 @@ public function deleteByIssueId($issueId) /** * Sequentially renumber galleys for an issue in their sequence order. - * - * @param int $issueId */ - public function resequence($issueId) + public function resequence(int $issueId): void { - $result = $this->retrieve('SELECT galley_id FROM issue_galleys WHERE issue_id = ? ORDER BY seq', [(int) $issueId]); + $result = $this->retrieve('SELECT galley_id FROM issue_galleys WHERE issue_id = ? ORDER BY seq', [$issueId]); for ($i = 1; $row = $result->current(); $i++) { $this->update('UPDATE issue_galleys SET seq = ? WHERE galley_id = ?', [$i, $row->galley_id]); $result->next(); @@ -428,14 +384,10 @@ public function resequence($issueId) /** * Get the the next sequence number for an issue's galleys (i.e., current max + 1). - * - * @param int $issueId - * - * @return int */ - public function getNextGalleySequence($issueId) + public function getNextGalleySequence(int $issueId): int { - $result = $this->retrieve('SELECT COALESCE(MAX(seq), 0) + 1 AS next_sequence FROM issue_galleys WHERE issue_id = ?', [(int) $issueId]); + $result = $this->retrieve('SELECT COALESCE(MAX(seq), 0) + 1 AS next_sequence FROM issue_galleys WHERE issue_id = ?', [$issueId]); $row = $result->current(); return $row->next_sequence; }