From 614bc1c9d22b234ad4de249e16fbb1ae4701effa Mon Sep 17 00:00:00 2001 From: Alexander Purr <purr@ub.uni-leipzig.de> Date: Thu, 23 Dec 2021 16:07:22 +0100 Subject: [PATCH] refs #21064 [fid] code style fid/Validators --- .../Validator/SubitoPartialCopyPageBounds.php | 35 ++++++++++++++--- .../Validator/SubitoPartialCopyPageOrder.php | 33 +++++++++++++--- ...bitoPartialCopyPageRangeValidatorTrait.php | 37 ++++++++++++++---- .../SubitoPartialCopyPageSelection.php | 39 ++++++++++++++++--- 4 files changed, 121 insertions(+), 23 deletions(-) diff --git a/module/fid/src/Validator/SubitoPartialCopyPageBounds.php b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php index 35bc8a99f53..c3fb3f86f3e 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageBounds.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageBounds.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page bounds validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page bounds validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageBounds extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -37,14 +53,23 @@ class SubitoPartialCopyPageBounds extends AbstractValidator self::PAGE_BOUNDS => "acquisition_error_page_bounds", ]; - public function isValid($value) + /** + * Validate if given page range is beetween first and last page of a record + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { if ($this->options['numberPages'] == null) { return false; } - $this->extractPages($value); + $this->_extractPages($value); - if (($this->pageEnd > $this->options['numberPages']) || ($this->pageStart < 1)) { + if (($this->_pageEnd > $this->options['numberPages']) + || ($this->_pageStart < 1) + ) { $this->error(self::PAGE_BOUNDS); return false; } else { diff --git a/module/fid/src/Validator/SubitoPartialCopyPageOrder.php b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php index 0415c5a348d..891087e3f7c 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageOrder.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageOrder.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page order validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page order validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageOrder extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -32,11 +48,18 @@ class SubitoPartialCopyPageOrder extends AbstractValidator self::PAGES_ORDER => "acquisition_error_page_order", ]; - public function isValid($value) + /** + * Validate if given page range is ordered correctly + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { - $this->extractPages($value); + $this->_extractPages($value); - if ($this->pageStart > $this->pageEnd) { + if ($this->_pageStart > $this->_pageEnd) { $this->error(self::PAGES_ORDER); return false; } else { diff --git a/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php index ee91dbc6a10..87a4551c814 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageRangeValidatorTrait.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page range validator trait + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -15,23 +19,42 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use fid\Controller\RecordController; +/** + * Subito partial copy page range validator trait + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ trait SubitoPartialCopyPageRangeValidatorTrait { - private $pageStart = null; + private $_pageStart = null; - private $pageEnd = null; + private $_pageEnd = null; - private function extractPages($value) + /** + * Extract start and end page of a page range (string like '12-123') + * + * @param string $value From to page range + * + * @return void + */ + private function _extractPages(string $value) { preg_match(RecordController::PAGE_RANGE_PATTERN, $value, $matches); - $this->pageStart = (int)$matches[1]; - $this->pageEnd = (int)$matches[2]; + $this->_pageStart = (int)$matches[1]; + $this->_pageEnd = (int)$matches[2]; } } diff --git a/module/fid/src/Validator/SubitoPartialCopyPageSelection.php b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php index 00f5be4679e..41dabd58c0b 100644 --- a/module/fid/src/Validator/SubitoPartialCopyPageSelection.php +++ b/module/fid/src/Validator/SubitoPartialCopyPageSelection.php @@ -1,7 +1,11 @@ <?php /** + * Subito partial copy page selection validator + * * Copyright (C) 2020 Leipzig University Library * + * PHP Version 7 + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -15,13 +19,25 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Alexander Purr <purr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Validator; use Zend\Validator\AbstractValidator; +/** + * Subito partial copy page selection validator + * + * @category VuFind + * @package Validator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class SubitoPartialCopyPageSelection extends AbstractValidator { use SubitoPartialCopyPageRangeValidatorTrait; @@ -39,15 +55,26 @@ class SubitoPartialCopyPageSelection extends AbstractValidator 'percentagedLimit' => 10 ]; - public function isValid($value) + /** + * Validate if given page selection does not exceed percentaged limit of a record + * + * @param string $value From to page range + * + * @return bool + */ + public function isValid(string $value) : bool { if ($this->options['numberPages'] == null) { return false; } - $this->extractPages($value); + $this->_extractPages($value); - $selection = $this->pageEnd - $this->pageStart; - $permittedSelection = (($this->options['percentagedLimit'] / 100) * $this->options['numberPages']) + $this->options['tolerancePages']; + $selection = $this->_pageEnd - $this->_pageStart; + $permittedSelection = ( + ($this->options['percentagedLimit'] / 100) + * $this->options['numberPages'] + ) + + $this->options['tolerancePages']; if ($selection > $permittedSelection) { $this->error(self::PAGE_SELECTION); return false; -- GitLab