From 5d1be8772bb93f9976323abc3a8a8696b24514e7 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 27 Jan 2017 09:21:04 -0500 Subject: [PATCH] Upgrade PHP_CodeSniffer. --- composer.json | 2 +- .../VuFind/src/VuFind/Connection/Oracle.php | 10 ++++++---- .../src/VuFind/Controller/AbstractBase.php | 6 +++--- .../VuFind/Controller/ContentController.php | 10 ++++------ .../src/VuFind/Controller/HoldsTrait.php | 18 +++++++++-------- .../VuFind/Controller/ILLRequestsTrait.php | 5 +++-- .../StorageRetrievalRequestsTrait.php | 5 +++-- module/VuFind/src/VuFind/ILS/Connection.php | 15 +++++++------- module/VuFind/src/VuFind/ILS/Driver/Aleph.php | 10 ++++------ module/VuFind/src/VuFind/ILS/Driver/DAIA.php | 3 ++- .../src/VuFind/ILS/Driver/MultiBackend.php | 20 +++++++++++-------- .../VuFind/src/VuFind/ILS/Driver/Virtua.php | 16 +++++---------- .../VuFind/src/VuFind/ILS/Driver/Voyager.php | 9 ++++----- module/VuFind/src/VuFind/OAI/Server.php | 5 +++-- .../Search/Solr/DeduplicationListener.php | 9 ++------- 15 files changed, 69 insertions(+), 74 deletions(-) diff --git a/composer.json b/composer.json index f1457df6339..aeeb53d564a 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,7 @@ "phpmd/phpmd": "2.4.2", "phpunit/phpunit": "4.8.27", "sebastian/phpcpd": "2.0.0", - "squizlabs/php_codesniffer": "2.6.0" + "squizlabs/php_codesniffer": "2.7.1" }, "scripts": { "post-update-cmd": "phing installsolr installswaggerui" diff --git a/module/VuFind/src/VuFind/Connection/Oracle.php b/module/VuFind/src/VuFind/Connection/Oracle.php index 24054d5ad66..aa73b4015ad 100644 --- a/module/VuFind/src/VuFind/Connection/Oracle.php +++ b/module/VuFind/src/VuFind/Connection/Oracle.php @@ -201,10 +201,11 @@ class Oracle public function bindParam( $parsed, $place_holder, $data, $data_type = 'string', $length = -1 ) { - if (@oci_bind_by_name( + $success = @oci_bind_by_name( $parsed, $place_holder, $data, $length, $this->getDataTypeConstant($data_type) - )) { + ); + if ($success) { return true; } else { $this->handleError('binding', oci_error()); @@ -234,10 +235,11 @@ class Oracle public function returnParam( $parsed, $place_holder, &$data, $data_type = 'string', $length = -1 ) { - if (@oci_bind_by_name( + $success = @oci_bind_by_name( $parsed, $place_holder, $data, $length, $this->getDataTypeConstant($data_type) - )) { + ); + if ($success) { return true; } else { $this->handleError('binding', oci_error()); diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 643c49ab4e1..982097b9957 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -123,9 +123,9 @@ class AbstractBase extends AbstractActionController */ protected function createViewModel($params = null) { - if ('lightbox' === $this->params()->fromPost( - 'layout', $this->params()->fromQuery('layout', false) - )) { + $layout = $this->params() + ->fromPost('layout', $this->params()->fromQuery('layout', false)); + if ('lightbox' === $layout) { $this->layout()->setTemplate('layout/lightbox'); } return new ViewModel($params); diff --git a/module/VuFind/src/VuFind/Controller/ContentController.php b/module/VuFind/src/VuFind/Controller/ContentController.php index 276df019950..ac9464b86fc 100644 --- a/module/VuFind/src/VuFind/Controller/ContentController.php +++ b/module/VuFind/src/VuFind/Controller/ContentController.php @@ -59,13 +59,11 @@ class ContentController extends \VuFind\Controller\AbstractBase // 1.) Current language suffix // 2.) Default language suffix // 3.) No language suffix - if (null !== $themeInfo->findContainingTheme( - "templates/content/{$page}_$language.phtml" - )) { + $currentTpl = "templates/content/{$page}_$language.phtml"; + $defaultTpl = "templates/content/{$page}_$defaultLanguage.phtml"; + if (null !== $themeInfo->findContainingTheme($currentTpl)) { $page = "{$page}_$language"; - } elseif (null !== $themeInfo->findContainingTheme( - "templates/content/{$page}_$defaultLanguage.phtml" - )) { + } elseif (null !== $themeInfo->findContainingTheme($defaultTpl)) { $page = "{$page}_$defaultLanguage"; } diff --git a/module/VuFind/src/VuFind/Controller/HoldsTrait.php b/module/VuFind/src/VuFind/Controller/HoldsTrait.php index 41957b1173b..1fb404e0418 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsTrait.php +++ b/module/VuFind/src/VuFind/Controller/HoldsTrait.php @@ -84,9 +84,10 @@ trait HoldsTrait } // Block invalid requests: - if (!$catalog->checkRequestIsValid( + $validRequest = $catalog->checkRequestIsValid( $driver->getUniqueID(), $gatheredDetails, $patron - )) { + ); + if (!$validRequest) { return $this->blockedholdAction(); } @@ -116,18 +117,19 @@ trait HoldsTrait $pickup = $catalog->getPickUpLocations($patron, $pickupDetails); // Process form submissions if necessary: - if (!is_null($this->params()->fromPost('placeHold'))) { + if (null !== $this->params()->fromPost('placeHold')) { // If the form contained a pickup location or request group, make sure // they are valid: - $valid = $this->holds()->validateRequestGroupInput( + $validGroup = $this->holds()->validateRequestGroupInput( $gatheredDetails, $extraHoldFields, $requestGroups ); - if (!$valid) { + $validPickup = $validGroup && $this->holds()->validatePickUpInput( + $gatheredDetails['pickUpLocation'], $extraHoldFields, $pickup + ); + if (!$validGroup) { $this->flashMessenger() ->addMessage('hold_invalid_request_group', 'error'); - } elseif (!$this->holds()->validatePickUpInput( - $gatheredDetails['pickUpLocation'], $extraHoldFields, $pickup - )) { + } elseif (!$validPickup) { $this->flashMessenger()->addMessage('hold_invalid_pickup', 'error'); } else { // If we made it this far, we're ready to place the hold; diff --git a/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php b/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php index eaa943d0416..099d9517d15 100644 --- a/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php +++ b/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php @@ -86,9 +86,10 @@ trait ILLRequestsTrait } // Block invalid requests: - if (!$catalog->checkILLRequestIsValid( + $validRequest = $catalog->checkILLRequestIsValid( $driver->getUniqueID(), $gatheredDetails, $patron - )) { + ); + if (!$validRequest) { return $this->blockedILLRequestAction(); } diff --git a/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php b/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php index e76997c3c39..1119e39ccd0 100644 --- a/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php +++ b/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php @@ -87,9 +87,10 @@ trait StorageRetrievalRequestsTrait } // Block invalid requests: - if (!$catalog->checkStorageRetrievalRequestIsValid( + $validRequest = $catalog->checkStorageRetrievalRequestIsValid( $driver->getUniqueID(), $gatheredDetails, $patron - )) { + ); + if (!$validRequest) { return $this->blockedStorageRetrievalRequestAction(); } diff --git a/module/VuFind/src/VuFind/ILS/Connection.php b/module/VuFind/src/VuFind/ILS/Connection.php index bfd4d300629..31dc2b08669 100644 --- a/module/VuFind/src/VuFind/ILS/Connection.php +++ b/module/VuFind/src/VuFind/ILS/Connection.php @@ -642,9 +642,8 @@ class Connection implements TranslatorAwareInterface, LoggerAwareInterface public function checkRequestIsValid($id, $data, $patron) { try { - if ($this->checkCapability( - 'checkRequestIsValid', [$id, $data, $patron] - )) { + $params = [$id, $data, $patron]; + if ($this->checkCapability('checkRequestIsValid', $params)) { return $this->getDriver()->checkRequestIsValid($id, $data, $patron); } } catch (\Exception $e) { @@ -674,9 +673,10 @@ class Connection implements TranslatorAwareInterface, LoggerAwareInterface public function checkStorageRetrievalRequestIsValid($id, $data, $patron) { try { - if ($this->checkCapability( + $check = $this->checkCapability( 'checkStorageRetrievalRequestIsValid', [$id, $data, $patron] - )) { + ); + if ($check) { return $this->getDriver()->checkStorageRetrievalRequestIsValid( $id, $data, $patron ); @@ -707,9 +707,8 @@ class Connection implements TranslatorAwareInterface, LoggerAwareInterface public function checkILLRequestIsValid($id, $data, $patron) { try { - if ($this->checkCapability( - 'checkILLRequestIsValid', [$id, $data, $patron] - )) { + $params = [$id, $data, $patron]; + if ($this->checkCapability('checkILLRequestIsValid', $params)) { return $this->getDriver()->checkILLRequestIsValid( $id, $data, $patron ); diff --git a/module/VuFind/src/VuFind/ILS/Driver/Aleph.php b/module/VuFind/src/VuFind/ILS/Driver/Aleph.php index fe69cf8b4c7..4a251de393d 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Aleph.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Aleph.php @@ -781,14 +781,12 @@ class Aleph extends AbstractBase implements \Zend\Log\LoggerAwareInterface, $addLink = ($hold_request[0] == 'Y'); } $matches = []; - if (preg_match( - "/([0-9]*\\/[a-zA-Z]*\\/[0-9]*);([a-zA-Z ]*)/", $status, $matches - )) { + $dueDateWithStatusRegEx = "/([0-9]*\\/[a-zA-Z]*\\/[0-9]*);([a-zA-Z ]*)/"; + $dueDateRegEx = "/([0-9]*\\/[a-zA-Z]*\\/[0-9]*)/"; + if (preg_match($dueDateWithStatusRegEx, $status, $matches)) { $duedate = $this->parseDate($matches[1]); $requested = (trim($matches[2]) == "Requested"); - } else if (preg_match( - "/([0-9]*\\/[a-zA-Z]*\\/[0-9]*)/", $status, $matches - )) { + } else if (preg_match($dueDateRegEx, $status, $matches)) { $duedate = $this->parseDate($matches[1]); } else { $duedate = null; diff --git a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php index 48e8ae6491f..0a0b8287c88 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php +++ b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php @@ -654,7 +654,8 @@ class DAIA extends AbstractBase implements || (in_array( $domNode->nodeName, ['storage', 'limitation', 'department', 'institution'] - ) && strlen($domNode->nodeValue))) { + ) && strlen($domNode->nodeValue)) + ) { if (trim($node->textContent)) { $domNode->setAttribute('content', $node->textContent); $node->nodeValue = ''; diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index c053f579b09..fdebc09f46d 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -554,9 +554,10 @@ class MultiBackend extends AbstractBase $source = $this->getSource($patron['cat_username']); $driver = $this->getDriver($source); if ($driver) { - if (!$this->methodSupported( + $supported = $this->methodSupported( $driver, 'getMyStorageRetrievalRequests', compact('patron') - )) { + ); + if (!$supported) { // Return empty array if not supported by the driver return []; } @@ -1076,9 +1077,10 @@ class MultiBackend extends AbstractBase $source = $this->getSource($patron['cat_username']); $driver = $this->getDriver($source); if ($driver) { - if (!$this->methodSupported( + $supported = $this->methodSupported( $driver, 'getMyILLRequests', compact('patron') - )) { + ); + if (!$supported) { // Return empty array if not supported by the driver return []; } @@ -1187,9 +1189,10 @@ class MultiBackend extends AbstractBase $source = $this->getSource($patron['cat_username']); $driver = $this->getDriver($source); if ($driver) { - if (!$this->methodSupported( + $supported = $this->methodSupported( $driver, 'getRequestBlocks', compact('patron') - )) { + ); + if (!$supported) { return false; } return $driver->getRequestBlocks( @@ -1212,9 +1215,10 @@ class MultiBackend extends AbstractBase $source = $this->getSource($patron['cat_username']); $driver = $this->getDriver($source); if ($driver) { - if (!$this->methodSupported( + $supported = $this->methodSupported( $driver, 'getAccountBlocks', compact('patron') - )) { + ); + if (!$supported) { return false; } return $driver->getAccountBlocks( diff --git a/module/VuFind/src/VuFind/ILS/Driver/Virtua.php b/module/VuFind/src/VuFind/ILS/Driver/Virtua.php index 2f56a89a8e2..602e6dc7ce1 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Virtua.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Virtua.php @@ -589,11 +589,9 @@ class Virtua extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterfa ) { // ... can this user borrow on loan items at this // location? - if (in_array( + $can_req = in_array( $location, $unavailable_locs[$item_loc_code] - )) { - $can_req = true; - } + ); } } else { // The item is NOT on loan ... @@ -601,9 +599,7 @@ class Virtua extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterfa // ... and has a requestable status ... if (in_array($item_stat_code, $status_list)) { // ... can the user borrow status items at this location? - if (in_array($location, $status_locs[$item_loc_code])) { - $can_req = true; - } + $can_req = in_array($location, $status_locs[$item_loc_code]); } else { // ... and DOESN'T have a requestable status ... if ($item_stat_code !== null) { @@ -611,11 +607,9 @@ class Virtua extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterfa } else { // ... can the user borrow available items at this // location? - if (in_array( + $can_req = in_array( $location, $available_locs[$item_loc_code] - )) { - $can_req = true; - } + ); } } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php index e9a4b951309..2176bd7861b 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php @@ -474,9 +474,10 @@ class Voyager extends AbstractBase : PHP_INT_MAX ]; } else { - if (!in_array( + $statusFound = in_array( $row['STATUS'], $data[$row['ITEM_ID']]['status_array'] - )) { + ); + if (!$statusFound) { $data[$row['ITEM_ID']]['status_array'][] = $row['STATUS']; } } @@ -760,9 +761,7 @@ class Voyager extends AbstractBase } // If we've encountered a new status code, we should track it: - if (!in_array( - $row['STATUS'], $record['STATUS_ARRAY'] - )) { + if (!in_array($row['STATUS'], $record['STATUS_ARRAY'])) { $record['STATUS_ARRAY'][] = $row['STATUS']; } } else { diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index a161e5dceed..539cec5baa1 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -369,9 +369,10 @@ class Server // Retrieve the record from the index if ($record = $this->loadRecord($this->params['identifier'])) { - if (!$this->attachNonDeleted( + $success = $this->attachNonDeleted( $xml, $record, $this->params['metadataPrefix'] - )) { + ); + if (!$success) { return $this->showError('cannotDisseminateFormat', 'Unknown Format'); } } else { diff --git a/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php b/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php index a2a34cc42b9..e0512d76f38 100644 --- a/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php +++ b/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php @@ -346,11 +346,7 @@ class DeduplicationListener { $result = []; foreach ($params->get('fq') as $fq) { - if (preg_match_all( - '/\bbuilding:"([^"]+)"/', - $fq, - $matches - )) { + if (preg_match_all('/\bbuilding:"([^"]+)"/', $fq, $matches)) { $values = $matches[1]; foreach ($values as $value) { if (preg_match('/^\d+\/([^\/]+?)\//', $value, $matches)) { @@ -364,8 +360,7 @@ class DeduplicationListener } array_unshift($result, ''); - $result = array_flip($result); - return $result; + return array_flip($result); } } -- GitLab