From e7c171e3f62cd8d5feb06a90cbd836697fd85ab9 Mon Sep 17 00:00:00 2001 From: Alexander Purr <purr@ub.uni-leipzig.de> Date: Thu, 23 Dec 2021 16:03:17 +0100 Subject: [PATCH] refs #21064 [fid] code style fid/Hydrator --- module/fid/src/Hydrator/OrderHydrator.php | 81 ++++++++++++++++--- .../Hydrator/OrderMissingRecordHydrator.php | 58 +++++++++++-- .../fid/src/Hydrator/OrderUpdateHydrator.php | 62 ++++++++++++-- .../Hydrator/Strategy/UserDataStrategy.php | 52 ++++++++++-- module/fid/src/Hydrator/UserHydrator.php | 28 ++++++- .../Hydrator/UserHydratorDelegatorFactory.php | 34 ++++++-- 6 files changed, 276 insertions(+), 39 deletions(-) diff --git a/module/fid/src/Hydrator/OrderHydrator.php b/module/fid/src/Hydrator/OrderHydrator.php index e85feda8d1f..edc7163bde8 100644 --- a/module/fid/src/Hydrator/OrderHydrator.php +++ b/module/fid/src/Hydrator/OrderHydrator.php @@ -1,42 +1,91 @@ <?php +/** + * Order hydrator + * + * Copyright (C) 2021 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @category VuFind + * @package Hydrator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ namespace fid\Hydrator; use fid\Service\DataTransferObject\Order; use VuFind\RecordDriver\DefaultRecord; use Zend\Hydrator\AbstractHydrator; +/** + * Order hydrator for saving aquistions data correctly to dto before sending to fidis + * + * @category VuFind + * @package Hydrator + * @author Alexander Purr <purr@ub.uni-leipzig.de> + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class OrderHydrator extends AbstractHydrator { + /** + * Extract method: + * Not implemented, not in use + * + * @param Order $object Order object + * + * @return void + */ public function extract($object) { - - // TODO: Implement extract() method. } /** - * @param array $data - * @param Order|object $object - * @return Order|object|void + * Save acquisition data to order object + * + * @param array $data Relevant data + * @param Order $object Order object + * + * @return Order|void */ public function hydrate(array $data, $object) { - /** - * @var DefaultRecord $driver - */ + /* @var DefaultRecord $driver */ $driver = $data['driver']; $object->setType($data['type']); $object->setUser($data['user']); - $partialCopy = array_key_exists('subitoPartialCopy', $data) ? $data['subitoPartialCopy'] : null; - $digitization = array_key_exists('digitization', $data) ? $data['digitization'] : null; + $partialCopy = array_key_exists('subitoPartialCopy', $data) + ? $data['subitoPartialCopy'] : null; + $digitization = array_key_exists('digitization', $data) + ? $data['digitization'] : null; $pda = array_key_exists('pda', $data) ? $data['pda'] : null; /* Collect needed record data */ $id = $driver->tryMethod('getUniqueID'); $title = $driver->tryMethod('getTitle'); $pdetails = $driver->tryMethod('getPublicationDetails'); - $publicationDetails = $this->toArray(!empty($pdetails) ? $pdetails[0] : null); + $publicationDetails + = $this->toArray(!empty($pdetails) ? $pdetails[0] : null); $authors = $driver->tryMethod('getDeduplicatedAuthors'); $primaryAuthor = $driver->tryMethod('getPrimaryAuthor'); $secondaryAuthors = $driver->tryMethod('getSecondaryAuthors'); @@ -77,7 +126,15 @@ class OrderHydrator extends AbstractHydrator $object->setLabel($data['label']); } - public function toArray($object) : array + /** + * Helper function to convert object member variables to array. + * Member name becomes array key. + * + * @param $object Object + * + * @return array + */ + protected function toArray($object) : array { $array = (array)$object; $keys = str_replace('*', '', array_keys($array)); diff --git a/module/fid/src/Hydrator/OrderMissingRecordHydrator.php b/module/fid/src/Hydrator/OrderMissingRecordHydrator.php index debe7570ed9..7a13f5db5c4 100644 --- a/module/fid/src/Hydrator/OrderMissingRecordHydrator.php +++ b/module/fid/src/Hydrator/OrderMissingRecordHydrator.php @@ -1,28 +1,74 @@ <?php +/** + * Order missing record hydrator + * + * Copyright (C) 2021 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @category VuFind + * @package Hydrator + * @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\Hydrator; use fid\Service\DataTransferObject\Order; use Zend\Hydrator\AbstractHydrator; +/** + * Order missing record (free/ open digitization-on-demand) hydrator + * for saving aquistions data correctly before sending to fidis. + * + * @category VuFind + * @package Hydrator + * @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 OrderMissingRecordHydrator extends AbstractHydrator { + /** + * Extract method: + * Not implemented, not in use + * + * @param Order $object Order object + * + * @return void + */ public function extract($object) { - - // TODO: Implement extract() method. } /** - * @param array $data - * @param Order|object $object - * @return Order|object|void + * Save free/ open digitization-on-demand data to order object + * + * @param array $data Data to hydrate + * @param Order $object Order object + * + * @return Order */ public function hydrate(array $data, $object) { $object->setType($data['type']); $object->setUser($data['user']); - $digitization = array_key_exists('digitization', $data) ? $data['digitization'] : null; + $digitization + = array_key_exists('digitization', $data) ? $data['digitization'] : null; $partialCopy = null; $pda = null; $record = null; diff --git a/module/fid/src/Hydrator/OrderUpdateHydrator.php b/module/fid/src/Hydrator/OrderUpdateHydrator.php index c098d7d6162..b9cf3ab5d29 100644 --- a/module/fid/src/Hydrator/OrderUpdateHydrator.php +++ b/module/fid/src/Hydrator/OrderUpdateHydrator.php @@ -1,30 +1,80 @@ <?php +/** + * Order update hydrator + * + * Copyright (C) 2021 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @category VuFind + * @package Hydrator + * @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\Hydrator; use fid\Service\DataTransferObject\Order; use Zend\Hydrator\AbstractHydrator; - +/** + * Order update hydrator for getting order data + * or update aquistions data correctly before sending to fidis + * + * @category VuFind + * @package Hydrator + * @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 OrderUpdateHydrator extends AbstractHydrator { public const DATE_FORMAT = 'Y-m-d'; + /** + * Extract and return due date and status + * + * @param Order $object Order object + * + * @return array + */ public function extract($object) { - $retval['due_date'] = $object->getDueDate() ? $object->getDueDate()->format(self::DATE_FORMAT) : ''; + $retval['due_date'] = $object->getDueDate() + ? $object->getDueDate()->format(self::DATE_FORMAT) : ''; $retval['status'] = $object->getStatus() ?? 'open'; return $retval; } /** - * @param array $data - * @param Order|object $object - * @return Order|object|void + * Save due date and status to order + * + * @param array $data Data to save to order object + * @param Order $object Order object + * + * @return Order */ public function hydrate(array $data, $object) { $data['status'] ? $object->setStatus($data['status']) : null; !empty($data['due_date']) - ? $object->setDueDate(\DateTime::createFromFormat(self::DATE_FORMAT, $data['due_date'])) + ? $object->setDueDate( + \DateTime::createFromFormat( + self::DATE_FORMAT, $data['due_date'] + ) + ) : null; return $object; } diff --git a/module/fid/src/Hydrator/Strategy/UserDataStrategy.php b/module/fid/src/Hydrator/Strategy/UserDataStrategy.php index 48808dff111..330a1cc1c23 100644 --- a/module/fid/src/Hydrator/Strategy/UserDataStrategy.php +++ b/module/fid/src/Hydrator/Strategy/UserDataStrategy.php @@ -1,7 +1,11 @@ <?php /** + * User data strategy + * * Copyright (C) 2019 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,27 +19,54 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Gregor Gawol <gawol@ub.uni-leipzig.de> - * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Hydrator\Strategy; +use fid\Hydrator\UserHydrator; +use fid\Hydrator\UserHydratorDelegatorFactory; use Zend\Hydrator\NamingStrategy\NamingStrategyInterface; use Zend\Hydrator\Strategy\StrategyInterface; - +/** + * User data strategy + * + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + * + * @see UserHydrator + * @see UserHydratorDelegatorFactory + */ class UserDataStrategy implements StrategyInterface { - /** - * @var NamingStrategyInterface - */ + /* @var NamingStrategyInterface */ protected $namingStrategy; + /** + * Constructor + * + * @param NamingStrategyInterface $namingStrategy Naming Startegy + */ public function __construct(NamingStrategyInterface $namingStrategy) { $this->namingStrategy = $namingStrategy; } + /** + * Extract method + * + * @param array|mixed $value Value(s) + * + * @return array|mixed + */ public function extract($value) { if (!is_array($value)) { @@ -50,6 +81,13 @@ class UserDataStrategy implements StrategyInterface return $result ?? []; } + /** + * Hydrate method + * + * @param array|mixed $value Value(s) + * + * @return array|mixed + */ public function hydrate($value) { if (!is_array($value)) { diff --git a/module/fid/src/Hydrator/UserHydrator.php b/module/fid/src/Hydrator/UserHydrator.php index f8f922c0d6d..698e2150fee 100644 --- a/module/fid/src/Hydrator/UserHydrator.php +++ b/module/fid/src/Hydrator/UserHydrator.php @@ -1,7 +1,11 @@ <?php /** + * User Hydrator + * * Copyright (C) 2019 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,14 +19,32 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Gregor Gawol <gawol@ub.uni-leipzig.de> - * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Hydrator; +use fid\Hydrator\Strategy\UserDataStrategy; use Zend\Hydrator\ClassMethods; +/** + * User Hydrator + * Gets functionality by using UserDataStrategy + * + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + * + * @see UserDataStrategy + * @see UserHydratorDelegatorFactory + */ class UserHydrator extends ClassMethods { } diff --git a/module/fid/src/Hydrator/UserHydratorDelegatorFactory.php b/module/fid/src/Hydrator/UserHydratorDelegatorFactory.php index 6ee434ffe80..f6e10fa4bd0 100644 --- a/module/fid/src/Hydrator/UserHydratorDelegatorFactory.php +++ b/module/fid/src/Hydrator/UserHydratorDelegatorFactory.php @@ -1,7 +1,11 @@ <?php /** + * User Hydrator Delegator Factory + * * Copyright (C) 2019 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,8 +19,11 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * @author Gregor Gawol <gawol@ub.uni-leipzig.de> - * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki */ namespace fid\Hydrator; @@ -28,17 +35,34 @@ use Zend\Hydrator\ClassMethods; use Zend\Hydrator\Strategy\CollectionStrategy; use Zend\ServiceManager\Factory\DelegatorFactoryInterface; +/** + * User Hydrator Delegator Factory + * + * @category VuFind + * @package Hydrator + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + * @link https://vufind.org/wiki/development Wiki + */ class UserHydratorDelegatorFactory implements DelegatorFactoryInterface { + /** + * Init user hydrator object and apply naming strategy + * + * @param ContainerInterface $container Service Container + * @param $name Class name + * @param callable $callback Callback funcktion + * @param array|null $options Options + * + * @return AbstractHydrator + */ public function __invoke( ContainerInterface $container, $name, callable $callback, array $options = null ) { - /** - * @var AbstractHydrator $hydrator - */ + /* @var AbstractHydrator $hydrator */ $hydrator = call_user_func($callback); $namingStrategy = $hydrator->getNamingStrategy(); $hydrator->addStrategy('data', new UserDataStrategy($namingStrategy)); -- GitLab