From e64b3fde2a2e511396526b5ffdb8fffe78a59551 Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Wed, 5 Apr 2017 11:10:46 +0200 Subject: [PATCH] * [MOD] Code refactoring --- inc/SP/Account/AccountAcl.class.php | 4 +- inc/SP/Util/ArrayUtil.class.php | 47 +++++++++++++++++-- inc/SP/Util/Checks.class.php | 1 - inc/SP/Util/Connection.class.php | 4 +- inc/SP/Util/ConnectionInterface.class.php | 2 +- inc/SP/Util/Util.class.php | 38 --------------- .../material-blue/views/itemshow/groups.inc | 4 +- 7 files changed, 53 insertions(+), 47 deletions(-) diff --git a/inc/SP/Account/AccountAcl.class.php b/inc/SP/Account/AccountAcl.class.php index b7f43f33..715374a6 100644 --- a/inc/SP/Account/AccountAcl.class.php +++ b/inc/SP/Account/AccountAcl.class.php @@ -30,8 +30,8 @@ use SP\Core\ActionsInterface; use SP\Core\Session; use SP\DataModel\UserData; use SP\Mgmt\Groups\GroupUsers; +use SP\Util\ArrayUtil; use SP\Util\Checks; -use SP\Util\Util; /** * Class AccountAcl @@ -450,7 +450,7 @@ class AccountAcl // o... permitir los grupos que no sean el principal del usuario? || (Config::getConfig()->isAccountFullGroupAccess() // Comprobar si el usuario está vinculado desde los grupos secundarios de la cuenta - && Util::checkInObjectArray($groupsId, 'groupId', $groupId)) + && ArrayUtil::checkInObjectArray($groupsId, 'groupId', $groupId)) ) { return true; } diff --git a/inc/SP/Util/ArrayUtil.class.php b/inc/SP/Util/ArrayUtil.class.php index 2f6524df..067a402f 100644 --- a/inc/SP/Util/ArrayUtil.class.php +++ b/inc/SP/Util/ArrayUtil.class.php @@ -34,10 +34,10 @@ class ArrayUtil /** * Buscar un objeto en un array según el valor de una propiedad * - * @param array $array + * @param array $array * @param string $property Nombre de la propiedad - * @param string $value Valor de la propiedad - * @param object $default Valor por defecto + * @param string $value Valor de la propiedad + * @param object $default Valor por defecto * @return false|object */ public static function searchInObject(array $array, $property, $value, $default = null) @@ -53,4 +53,45 @@ class ArrayUtil return null !== $default ? $default : false; } + + /** + * Comprobar si un valor existe en un array de objetos + * + * @param array $objectArray + * @param string $method + * @param mixed $value + * @return bool + */ + public static function checkInObjectArrayMethod(array $objectArray, $method, $value) + { + foreach ($objectArray as $object) { + if (is_callable([$object, $method]) && $object->$method() === $value) { + return true; + } + } + + return false; + } + + /** + * Comprobar si un valor existe en un array de objetos + * + * @param array $objectArray + * @param string $property + * @param mixed $value + * @return bool + */ + public static function checkInObjectArray(array $objectArray, $property, $value) + { + foreach ($objectArray as $object) { + if (is_object($object) + && isset($object->$property) + && $object->$property == $value + ) { + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/inc/SP/Util/Checks.class.php b/inc/SP/Util/Checks.class.php index 47c0233c..47283532 100644 --- a/inc/SP/Util/Checks.class.php +++ b/inc/SP/Util/Checks.class.php @@ -25,7 +25,6 @@ namespace SP\Util; use SP\Config\Config; -use SP\Core\Exceptions\SPException; use SP\Http\Request; /** diff --git a/inc/SP/Util/Connection.class.php b/inc/SP/Util/Connection.class.php index a2785d86..3564447b 100644 --- a/inc/SP/Util/Connection.class.php +++ b/inc/SP/Util/Connection.class.php @@ -74,7 +74,7 @@ class Connection implements ConnectionInterface * Obtener un socket * * @param $type int EL tipo de socket TCP/UDP - * @return mixed + * @return resource * @throws \SP\Core\Exceptions\SPException */ public function getSocket($type) @@ -96,6 +96,8 @@ class Connection implements ConnectionInterface } stream_set_timeout($this->socket, self::SOCKET_TIMEOUT); + + return $this->socket; } /** diff --git a/inc/SP/Util/ConnectionInterface.class.php b/inc/SP/Util/ConnectionInterface.class.php index 833ebb82..cec5db2f 100644 --- a/inc/SP/Util/ConnectionInterface.class.php +++ b/inc/SP/Util/ConnectionInterface.class.php @@ -39,7 +39,7 @@ interface ConnectionInterface * Obtener un socket * * @param $type - * @return mixed + * @return resource */ public function getSocket($type); diff --git a/inc/SP/Util/Util.class.php b/inc/SP/Util/Util.class.php index 3a3cc3e7..71b20f48 100644 --- a/inc/SP/Util/Util.class.php +++ b/inc/SP/Util/Util.class.php @@ -619,44 +619,6 @@ class Util } } - /** - * Comprobar si un valor existe en un array de objetos - * - * @param array $objectArray - * @param string $method - * @param mixed $value - * @return bool - */ - public static function checkInObjectArrayMethod(array $objectArray, $method, $value) - { - foreach ($objectArray as $object) { - if (is_callable([$object, $method]) && $object->$method() === $value) { - return true; - } - } - - return false; - } - - /** - * Comprobar si un valor existe en un array de objetos - * - * @param array $objectArray - * @param string $property - * @param mixed $value - * @return bool - */ - public static function checkInObjectArray(array $objectArray, $property, $value) - { - foreach ($objectArray as $object) { - if (isset($object->$property) && $object->$property == $value) { - return true; - } - } - - return false; - } - /** * Bloquear la aplicación * diff --git a/inc/themes/material-blue/views/itemshow/groups.inc b/inc/themes/material-blue/views/itemshow/groups.inc index 5844f8cc..1e33c230 100644 --- a/inc/themes/material-blue/views/itemshow/groups.inc +++ b/inc/themes/material-blue/views/itemshow/groups.inc @@ -1,4 +1,6 @@ - id) ? 'selected' : ''; ?> + id) ? 'selected' : ''; ?>