From 3a7b02a71046ead57f686a08425a39bece9608d0 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:10:21 -0430 Subject: [PATCH 01/59] add: PSR2 corrections. Spaces to indent in the next commit. --- src/Object.php | 99 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/src/Object.php b/src/Object.php index 5ab2849..7df020e 100644 --- a/src/Object.php +++ b/src/Object.php @@ -18,6 +18,7 @@ * */ namespace NelsonMartell { + use \BadMethodCallException; spl_autoload_call('NelsonMartell\Type'); @@ -37,23 +38,26 @@ * la propiedad. * * public function get_Nombre() { - * return $this->_nombre; + * return $this->_nombre; * } * * public function set_Nombre(string $value) { - * // Validaciones - * $this->_nombre = $value; + * // Validaciones + * $this->_nombre = $value; * } * * Además, para habilitar esta funcionalidad de propiedades, el constructor debe la siguiente * línea: - * unset($this->Nombre); + * unset($this->Nombre); * * * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class Object { - function __construct() { } + * */ + class Object + { + public function __construct() + { + } /** * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este @@ -63,7 +67,8 @@ function __construct() { } * * * */ - function __get($name) { + public function __get($name) + { $error = false; if (!property_exists($this, $name)) { @@ -79,7 +84,17 @@ function __get($name) { } if ($error) { - throw new BadMethodCallException(sprintf(dgettext('nml', "Unable to access to '%s' property in '%s' class. Reason: %s"), $name, $this->GetType()->Name, $error)); + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to access to '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); } return $this->$getter(); @@ -92,7 +107,8 @@ function __get($name) { * * * */ - function __set($name, $value) { + public function __set($name, $value) + { $error = false; if (!property_exists($this, $name)) { @@ -103,12 +119,23 @@ function __set($name, $value) { if (!$error) { if (!method_exists($this, $setter)) { - $error = dgettext('nml', 'Property is read only') . '.'; //La propiedad existe, pero no tiene establecido el método setter. + //La propiedad existe, pero no tiene establecido el método setter. + $error = dgettext('nml', 'Property is read only') . '.'; } } if ($error) { - throw new BadMethodCallException(sprintf(dgettext('nml', "Unable to assign '%s' property in '%s' class. Reason: %s"), $name, $this->GetType()->Name, $error)); + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to assign '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); } $this->$setter($value); @@ -122,7 +149,8 @@ function __set($name, $value) { * * @return string * */ - final function __toString() { + final public function __toString() + { //$args = null; //list($args) = func_get_args(); return $this->ToString(); @@ -134,16 +162,28 @@ final function __toString() { * * @return string * */ - public function ToString() { - $t = $this->GetType(); + public function toString() + { + $type = $this->GetType(); if (defined('CODE_ANALYSIS')) { - if ($t->Name != 'NelsonMartell\Object') { - trigger_error(sprintf(dgettext('nml', 'Using default %s method. You can replace its behavior, overriding it by creating %s::ToString() public method.'), __METHOD__, $t->Name), E_USER_NOTICE); + if ($type->Name != 'NelsonMartell\Object') { + trigger_error( + sprintf( + dgettext( + 'nml', + 'Using default %s method. ' . + 'You can replace its behavior, overriding it by creating %s::ToString() public method.' + ), + __METHOD__, + $type->Name + ), + E_USER_NOTICE + ); } } - return '{ ' . $t . ' }'; + return '{ ' . $type . ' }'; } /** @@ -152,15 +192,27 @@ public function ToString() { * * @return Type * */ - public final function GetType() { + final public function getType() + { return typeof($this); } - public function Equals($other) { + public function equals($other) + { if (defined('CODE_ANALYSIS')) { if ($this instanceof IEquatable) { - $t = $this->GetType(); - trigger_error(sprintf(dgettext('nml', 'You implemented IEquatable interface, but using default Object::Equals() method. You must override it, creating %s::Equals() public method.'), $t->Name), E_USER_NOTICE); + $type = $this->GetType(); + trigger_error( + sprintf( + dgettext( + 'nml', + 'You implemented IEquatable interface, but using default Object::Equals() method. '. + 'You must override it, creating %s::Equals() public method.' + ), + $type->Name + ), + E_USER_NOTICE + ); } } @@ -176,7 +228,8 @@ public function Equals($other) { * @param mixed $right Objeto de la derecha * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. * */ - public static function Compare($left, $right) { + public static function compare($left, $right) + { $r = null; if ($left instanceof IComparable) { From 193c37c1d393e20d4786d65dd129c289888f8bbc Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:12:37 -0430 Subject: [PATCH 02/59] add: Completed PSR2 corrections (tab indent). --- src/Object.php | 462 ++++++++++++++++++++++++------------------------- 1 file changed, 231 insertions(+), 231 deletions(-) diff --git a/src/Object.php b/src/Object.php index 7df020e..b5c51b6 100644 --- a/src/Object.php +++ b/src/Object.php @@ -19,235 +19,235 @@ namespace NelsonMartell { - use \BadMethodCallException; - - spl_autoload_call('NelsonMartell\Type'); - - /** - * Clase base de objetos, para encapsular propiedades y otros métodos básicos. - * - * - * @example Para usar los getter y setter de los atributos como propiedades, el atributo debe - * ser privado y su nombre tipo cammel, iniciando con $_, y su propiedad para get/set debe - * iniciar en Mayúscula, sin '_'. Ejemplo: - * - * private $_nombre = ''; //Atributo - * public $Nombre; //Propiedad para acceder a $_nombre - * - * Luego, las respectivas funciones siguiendo el formato "get_" o "set_", seguido del nombre de - * la propiedad. - * - * public function get_Nombre() { - * return $this->_nombre; - * } - * - * public function set_Nombre(string $value) { - * // Validaciones - * $this->_nombre = $value; - * } - * - * Además, para habilitar esta funcionalidad de propiedades, el constructor debe la siguiente - * línea: - * unset($this->Nombre); - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class Object - { - public function __construct() - { - } - - /** - * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este - * modelo: 'get_' + $name + '()'. - * Restringe la obtención de una propiedad no definida dentro de la clase si no posee su - * método getter. - * - * - * */ - public function __get($name) - { - $error = false; - - if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists') . '.'; - } - - $getter = 'get_' . $name; - - if (!$error) { - if (!method_exists($this, $getter)) { - $error = dgettext('nml', 'Property is write only') . '.'; //? - } - } - - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to access to '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); - } - - return $this->$getter(); - } - - /** - * Establece el valor de una propiedad según el modelo: 'set_' + $name + '(' + $value + ')' - * Restringe la asignación de una propiedad no definida dentro de la clase si no posee su - * método setter. - * - * - * */ - public function __set($name, $value) - { - $error = false; - - if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists') . '.'; - } - - $setter = 'set_' . $name; - - if (!$error) { - if (!method_exists($this, $setter)) { - //La propiedad existe, pero no tiene establecido el método setter. - $error = dgettext('nml', 'Property is read only') . '.'; - } - } - - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to assign '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); - } - - $this->$setter($value); - } - - /** - * Convierte esta instancia en su representación de cadena. - * Para modificar el funcionamiento de esta función, debe reemplazarse la función - * ObjectClass::ToString() - * - * - * @return string - * */ - final public function __toString() - { - //$args = null; - //list($args) = func_get_args(); - return $this->ToString(); - } - - /** - * Convierte la instancia actual en su representación de cadena. - * - * - * @return string - * */ - public function toString() - { - $type = $this->GetType(); - - if (defined('CODE_ANALYSIS')) { - if ($type->Name != 'NelsonMartell\Object') { - trigger_error( - sprintf( - dgettext( - 'nml', - 'Using default %s method. ' . - 'You can replace its behavior, overriding it by creating %s::ToString() public method.' - ), - __METHOD__, - $type->Name - ), - E_USER_NOTICE - ); - } - } - - return '{ ' . $type . ' }'; - } - - /** - * Obtiene el tipo del objeto actual. - * - * - * @return Type - * */ - final public function getType() - { - return typeof($this); - } - - public function equals($other) - { - if (defined('CODE_ANALYSIS')) { - if ($this instanceof IEquatable) { - $type = $this->GetType(); - trigger_error( - sprintf( - dgettext( - 'nml', - 'You implemented IEquatable interface, but using default Object::Equals() method. '. - 'You must override it, creating %s::Equals() public method.' - ), - $type->Name - ), - E_USER_NOTICE - ); - } - } - - return $this == $other; - } - - /** - * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. - * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. - * - * - * @param mixed $left Objeto de la izquierda - * @param mixed $right Objeto de la derecha - * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. - * */ - public static function compare($left, $right) - { - $r = null; - - if ($left instanceof IComparable) { - $r = $left->CompareTo($right); - } else { - if ($right instanceof IComparable) { - $r = $right->CompareTo($left); - } else { - //Si no son miembros de IComparable, se usa por defecto: - if ($left == $right) { - $r = 0; - } else { - $r = ($left > $right) ? +1 : -1; - } - } - } - - return $r; - } - } + use \BadMethodCallException; + + spl_autoload_call('NelsonMartell\Type'); + + /** + * Clase base de objetos, para encapsular propiedades y otros métodos básicos. + * + * + * @example Para usar los getter y setter de los atributos como propiedades, el atributo debe + * ser privado y su nombre tipo cammel, iniciando con $_, y su propiedad para get/set debe + * iniciar en Mayúscula, sin '_'. Ejemplo: + * + * private $_nombre = ''; //Atributo + * public $Nombre; //Propiedad para acceder a $_nombre + * + * Luego, las respectivas funciones siguiendo el formato "get_" o "set_", seguido del nombre de + * la propiedad. + * + * public function get_Nombre() { + * return $this->_nombre; + * } + * + * public function set_Nombre(string $value) { + * // Validaciones + * $this->_nombre = $value; + * } + * + * Además, para habilitar esta funcionalidad de propiedades, el constructor debe la siguiente + * línea: + * unset($this->Nombre); + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + class Object + { + public function __construct() + { + } + + /** + * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este + * modelo: 'get_' + $name + '()'. + * Restringe la obtención de una propiedad no definida dentro de la clase si no posee su + * método getter. + * + * + * */ + public function __get($name) + { + $error = false; + + if (!property_exists($this, $name)) { + $error = dgettext('nml', 'Property do not exists') . '.'; + } + + $getter = 'get_' . $name; + + if (!$error) { + if (!method_exists($this, $getter)) { + $error = dgettext('nml', 'Property is write only') . '.'; //? + } + } + + if ($error) { + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to access to '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); + } + + return $this->$getter(); + } + + /** + * Establece el valor de una propiedad según el modelo: 'set_' + $name + '(' + $value + ')' + * Restringe la asignación de una propiedad no definida dentro de la clase si no posee su + * método setter. + * + * + * */ + public function __set($name, $value) + { + $error = false; + + if (!property_exists($this, $name)) { + $error = dgettext('nml', 'Property do not exists') . '.'; + } + + $setter = 'set_' . $name; + + if (!$error) { + if (!method_exists($this, $setter)) { + //La propiedad existe, pero no tiene establecido el método setter. + $error = dgettext('nml', 'Property is read only') . '.'; + } + } + + if ($error) { + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to assign '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); + } + + $this->$setter($value); + } + + /** + * Convierte esta instancia en su representación de cadena. + * Para modificar el funcionamiento de esta función, debe reemplazarse la función + * ObjectClass::ToString() + * + * + * @return string + * */ + final public function __toString() + { + //$args = null; + //list($args) = func_get_args(); + return $this->ToString(); + } + + /** + * Convierte la instancia actual en su representación de cadena. + * + * + * @return string + * */ + public function toString() + { + $type = $this->GetType(); + + if (defined('CODE_ANALYSIS')) { + if ($type->Name != 'NelsonMartell\Object') { + trigger_error( + sprintf( + dgettext( + 'nml', + 'Using default %s method. ' . + 'You can replace its behavior, overriding it by creating %s::ToString() public method.' + ), + __METHOD__, + $type->Name + ), + E_USER_NOTICE + ); + } + } + + return '{ ' . $type . ' }'; + } + + /** + * Obtiene el tipo del objeto actual. + * + * + * @return Type + * */ + final public function getType() + { + return typeof($this); + } + + public function equals($other) + { + if (defined('CODE_ANALYSIS')) { + if ($this instanceof IEquatable) { + $type = $this->GetType(); + trigger_error( + sprintf( + dgettext( + 'nml', + 'You implemented IEquatable interface, but using default Object::Equals() method. '. + 'You must override it, creating %s::Equals() public method.' + ), + $type->Name + ), + E_USER_NOTICE + ); + } + } + + return $this == $other; + } + + /** + * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. + * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. + * + * + * @param mixed $left Objeto de la izquierda + * @param mixed $right Objeto de la derecha + * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. + * */ + public static function compare($left, $right) + { + $r = null; + + if ($left instanceof IComparable) { + $r = $left->CompareTo($right); + } else { + if ($right instanceof IComparable) { + $r = $right->CompareTo($left); + } else { + //Si no son miembros de IComparable, se usa por defecto: + if ($left == $right) { + $r = 0; + } else { + $r = ($left > $right) ? +1 : -1; + } + } + } + + return $r; + } + } } From e53264cec36891d5a07f8d65572dcfef893963b2 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:33:23 -0430 Subject: [PATCH 03/59] add: PSR2 corrections for Type. Spaces to indent in the next commit. TODO: Left camel caps formar name in methods. --- src/Type.php | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Type.php b/src/Type.php index 99b447d..6ded889 100644 --- a/src/Type.php +++ b/src/Type.php @@ -4,7 +4,7 @@ * * Content: * - Class definition: [NelsonMartell] Type - * - Function definition: [] typeof(mixed) + * - Function definition: [] typeof(mixed) * * Copyright © 2013-2015 Nelson Martell (http://nelson6e65.github.io) * @@ -19,6 +19,7 @@ * */ namespace NelsonMartell { + use \ReflectionClass; use \ReflectionProperty; use \ReflectionMethod; @@ -29,14 +30,16 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - final class Type extends Object { + final class Type extends Object + { /** * Gets the type of specified $obj and collect some info about itself. * * @param mixed $obj Target object. * */ - function __construct($obj) { + public function __construct($obj) + { parent::__construct(); unset($this->Namespace, $this->Name, $this->ShortName, $this->Vars, $this->Methods); @@ -92,7 +95,8 @@ function __construct($obj) { * * @return string * */ - public function get_Name() { + public function get_Name() + { return $this->_name; } @@ -111,7 +115,8 @@ public function get_Name() { * @return string * @see Type::ShortName * */ - public function get_ShortName() { + public function get_ShortName() + { return $this->_shortName; } @@ -131,7 +136,8 @@ public function get_ShortName() { * @return string|NULL * @see Type::Namespace * */ - public function get_Namespace() { + public function get_Namespace() + { return $this->_namespace; } @@ -144,8 +150,9 @@ public function get_Namespace() { * */ public $Vars; private $_vars = null; - public function get_Vars() { - if ($this->_vars == NULL) { + public function get_Vars() + { + if ($this->_vars == null) { $this->_vars = $this->_reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); } return $this->_vars; @@ -160,7 +167,8 @@ public function get_Vars() { * */ public $Methods; private $_methods = null; - public function get_Methods() { + public function get_Methods() + { if ($this->_methods == null) { $this->_methods = $this->_reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); } @@ -173,7 +181,8 @@ public function get_Methods() { * * @return boolean True if this type is null; other case, False. * */ - public function IsNull() { + public function isNull() + { if ($this->Name == 'NULL' || $this->Name == 'null') { return true; } @@ -187,7 +196,8 @@ public function IsNull() { * * @return boolean True if this type is NOT null; other case, False. * */ - public function IsNotNull() { + public function isNotNull() + { return !$this->IsNull(); } @@ -198,7 +208,8 @@ public function IsNotNull() { * * @return boolean True, if this Type is a custom class; another case, False. * */ - public function IsCustom() { + public function isCustom() + { switch ($this->Name) { case 'boolean': case 'integer': @@ -219,7 +230,8 @@ public function IsCustom() { * @return boolean * @see is_scalar() * */ - public function IsScalar() { + public function isScalar() + { $r = false; switch ($this->Name) { @@ -244,7 +256,8 @@ public function IsScalar() { * @return boolean * @deprecated Use more precise method: Type::IsScalar, which excludes `array`. * */ - public function IsValueType() { + public function isValueType() + { switch($this->Name){ case 'string': case 'integer': @@ -263,7 +276,8 @@ public function IsValueType() { * * @return boolean * */ - public function IsReferenceType() { + public function isReferenceType() + { return !IsValueType(); } @@ -273,7 +287,8 @@ public function IsReferenceType() { * * @return string * */ - public function ToString() { + public function toString() + { $s = $this->Name; if ($this->IsCustom()) { @@ -291,9 +306,9 @@ public function ToString() { * @return Type * @deprecated * */ - public static function typeof($obj) { + public static function typeof($obj) + { return new static($obj); } - } } From a8114737aae48967a942551f27be41309c6b7fd2 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:38:16 -0430 Subject: [PATCH 04/59] add: Completed indent PSR2 corrections to `Type`. TODO: Camel cap format in getters and setters. --- src/Type.php | 584 +++++++++++++++++++++++++-------------------------- 1 file changed, 292 insertions(+), 292 deletions(-) diff --git a/src/Type.php b/src/Type.php index 6ded889..abc2401 100644 --- a/src/Type.php +++ b/src/Type.php @@ -4,7 +4,7 @@ * * Content: * - Class definition: [NelsonMartell] Type - * - Function definition: [] typeof(mixed) + * - Function definition: [] typeof(mixed) * * Copyright © 2013-2015 Nelson Martell (http://nelson6e65.github.io) * @@ -20,295 +20,295 @@ namespace NelsonMartell { - use \ReflectionClass; - use \ReflectionProperty; - use \ReflectionMethod; - - /** - * Represents a PHP object type, and provides some properties and methods to describe some info - * about itself. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - final class Type extends Object - { - - /** - * Gets the type of specified $obj and collect some info about itself. - * - * @param mixed $obj Target object. - * */ - public function __construct($obj) - { - parent::__construct(); - unset($this->Namespace, $this->Name, $this->ShortName, $this->Vars, $this->Methods); - - $name = gettype($obj); - $shortname = null; - $namespace = null; - $vars = null; - $methods = null; - $ref = null; - - switch ($name) { - case 'object': - $ref = new ReflectionClass($obj); - $name = $ref->getName(); - $shortName = $ref->getShortName(); - $namespace = $ref->getNamespaceName(); - break; - - case 'resource': - $shortName = get_resource_type($obj); - $name = 'resource: ' . $shortName; - $vars = []; - $methods = []; - break; - - default: - $shortName = $name; - $vars = []; - $methods = []; - } - - $this->_name = $name; - $this->_shortName = $shortName; - $this->_namespace = $namespace; - $this->_vars = $vars; - $this->_methods = $methods; - $this->_reflectionObject = $ref; - } - - private $_reflectionObject = null; - - /** - * Gets the name of this Type. - * This property is read-only. - * - * @var string - * */ - public $Name; - private $_name; - - /** - * Getter for Type::Name property. - * - * @return string - * */ - public function get_Name() - { - return $this->_name; - } - - /** - * Gets the abbreviated name of class, in other words, without the namespace. - * This property is read-only. - * - * @var string - * */ - public $ShortName; - private $_shortName = null; - - /** - * Getter for Type::ShortName property. - * - * @return string - * @see Type::ShortName - * */ - public function get_ShortName() - { - return $this->_shortName; - } - - /** - * Gets the namespace name of this class. - * If this Type is not a class, this property is set to `NULL`. - * This property is read-only. - * - * @var string|NULL - * */ - public $Namespace; - private $_namespace; - - /** - * Getter for Type::Namespace property. - * - * @return string|NULL - * @see Type::Namespace - * */ - public function get_Namespace() - { - return $this->_namespace; - } - - /** - * Gets the public|protected properties (ReflectionProperty) of this Type. - * This property is read-only. - * - * - * @var array - * */ - public $Vars; - private $_vars = null; - public function get_Vars() - { - if ($this->_vars == null) { - $this->_vars = $this->_reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); - } - return $this->_vars; - } - - /** - * Gets the public|protected methods (ReflectionMethod) of this Type. - * This property is read-only. - * - * - * @var array - * */ - public $Methods; - private $_methods = null; - public function get_Methods() - { - if ($this->_methods == null) { - $this->_methods = $this->_reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); - } - return $this->_methods; - } - - /** - * Determina si este Type es NULL. - * - * - * @return boolean True if this type is null; other case, False. - * */ - public function isNull() - { - if ($this->Name == 'NULL' || $this->Name == 'null') { - return true; - } - - return false; - } - - /** - * Determina si este Type NO es NULL. - * - * - * @return boolean True if this type is NOT null; other case, False. - * */ - public function isNotNull() - { - return !$this->IsNull(); - } - - - /** - * Determina si este Type es una clase personalizada. - * - * - * @return boolean True, if this Type is a custom class; another case, False. - * */ - public function isCustom() - { - switch ($this->Name) { - case 'boolean': - case 'integer': - case 'double': - case 'string': - case 'array': - case 'NULL': - case 'null': - return false; - default: - return true; - } - } - - /** - * Determinate if this type is scalar. - * - * @return boolean - * @see is_scalar() - * */ - public function isScalar() - { - $r = false; - - switch ($this->Name) { - case 'boolean': - case 'integer': - case 'double': - case 'string': - $r = true; - break; - - default: - $r = false; - } - - return $r; - } - - /** - * Determina si este Type es de tipo valor. - * - * - * @return boolean - * @deprecated Use more precise method: Type::IsScalar, which excludes `array`. - * */ - public function isValueType() - { - switch($this->Name){ - case 'string': - case 'integer': - case 'double': - case 'boolean': - case 'array': - return true; - default: - return false; - } - } - - /** - * Determina si este Type es de tipo referencia. - * - * - * @return boolean - * */ - public function isReferenceType() - { - return !IsValueType(); - } - - /** - * Convierte la instancia actual en su representación en cadena. - * - * - * @return string - * */ - public function toString() - { - $s = $this->Name; - - if ($this->IsCustom()) { - $s = sprintf("object (%s)", $s); - } - - return $s; - } - - /** - * Obtiene el tipo del objeto especificado. - * Es un alias para el constructor de Type. - * - * - * @return Type - * @deprecated - * */ - public static function typeof($obj) - { - return new static($obj); - } - } + use \ReflectionClass; + use \ReflectionProperty; + use \ReflectionMethod; + + /** + * Represents a PHP object type, and provides some properties and methods to describe some info + * about itself. + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + final class Type extends Object + { + + /** + * Gets the type of specified $obj and collect some info about itself. + * + * @param mixed $obj Target object. + * */ + public function __construct($obj) + { + parent::__construct(); + unset($this->Namespace, $this->Name, $this->ShortName, $this->Vars, $this->Methods); + + $name = gettype($obj); + $shortname = null; + $namespace = null; + $vars = null; + $methods = null; + $ref = null; + + switch ($name) { + case 'object': + $ref = new ReflectionClass($obj); + $name = $ref->getName(); + $shortName = $ref->getShortName(); + $namespace = $ref->getNamespaceName(); + break; + + case 'resource': + $shortName = get_resource_type($obj); + $name = 'resource: ' . $shortName; + $vars = []; + $methods = []; + break; + + default: + $shortName = $name; + $vars = []; + $methods = []; + } + + $this->_name = $name; + $this->_shortName = $shortName; + $this->_namespace = $namespace; + $this->_vars = $vars; + $this->_methods = $methods; + $this->_reflectionObject = $ref; + } + + private $_reflectionObject = null; + + /** + * Gets the name of this Type. + * This property is read-only. + * + * @var string + * */ + public $Name; + private $_name; + + /** + * Getter for Type::Name property. + * + * @return string + * */ + public function get_Name() + { + return $this->_name; + } + + /** + * Gets the abbreviated name of class, in other words, without the namespace. + * This property is read-only. + * + * @var string + * */ + public $ShortName; + private $_shortName = null; + + /** + * Getter for Type::ShortName property. + * + * @return string + * @see Type::ShortName + * */ + public function get_ShortName() + { + return $this->_shortName; + } + + /** + * Gets the namespace name of this class. + * If this Type is not a class, this property is set to `NULL`. + * This property is read-only. + * + * @var string|NULL + * */ + public $Namespace; + private $_namespace; + + /** + * Getter for Type::Namespace property. + * + * @return string|NULL + * @see Type::Namespace + * */ + public function get_Namespace() + { + return $this->_namespace; + } + + /** + * Gets the public|protected properties (ReflectionProperty) of this Type. + * This property is read-only. + * + * + * @var array + * */ + public $Vars; + private $_vars = null; + public function get_Vars() + { + if ($this->_vars == null) { + $this->_vars = $this->_reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); + } + return $this->_vars; + } + + /** + * Gets the public|protected methods (ReflectionMethod) of this Type. + * This property is read-only. + * + * + * @var array + * */ + public $Methods; + private $_methods = null; + public function get_Methods() + { + if ($this->_methods == null) { + $this->_methods = $this->_reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); + } + return $this->_methods; + } + + /** + * Determina si este Type es NULL. + * + * + * @return boolean True if this type is null; other case, False. + * */ + public function isNull() + { + if ($this->Name == 'NULL' || $this->Name == 'null') { + return true; + } + + return false; + } + + /** + * Determina si este Type NO es NULL. + * + * + * @return boolean True if this type is NOT null; other case, False. + * */ + public function isNotNull() + { + return !$this->IsNull(); + } + + + /** + * Determina si este Type es una clase personalizada. + * + * + * @return boolean True, if this Type is a custom class; another case, False. + * */ + public function isCustom() + { + switch ($this->Name) { + case 'boolean': + case 'integer': + case 'double': + case 'string': + case 'array': + case 'NULL': + case 'null': + return false; + default: + return true; + } + } + + /** + * Determinate if this type is scalar. + * + * @return boolean + * @see is_scalar() + * */ + public function isScalar() + { + $r = false; + + switch ($this->Name) { + case 'boolean': + case 'integer': + case 'double': + case 'string': + $r = true; + break; + + default: + $r = false; + } + + return $r; + } + + /** + * Determina si este Type es de tipo valor. + * + * + * @return boolean + * @deprecated Use more precise method: Type::IsScalar, which excludes `array`. + * */ + public function isValueType() + { + switch($this->Name){ + case 'string': + case 'integer': + case 'double': + case 'boolean': + case 'array': + return true; + default: + return false; + } + } + + /** + * Determina si este Type es de tipo referencia. + * + * + * @return boolean + * */ + public function isReferenceType() + { + return !IsValueType(); + } + + /** + * Convierte la instancia actual en su representación en cadena. + * + * + * @return string + * */ + public function toString() + { + $s = $this->Name; + + if ($this->IsCustom()) { + $s = sprintf("object (%s)", $s); + } + + return $s; + } + + /** + * Obtiene el tipo del objeto especificado. + * Es un alias para el constructor de Type. + * + * + * @return Type + * @deprecated + * */ + public static function typeof($obj) + { + return new static($obj); + } + } } From 005c88dc30788d4a3229433a742dbea54db26471 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:47:44 -0430 Subject: [PATCH 05/59] add: PSR2 corrections for IEquatable. --- src/IEquatable.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/IEquatable.php b/src/IEquatable.php index 6941306..5e9fe43 100644 --- a/src/IEquatable.php +++ b/src/IEquatable.php @@ -19,20 +19,20 @@ namespace NelsonMartell { - /** - * Provee un método para compara igualdad entre objetos del mismo tipo. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - interface IEquatable { + /** + * Provee un método para compara igualdad entre objetos del mismo tipo. + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + interface IEquatable + { - /** - * Indica si el objeto especificado es igual a la instancia actual. - * - * - * @return boolean - * */ - public function Equals($other); - - } + /** + * Indica si el objeto especificado es igual a la instancia actual. + * + * + * @return boolean + * */ + public function equals($other); + } } From 2586c24211d1efb4d30c1abd609d6e2a2eb138df Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 03:49:41 -0430 Subject: [PATCH 06/59] add: PSR2 corrections to `IComparable`. --- src/IComparable.php | 51 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/IComparable.php b/src/IComparable.php index 53fbed3..8e9ddfa 100644 --- a/src/IComparable.php +++ b/src/IComparable.php @@ -19,31 +19,32 @@ namespace NelsonMartell { - /** - * Provee un método para compara igualdad entre objetos del mismo tipo. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - interface IComparable { + /** + * Provee un método para compara igualdad entre objetos del mismo tipo. + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + interface IComparable + { - /** - * Determina la posición relativa del objeto especificado con respecto a esta instancia. - * - * - * @param mixed $other - * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. - * */ - public function CompareTo($other); + /** + * Determina la posición relativa del objeto especificado con respecto a esta instancia. + * + * + * @param mixed $other + * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. + * */ + public function compareTo($other); - /** - * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. - * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. - * - * - * @param mixed $left Objeto de la izquierda - * @param mixed $right Objeto de la derecha - * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. - * */ - public static function Compare($left, $right); - } + /** + * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. + * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. + * + * + * @param mixed $left Objeto de la izquierda + * @param mixed $right Objeto de la derecha + * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. + * */ + public static function compare($left, $right); + } } From 305b357464de0b417a712777f9d8825277e2a9ed Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:06:51 -0430 Subject: [PATCH 07/59] Applied PSR2 corrections to non-class files. --- autoload.php | 41 +++++++++++++++++++++-------------------- src/functions.php | 43 ++++++++++++++++++++++--------------------- src/nml.php | 2 +- vendor/autoload.php | 19 ++++++++++--------- 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/autoload.php b/autoload.php index 513e448..f20f088 100644 --- a/autoload.php +++ b/autoload.php @@ -21,26 +21,27 @@ * @param string $class NML class name (full name). * @return void */ -function autoload_NML($class) { - if ($class[0] == '\\') { - $class = substr($class, 1); - } - - $classArray = explode('\\', $class); - - if ($classArray[0] == 'NelsonMartell') { - $classArray[0] = 'src'; - } else { - return; // Only checks for NelsonMartell namespace. - } - - $path = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); - - if (is_file($path)) { - require_once($path); - } else { - throw new Exception(sprintf(dgettext('nml', 'Unable to auto-load "%s" class in Nelson Martell Library (NML): "%s" file was not found. You can see the API documentation (http://nelson6e65.github.io/php_nml/api) in order to check availability of all classes/namespaces in NML. Note: If you are using "NelsonMartell" as main namespace in a file that not belongs to NML, you should include it before to load "NML/autoload.php" or, using SPL autoload features, register autoload function for that class(es) using "prepend" argument for spl_autoload_register function set to TRUE.'), $class, $path)); - } +function autoload_NML($class) +{ + if ($class[0] == '\\') { + $class = substr($class, 1); + } + + $classArray = explode('\\', $class); + + if ($classArray[0] == 'NelsonMartell') { + $classArray[0] = 'src'; + } else { + return; // Only checks for NelsonMartell namespace. + } + + $path = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); + + if (is_file($path)) { + require_once($path); + } else { + throw new Exception(sprintf(dgettext('nml', 'Unable to auto-load "%s" class in Nelson Martell Library (NML): "%s" file was not found. You can see the API documentation (http://nelson6e65.github.io/php_nml/api) in order to check availability of all classes/namespaces in NML. Note: If you are using "NelsonMartell" as main namespace in a file that not belongs to NML, you should include it before to load "NML/autoload.php" or, using SPL autoload features, register autoload function for that class(es) using "prepend" argument for spl_autoload_register function set to TRUE.'), $class, $path)); + } } spl_autoload_register('autoload_NML'); diff --git a/src/functions.php b/src/functions.php index 63614ee..51ce6dd 100644 --- a/src/functions.php +++ b/src/functions.php @@ -35,10 +35,10 @@ * @see dgettext * @see String::Format * */ -function nml_msg($message, $args = null) { - $s = String::Format($message, array_slice(func_get_args(), 1)); - - return dgettext(NML_GETTEXT_DOMAIN, $s); +function nml_msg($message, $args = null) +{ + $s = String::Format($message, array_slice(func_get_args(), 1)); + return dgettext(NML_GETTEXT_DOMAIN, $s); } @@ -55,25 +55,26 @@ function nml_msg($message, $args = null) { * @see dngettext * @see String::Format * */ -function nml_nmsg($singular, $plural, $n, $args = null) { - $s = String::Format($singular, array_slice(func_get_args(), 1)); - $p = String::Format($plural, array_slice(func_get_args(), 1)); +function nml_nmsg($singular, $plural, $n, $args = null) +{ + $s = String::Format($singular, array_slice(func_get_args(), 1)); + $p = String::Format($plural, array_slice(func_get_args(), 1)); - return dngettext(NML_GETTEXT_DOMAIN, $s, $p, $n); + return dngettext(NML_GETTEXT_DOMAIN, $s, $p, $n); } if (!function_exists('typeof')) { - - /** - * Obtiene el tipo del objeto especificado. - * Es un alias para el constructor de la clase Type. - * - * - * @param mixed $obj Objeto al cual se le extraerá su tipo. - * @return Type - * @see Type::__construct - * */ - function typeof($obj) { - return new Type($obj); - } + /** + * Obtiene el tipo del objeto especificado. + * Es un alias para el constructor de la clase Type. + * + * + * @param mixed $obj Objeto al cual se le extraerá su tipo. + * @return Type + * @see Type::__construct + * */ + function typeof($obj) + { + return new Type($obj); + } } diff --git a/src/nml.php b/src/nml.php index 9e8de5e..4729b4a 100644 --- a/src/nml.php +++ b/src/nml.php @@ -21,4 +21,4 @@ define('NML_VERSION_MAJOR', 0); define('NML_VERSION_MINOR', 4); define('NML_VERSION_BUILD', 6); -define('NML_VERSION_REVISION', NULL); +define('NML_VERSION_REVISION', null); diff --git a/vendor/autoload.php b/vendor/autoload.php index 1c9ab8e..ef87382 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -7,18 +7,19 @@ * @param string $class Class name. * @return void */ -function autoload_NML_Vendors($class) { - if ($class[0] == '\\') { - $class = substr($class, 1); - } +function autoload_NML_Vendors($class) +{ + if ($class[0] == '\\') { + $class = substr($class, 1); + } - $classArray = explode('\\', $class); + $classArray = explode('\\', $class); - $path = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); + $path = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); - if (is_file($path)) { - require_once($path); - } + if (is_file($path)) { + require_once($path); + } } spl_autoload_register('autoload_NML_Vendors'); From 960f67987bd87fbab6b420b40ecbf924b8cd61f2 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:28:57 -0430 Subject: [PATCH 08/59] Applied PSR2 corrections to `IntString` class (incomplete). Spaces instead of tabs to indent will come in the next commit. --- src/IntString.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/IntString.php b/src/IntString.php index daf2175..18ae3d1 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -26,12 +26,14 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - class IntString extends Object implements IEquatable, IComparable { + class IntString extends Object implements IEquatable, IComparable + { - function __construct($intValue = 0, $stringValue = '') { + public function __construct($intValue = 0, $stringValue = '') + { unset($this->IntValue, $this->StringValue); - if (is_integer($intValue) or $intValue == NULL) { + if (is_integer($intValue) or $intValue == null) { $this->_intValue = $intValue; } else { //Try convert to integer @@ -41,7 +43,8 @@ function __construct($intValue = 0, $stringValue = '') { $this->_stringValue = (string) $stringValue; } - public static function Parse($value) { + public static function parse($value) + { if ($value instanceof IntString) { return $value; } @@ -65,20 +68,24 @@ public static function Parse($value) { protected $_stringValue; public $IntValue; - public function get_IntValue() { + public function get_IntValue() + { return (int) $this->_intValue; } public $StringValue; - public function get_StringValue() { + public function get_StringValue() + { return $this->_stringValue; } - public function ToString() { + public function toString() + { return $this->IntValue . $this->StringValue; } - public function Equals($other) { + public function equals($other) + { if ($other instanceof IntString) { if ($this->IntValue === $other->IntValue) { if ($this->StringValue === $other->StringValue) { @@ -102,7 +109,8 @@ public function Equals($other) { * @return integer Cero (0), si esta instancia es igual a $other; mayor a cero (>0), * si es mayor a $other; menor a cero (<0), si es menor. * */ - public function CompareTo($other) { + public function compareTo($other) + { $r = $this->Equals($other) ? 0 : 9999; @@ -122,6 +130,5 @@ public function CompareTo($other) { } #endregion - } } From 6dbe072f35b20208fc1e1bb20a1aadae03ffc9b1 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:30:22 -0430 Subject: [PATCH 09/59] Applied PSR2 corrections to `IntString` class (incomplete). Tab to spaces. --- src/IntString.php | 224 +++++++++++++++++++++++----------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/src/IntString.php b/src/IntString.php index 18ae3d1..ec09299 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -19,116 +19,116 @@ namespace NelsonMartell { - /** - * Representa un elemento mixto, compuesto por un entero y una cadena unidos (en ese orden). - * El método ToString obtiene esa cadena compuesta. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class IntString extends Object implements IEquatable, IComparable - { - - public function __construct($intValue = 0, $stringValue = '') - { - unset($this->IntValue, $this->StringValue); - - if (is_integer($intValue) or $intValue == null) { - $this->_intValue = $intValue; - } else { - //Try convert to integer - $this->_intValue = (integer) $intValue; - } - - $this->_stringValue = (string) $stringValue; - } - - public static function parse($value) - { - if ($value instanceof IntString) { - return $value; - } - - $s = (string) $value; - $intValue = (int) $s; - - $stringValue = explode($intValue, $s, 2); - - if ($intValue > 0 or $stringValue[1] != '') { - $stringValue = $stringValue[1]; - } else { - $stringValue = $stringValue[0]; - } - - return new IntString($intValue, $stringValue); - } - - - protected $_intValue; - protected $_stringValue; - - public $IntValue; - public function get_IntValue() - { - return (int) $this->_intValue; - } - - public $StringValue; - public function get_StringValue() - { - return $this->_stringValue; - } - - public function toString() - { - return $this->IntValue . $this->StringValue; - } - - public function equals($other) - { - if ($other instanceof IntString) { - if ($this->IntValue === $other->IntValue) { - if ($this->StringValue === $other->StringValue) { - return true; - } - } - } - - return false; - } - - - #region IComparable - - /** - * Determina la posición relativa de esta instancia con respecto al objeto especificado. - * Nota: Cualquier objeto que no sea instancia de IntString se considerará menor. - * - * - * @param IntString|mixed $other Objeto con el que se va a comparar. - * @return integer Cero (0), si esta instancia es igual a $other; mayor a cero (>0), - * si es mayor a $other; menor a cero (<0), si es menor. - * */ - public function compareTo($other) - { - - $r = $this->Equals($other) ? 0 : 9999; - - if ($r != 0) { - if ($other instanceof IntString) { - $r = $this->IntValue - $other->IntValue; - - if ($r == 0) { - $r = $this->StringValue < $other->StringValue ? -1 : 1; - } - } else { - $r = 1; - } - } - - return $r; - } - - #endregion - } + /** + * Representa un elemento mixto, compuesto por un entero y una cadena unidos (en ese orden). + * El método ToString obtiene esa cadena compuesta. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + class IntString extends Object implements IEquatable, IComparable + { + + public function __construct($intValue = 0, $stringValue = '') + { + unset($this->IntValue, $this->StringValue); + + if (is_integer($intValue) or $intValue == null) { + $this->_intValue = $intValue; + } else { + //Try convert to integer + $this->_intValue = (integer) $intValue; + } + + $this->_stringValue = (string) $stringValue; + } + + public static function parse($value) + { + if ($value instanceof IntString) { + return $value; + } + + $s = (string) $value; + $intValue = (int) $s; + + $stringValue = explode($intValue, $s, 2); + + if ($intValue > 0 or $stringValue[1] != '') { + $stringValue = $stringValue[1]; + } else { + $stringValue = $stringValue[0]; + } + + return new IntString($intValue, $stringValue); + } + + + protected $_intValue; + protected $_stringValue; + + public $IntValue; + public function get_IntValue() + { + return (int) $this->_intValue; + } + + public $StringValue; + public function get_StringValue() + { + return $this->_stringValue; + } + + public function toString() + { + return $this->IntValue . $this->StringValue; + } + + public function equals($other) + { + if ($other instanceof IntString) { + if ($this->IntValue === $other->IntValue) { + if ($this->StringValue === $other->StringValue) { + return true; + } + } + } + + return false; + } + + + #region IComparable + + /** + * Determina la posición relativa de esta instancia con respecto al objeto especificado. + * Nota: Cualquier objeto que no sea instancia de IntString se considerará menor. + * + * + * @param IntString|mixed $other Objeto con el que se va a comparar. + * @return integer Cero (0), si esta instancia es igual a $other; mayor a cero (>0), + * si es mayor a $other; menor a cero (<0), si es menor. + * */ + public function compareTo($other) + { + + $r = $this->Equals($other) ? 0 : 9999; + + if ($r != 0) { + if ($other instanceof IntString) { + $r = $this->IntValue - $other->IntValue; + + if ($r == 0) { + $r = $this->StringValue < $other->StringValue ? -1 : 1; + } + } else { + $r = 1; + } + } + + return $r; + } + + #endregion + } } From ed1221bfab22c6da1f565479483eb5396c7b8ca9 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:42:14 -0430 Subject: [PATCH 10/59] Applied PSR2 corrections to VersionComponent class (incomplete). Spaces instead of tabs to indent will come in the next commit. --- src/VersionComponent.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/VersionComponent.php b/src/VersionComponent.php index 87fad0b..1242e94 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -18,6 +18,7 @@ * */ namespace NelsonMartell { + use \InvalidArgumentException; /** @@ -27,9 +28,11 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - class VersionComponent extends IntString implements IEquatable { + class VersionComponent extends IntString implements IEquatable + { - function __construct($intValue = null, $stringValue = null) { + public function __construct($intValue = null, $stringValue = null) + { parent::__construct($intValue, $stringValue); if (is_integer($intValue)) { @@ -82,12 +85,13 @@ function __construct($intValue = null, $stringValue = null) { } // Only integer or null } - public static function Parse($value = NULL) { + public static function parse($value = null) + { if ($value instanceof VersionComponent) { return $value; } - if ($value === NULL or trim((string) $value) === '') { + if ($value === null or trim((string) $value) === '') { return new VersionComponent(); } @@ -104,8 +108,9 @@ public static function Parse($value = NULL) { * * @return boolean * */ - public function IsDefault() { - if ($this->IntValue == 0){ + public function isDefault() + { + if ($this->IntValue == 0) { if ($this->StringValue == '') { return true; } @@ -120,7 +125,8 @@ public function IsDefault() { * * @return integer|NULL * */ - public function get_IntValue() { + public function get_IntValue() + { return $this->_intValue; } @@ -131,7 +137,8 @@ public function get_IntValue() { * * @return boolean * */ - public function IsNotDefault() { + public function isNotDefault() + { return !$this->IsDefault(); } @@ -140,8 +147,9 @@ public function IsNotDefault() { * * @return boolean * */ - public function IsNull() { - if ($this->IntValue === NULL) { + public function isNull() + { + if ($this->IntValue === null) { return true; } @@ -153,9 +161,9 @@ public function IsNull() { * * @return boolean * */ - public function IsNotNull() { + public function isNotNull() + { return !$this->IsNull(); } - } } From 098ece188c111ed0d4372951983e1cc08d02c2d5 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:45:48 -0430 Subject: [PATCH 11/59] PSR2 to VersionComponent class: tabs to space (incomplete). TODO: Camel cap format for method names. --- src/VersionComponent.php | 294 +++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/src/VersionComponent.php b/src/VersionComponent.php index 1242e94..d32dfe8 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -19,151 +19,151 @@ namespace NelsonMartell { - use \InvalidArgumentException; - - /** - * Representa un componente de un número de Version. - * Extiende la clase IntString, pero restringe los valores que puede tomar. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class VersionComponent extends IntString implements IEquatable - { - - public function __construct($intValue = null, $stringValue = null) - { - parent::__construct($intValue, $stringValue); - - if (is_integer($intValue)) { - //Validaciones: - if ($this->IntValue < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) must be positive; "%s" given.'), '$intValue', 1, $intValue)); - } - } else { - if ($intValue === null) { - if ($stringValue != null) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" must be NULL when "%s" is NULL; "%s" given.'), '$stringValue', '$intValue', $stringValue)); - } - } else { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an integer or NULL; "%s" given.'), '$intValue', 1, $intValue)); - } - } //Only integer or null - - if (is_string($stringValue)) { - if ($this->StringValue != '') { - // if ($this->IntValue == 0) { - // throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid format: "%s". VersionComponent can not be a text-only value. $intValue must be > 0 to append it text.'), '$stringValue', 2, $stringValue)); - // } Sí puede ser 0 - - $pattern = '~^([a-z])$~'; // 1 char - - if (strlen($this->StringValue) > 1) { - $start = '~^([a-z]|-)'; - $middle = '([a-z]|[0-9]|-)*'; - $end = '([a-z]|[0-9])$~'; - - $pattern = $start . $middle . $end; - } - - $correct = (boolean) preg_match($pattern, $this->StringValue); - - if ($correct) { - //Último chequeo: que no hayan 2 '-' consecutivos. - $correct = strpos($this->StringValue, '--') == false ? true : false; - } - - if (!$correct) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid chars: "%s".'), '$stringValue', 2, $stringValue)); - } - - } - } else { - if ($stringValue != null) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an string or NULL; "%s" given.'), '$stringValue', 2, $stringValue)); - } - } // Only integer or null - } - - public static function parse($value = null) - { - if ($value instanceof VersionComponent) { - return $value; - } - - if ($value === null or trim((string) $value) === '') { - return new VersionComponent(); - } - - $s = parent::Parse($value); - - $r = new VersionComponent($s->IntValue, $s->StringValue); - - return $r; - } - - /** - * Determina si este componente tiene los valores predeterminados (0). - * - * - * @return boolean - * */ - public function isDefault() - { - if ($this->IntValue == 0) { - if ($this->StringValue == '') { - return true; - } - } - - return false; - } - - - /** - * Getter method for VersionComponent::IntValue property. - * - * @return integer|NULL - * */ - public function get_IntValue() - { - return $this->_intValue; - } - - - /** - * Determina si este componente NO tiene los valores predeterminados. - * - * - * @return boolean - * */ - public function isNotDefault() - { - return !$this->IsDefault(); - } - - /** - * Determina si esta instancia es nula. - * - * @return boolean - * */ - public function isNull() - { - if ($this->IntValue === null) { - return true; - } - - return false; - } - - /** - * Determina si esta instancia NO es nula. - * - * @return boolean - * */ - public function isNotNull() - { - return !$this->IsNull(); - } - } + use \InvalidArgumentException; + + /** + * Representa un componente de un número de Version. + * Extiende la clase IntString, pero restringe los valores que puede tomar. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + class VersionComponent extends IntString implements IEquatable + { + + public function __construct($intValue = null, $stringValue = null) + { + parent::__construct($intValue, $stringValue); + + if (is_integer($intValue)) { + //Validaciones: + if ($this->IntValue < 0) { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) must be positive; "%s" given.'), '$intValue', 1, $intValue)); + } + } else { + if ($intValue === null) { + if ($stringValue != null) { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" must be NULL when "%s" is NULL; "%s" given.'), '$stringValue', '$intValue', $stringValue)); + } + } else { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an integer or NULL; "%s" given.'), '$intValue', 1, $intValue)); + } + } //Only integer or null + + if (is_string($stringValue)) { + if ($this->StringValue != '') { + // if ($this->IntValue == 0) { + // throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid format: "%s". VersionComponent can not be a text-only value. $intValue must be > 0 to append it text.'), '$stringValue', 2, $stringValue)); + // } Sí puede ser 0 + + $pattern = '~^([a-z])$~'; // 1 char + + if (strlen($this->StringValue) > 1) { + $start = '~^([a-z]|-)'; + $middle = '([a-z]|[0-9]|-)*'; + $end = '([a-z]|[0-9])$~'; + + $pattern = $start . $middle . $end; + } + + $correct = (boolean) preg_match($pattern, $this->StringValue); + + if ($correct) { + //Último chequeo: que no hayan 2 '-' consecutivos. + $correct = strpos($this->StringValue, '--') == false ? true : false; + } + + if (!$correct) { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid chars: "%s".'), '$stringValue', 2, $stringValue)); + } + + } + } else { + if ($stringValue != null) { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an string or NULL; "%s" given.'), '$stringValue', 2, $stringValue)); + } + } // Only integer or null + } + + public static function parse($value = null) + { + if ($value instanceof VersionComponent) { + return $value; + } + + if ($value === null or trim((string) $value) === '') { + return new VersionComponent(); + } + + $s = parent::Parse($value); + + $r = new VersionComponent($s->IntValue, $s->StringValue); + + return $r; + } + + /** + * Determina si este componente tiene los valores predeterminados (0). + * + * + * @return boolean + * */ + public function isDefault() + { + if ($this->IntValue == 0) { + if ($this->StringValue == '') { + return true; + } + } + + return false; + } + + + /** + * Getter method for VersionComponent::IntValue property. + * + * @return integer|NULL + * */ + public function get_IntValue() + { + return $this->_intValue; + } + + + /** + * Determina si este componente NO tiene los valores predeterminados. + * + * + * @return boolean + * */ + public function isNotDefault() + { + return !$this->IsDefault(); + } + + /** + * Determina si esta instancia es nula. + * + * @return boolean + * */ + public function isNull() + { + if ($this->IntValue === null) { + return true; + } + + return false; + } + + /** + * Determina si esta instancia NO es nula. + * + * @return boolean + * */ + public function isNotNull() + { + return !$this->IsNull(); + } + } } From f8093e88a66c71520b75cd567fd991182d012912 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 05:48:06 -0430 Subject: [PATCH 12/59] Convert tabs indentation to 4 spaces in Version class. --- src/Version.php | 550 ++++++++++++++++++++++++------------------------ 1 file changed, 275 insertions(+), 275 deletions(-) diff --git a/src/Version.php b/src/Version.php index b28d3ba..06cee57 100644 --- a/src/Version.php +++ b/src/Version.php @@ -18,279 +18,279 @@ * */ namespace NelsonMartell { - use \InvalidArgumentException; - - /** - * Representa el número de versión de un programa o ensamblado, de la forma "1.2.3.4". Sólo - * siendo obligatorios el primer y segundo componente. - * No se puede heredar esta clase. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - final class Version extends Object implements IEquatable, IComparable { - - /** - * Crea una nueva instancia con los números principal, secundario, de compilación (opcional) - * y revisión (opcional). - * Para comprobar si la versión es válida, usar el método IsValid. - * - * - * @param int $major Componente principal - * @param int $minor Componente secundario - * @param int|string|VersionComponent|NULL $build Componente de compilación - * @param int|string|VersionComponent|NULL $revision Componente de revisión - * @throw InvalidArgumentException - * */ - function __construct($major, $minor, $build = null, $revision = null) { - parent::__construct(); - unset($this->Major, $this->Minor, $this->Build, $this->Revision); - - if (!is_integer($major)) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "major", 1, typeof(0), typeof($major))); - } - - if (!is_integer($minor)) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "minor", 2, typeof(0), typeof($major))); - } - - if ($major < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "major", 1, $major)); - } - - if ($minor < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "minor", 2, $minor)); - } - - $this->_major = $major; - $this->_minor = $minor; - $this->_build = VersionComponent::Parse($build); - $this->_revision = VersionComponent::Parse($revision); - } - - /** - * Convierte una cadena a su representación del tipo Version. - * - * - * @param string Cadena a convertir. - * @return Version Objeto convertido desde $value. - * */ - public static function Parse($value) { - if ($value instanceof Version) { - return $value; - } - - $version = (string) $value; - - $version = explode('.', $version); - - $c = count($version); - - if ($c > 4 || $c < 2) { - //var_dump($version); - throw new InvalidArgumentException(sprintf(dgettext('nml', "Unable to parse. Argument passed has an invalid format: '%s'."), $value)); - } - - - $major = (int) $version[0]; - $minor = (int) $version[1]; - $build = null; - $revision = null; - - if(count($version) >= 3) { - $build = VersionComponent::Parse($version[2]); - - if(count($version) == 4) { - $revision = VersionComponent::Parse($version[3]); - } - } - - - - return new Version($major, $minor, $build, $revision); - } - - /** - * Obtiene el valor del componente principal del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * - * - * @var int Componente principal del número de versión - * */ - public $Major; - private $_major; - - public function get_Major() { return $this->_major; } - - - /** - * Obtiene el valor del componente secundario del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * - * - * @var int Componente secundario del número de versión - * */ - public $Minor; - private $_minor; - - public function get_Minor() { return $this->_minor; } - - /** - * Obtiene el valor del componente de compilación del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * - * - * @var VersionComponent Componente de compilación del número de versión - * */ - public $Build; - private $_build; - - public function get_Build() { return $this->_build; } - - /** - * Obtiene el valor del componente de revisión del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * - * - * @var VersionComponent Componente de revisión del número de versión - * */ - public $Revision; - private $_revision; - - public function get_Revision() { return $this->_revision; } - - - /** - * Convierte la instancia actual en su representación en cadena. - * Por defecto, si no están definidos los componentes de compilación y revisión, no se - * incluyen en la salida. - * Use el método IsValid si quiere determinar si la versión es válida antes de devolver esta cadena. - * - * - * @return string Representación de la versión en forma de cadena: 'major.minor[.build[.revision]]' - * @see VersionComponent::IsNull - * @see Version::IsValid - * */ - public function ToString() { - $s[0] = $this->Major; - $s[1] = $this->Minor; - - if ($this->Revision->IsNotNull()) { - $s[2] = $this->Build; - $s[3] = $this->Revision; - } else { - if ($this->Build->IsNotNull()) { - $s[2] = $this->Build; - } - } - $v = implode('.', $s); - - return $v; - } - - /** - * Indica si la instancia actual es un número de versión válido. - * - * Se considera válido si: - * 1. Major o Minor es mayor a cero (0). No puede ser '0.0'. - * 2. Build y Revision son nulos (no están definidos). - * 3. Build está definido pero Revision no. - * 4. Ambos están definidos, pero no poseen la parte de la cadena. - * 5. Ambos están definidos, pero Build no posee la parte de cadena. - * 6. Build está definido y tiene la cadena, pero Revision no está definido. - * 7. Revision posee cadena, pero Build no. - * - * @return boolean Un valor que indica si la instancia actual es válida. - * */ - public function IsValid() { - // Validación de Major y Minor: - $r = ($this->Major > 0 or $this->Minor > 0); //#1 - - // Validación de Build y Revision: - if ($r) { - $r = ($this->Build->IsNull() and $this->Revision->IsNull()); // #2 - - if (!$r) { - if ($this->Build->IsNotNull() and $this->Revision->IsNotNull()) { // Si ambos están definidos... - - $r = (bool)($this->Build->StringValue == ''); //#5 - - if (!$r) { - $r = (bool)(($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); //#4 - - if (!$r) { - if ($this->Build->StringValue != '') { - $r = $this->Revision->IsNull(); #6 - } - - if ($this->Revision->StringValue != '') { - $r = ($this->Build->StringValue == ''); #7 - } - } - } - } else { - $r = ($this->Build->IsNotNull() and $this->Revision->IsNull()); //#3 - } - } - } - - return (bool) $r; - } - - /** - * Determina si el objeto $other especificado es igual a la instancia actual. - * - * - * @return bool True si $other es igual esta instancia - * */ - public function Equals($other) { - if ($other instanceof Version) { - if ($this->Major == $other->Major && $this->Minor == $other->Minor) { - if ($this->Build->Equals($other->Build)) { - if ($this->Revision->Equals($other->Revision)) { - return true; - } - } - } - } - - return false; - } - - - #region IComparable - - /** - * Determina la posición relativa del objeto especificado con respecto a esta instancia. - * - * - * @param Version $other - * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. - * */ - public function CompareTo($other){ - - $r = $this->Equals($other) ? 0 : 9999; - - if ($r != 0) { - $r = $this->Major - $other->Major; - - if ($r == 0) { - $r = $this->Minor - $other->Minor; - - if ($r == 0) { - $r = $this->Build->CompareTo($other->Build); - - if ($r == 0) { - $r = $this->Revision->CompareTo($other->Revision); - } - } - } - } - - return $r; - } - - #endregion - - } + use \InvalidArgumentException; + + /** + * Representa el número de versión de un programa o ensamblado, de la forma "1.2.3.4". Sólo + * siendo obligatorios el primer y segundo componente. + * No se puede heredar esta clase. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + final class Version extends Object implements IEquatable, IComparable { + + /** + * Crea una nueva instancia con los números principal, secundario, de compilación (opcional) + * y revisión (opcional). + * Para comprobar si la versión es válida, usar el método IsValid. + * + * + * @param int $major Componente principal + * @param int $minor Componente secundario + * @param int|string|VersionComponent|NULL $build Componente de compilación + * @param int|string|VersionComponent|NULL $revision Componente de revisión + * @throw InvalidArgumentException + * */ + function __construct($major, $minor, $build = null, $revision = null) { + parent::__construct(); + unset($this->Major, $this->Minor, $this->Build, $this->Revision); + + if (!is_integer($major)) { + throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "major", 1, typeof(0), typeof($major))); + } + + if (!is_integer($minor)) { + throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "minor", 2, typeof(0), typeof($major))); + } + + if ($major < 0) { + throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "major", 1, $major)); + } + + if ($minor < 0) { + throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "minor", 2, $minor)); + } + + $this->_major = $major; + $this->_minor = $minor; + $this->_build = VersionComponent::Parse($build); + $this->_revision = VersionComponent::Parse($revision); + } + + /** + * Convierte una cadena a su representación del tipo Version. + * + * + * @param string Cadena a convertir. + * @return Version Objeto convertido desde $value. + * */ + public static function Parse($value) { + if ($value instanceof Version) { + return $value; + } + + $version = (string) $value; + + $version = explode('.', $version); + + $c = count($version); + + if ($c > 4 || $c < 2) { + //var_dump($version); + throw new InvalidArgumentException(sprintf(dgettext('nml', "Unable to parse. Argument passed has an invalid format: '%s'."), $value)); + } + + + $major = (int) $version[0]; + $minor = (int) $version[1]; + $build = null; + $revision = null; + + if(count($version) >= 3) { + $build = VersionComponent::Parse($version[2]); + + if(count($version) == 4) { + $revision = VersionComponent::Parse($version[3]); + } + } + + + + return new Version($major, $minor, $build, $revision); + } + + /** + * Obtiene el valor del componente principal del número de versión del objeto actual. + * Ésta propiedad es de sólo lectura. + * + * + * @var int Componente principal del número de versión + * */ + public $Major; + private $_major; + + public function get_Major() { return $this->_major; } + + + /** + * Obtiene el valor del componente secundario del número de versión del objeto actual. + * Ésta propiedad es de sólo lectura. + * + * + * @var int Componente secundario del número de versión + * */ + public $Minor; + private $_minor; + + public function get_Minor() { return $this->_minor; } + + /** + * Obtiene el valor del componente de compilación del número de versión del objeto actual. + * Ésta propiedad es de sólo lectura. + * + * + * @var VersionComponent Componente de compilación del número de versión + * */ + public $Build; + private $_build; + + public function get_Build() { return $this->_build; } + + /** + * Obtiene el valor del componente de revisión del número de versión del objeto actual. + * Ésta propiedad es de sólo lectura. + * + * + * @var VersionComponent Componente de revisión del número de versión + * */ + public $Revision; + private $_revision; + + public function get_Revision() { return $this->_revision; } + + + /** + * Convierte la instancia actual en su representación en cadena. + * Por defecto, si no están definidos los componentes de compilación y revisión, no se + * incluyen en la salida. + * Use el método IsValid si quiere determinar si la versión es válida antes de devolver esta cadena. + * + * + * @return string Representación de la versión en forma de cadena: 'major.minor[.build[.revision]]' + * @see VersionComponent::IsNull + * @see Version::IsValid + * */ + public function ToString() { + $s[0] = $this->Major; + $s[1] = $this->Minor; + + if ($this->Revision->IsNotNull()) { + $s[2] = $this->Build; + $s[3] = $this->Revision; + } else { + if ($this->Build->IsNotNull()) { + $s[2] = $this->Build; + } + } + $v = implode('.', $s); + + return $v; + } + + /** + * Indica si la instancia actual es un número de versión válido. + * + * Se considera válido si: + * 1. Major o Minor es mayor a cero (0). No puede ser '0.0'. + * 2. Build y Revision son nulos (no están definidos). + * 3. Build está definido pero Revision no. + * 4. Ambos están definidos, pero no poseen la parte de la cadena. + * 5. Ambos están definidos, pero Build no posee la parte de cadena. + * 6. Build está definido y tiene la cadena, pero Revision no está definido. + * 7. Revision posee cadena, pero Build no. + * + * @return boolean Un valor que indica si la instancia actual es válida. + * */ + public function IsValid() { + // Validación de Major y Minor: + $r = ($this->Major > 0 or $this->Minor > 0); //#1 + + // Validación de Build y Revision: + if ($r) { + $r = ($this->Build->IsNull() and $this->Revision->IsNull()); // #2 + + if (!$r) { + if ($this->Build->IsNotNull() and $this->Revision->IsNotNull()) { // Si ambos están definidos... + + $r = (bool)($this->Build->StringValue == ''); //#5 + + if (!$r) { + $r = (bool)(($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); //#4 + + if (!$r) { + if ($this->Build->StringValue != '') { + $r = $this->Revision->IsNull(); #6 + } + + if ($this->Revision->StringValue != '') { + $r = ($this->Build->StringValue == ''); #7 + } + } + } + } else { + $r = ($this->Build->IsNotNull() and $this->Revision->IsNull()); //#3 + } + } + } + + return (bool) $r; + } + + /** + * Determina si el objeto $other especificado es igual a la instancia actual. + * + * + * @return bool True si $other es igual esta instancia + * */ + public function Equals($other) { + if ($other instanceof Version) { + if ($this->Major == $other->Major && $this->Minor == $other->Minor) { + if ($this->Build->Equals($other->Build)) { + if ($this->Revision->Equals($other->Revision)) { + return true; + } + } + } + } + + return false; + } + + + #region IComparable + + /** + * Determina la posición relativa del objeto especificado con respecto a esta instancia. + * + * + * @param Version $other + * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. + * */ + public function CompareTo($other){ + + $r = $this->Equals($other) ? 0 : 9999; + + if ($r != 0) { + $r = $this->Major - $other->Major; + + if ($r == 0) { + $r = $this->Minor - $other->Minor; + + if ($r == 0) { + $r = $this->Build->CompareTo($other->Build); + + if ($r == 0) { + $r = $this->Revision->CompareTo($other->Revision); + } + } + } + } + + return $r; + } + + #endregion + + } } From f5c96d6c2edd547d87a5e589a9f9e723b72f1ab6 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 06:17:04 -0430 Subject: [PATCH 13/59] Applied PSR2 corrections to Version class (incomplete). 4 violations left: Method name is not un camel caps format --- src/Version.php | 115 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 21 deletions(-) diff --git a/src/Version.php b/src/Version.php index 06cee57..7304033 100644 --- a/src/Version.php +++ b/src/Version.php @@ -18,6 +18,7 @@ * */ namespace NelsonMartell { + use \InvalidArgumentException; /** @@ -28,7 +29,8 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - final class Version extends Object implements IEquatable, IComparable { + final class Version extends Object implements IEquatable, IComparable + { /** * Crea una nueva instancia con los números principal, secundario, de compilación (opcional) @@ -42,24 +44,69 @@ final class Version extends Object implements IEquatable, IComparable { * @param int|string|VersionComponent|NULL $revision Componente de revisión * @throw InvalidArgumentException * */ - function __construct($major, $minor, $build = null, $revision = null) { + public function __construct($major, $minor, $build = null, $revision = null) + { parent::__construct(); unset($this->Major, $this->Minor, $this->Build, $this->Revision); if (!is_integer($major)) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "major", 1, typeof(0), typeof($major))); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. " . + "Convert value or use the static method Version::parse." + ), + "major", + 1, + typeof(0), + typeof($major) + ) + ); } if (!is_integer($minor)) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. Convert value or use the static method Version::Parse(string|mixed) to create a new instance from an string."), "minor", 2, typeof(0), typeof($major))); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. " . + "Convert value or use the static method Version::parse." + ), + "minor", + 2, + typeof(0), + typeof($minor) + ) + ); } if ($major < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "major", 1, $major)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given." + ), + "major", + 1, + $major + ) + ); } if ($minor < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given."), "minor", 2, $minor)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given." + ), + "minor", + 2, + $minor + ) + ); } $this->_major = $major; @@ -75,7 +122,8 @@ function __construct($major, $minor, $build = null, $revision = null) { * @param string Cadena a convertir. * @return Version Objeto convertido desde $value. * */ - public static function Parse($value) { + public static function parse($value) + { if ($value instanceof Version) { return $value; } @@ -88,7 +136,15 @@ public static function Parse($value) { if ($c > 4 || $c < 2) { //var_dump($version); - throw new InvalidArgumentException(sprintf(dgettext('nml', "Unable to parse. Argument passed has an invalid format: '%s'."), $value)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + "Unable to parse. Argument passed has an invalid format: '%s'." + ), + $value + ) + ); } @@ -97,10 +153,10 @@ public static function Parse($value) { $build = null; $revision = null; - if(count($version) >= 3) { + if (count($version) >= 3) { $build = VersionComponent::Parse($version[2]); - if(count($version) == 4) { + if (count($version) == 4) { $revision = VersionComponent::Parse($version[3]); } } @@ -120,7 +176,10 @@ public static function Parse($value) { public $Major; private $_major; - public function get_Major() { return $this->_major; } + public function get_Major() + { + return $this->_major; + } /** @@ -133,7 +192,10 @@ public function get_Major() { return $this->_major; } public $Minor; private $_minor; - public function get_Minor() { return $this->_minor; } + public function get_Minor() + { + return $this->_minor; + } /** * Obtiene el valor del componente de compilación del número de versión del objeto actual. @@ -145,7 +207,10 @@ public function get_Minor() { return $this->_minor; } public $Build; private $_build; - public function get_Build() { return $this->_build; } + public function get_Build() + { + return $this->_build; + } /** * Obtiene el valor del componente de revisión del número de versión del objeto actual. @@ -157,7 +222,10 @@ public function get_Build() { return $this->_build; } public $Revision; private $_revision; - public function get_Revision() { return $this->_revision; } + public function get_Revision() + { + return $this->_revision; + } /** @@ -171,7 +239,8 @@ public function get_Revision() { return $this->_revision; } * @see VersionComponent::IsNull * @see Version::IsValid * */ - public function ToString() { + public function toString() + { $s[0] = $this->Major; $s[1] = $this->Minor; @@ -202,7 +271,8 @@ public function ToString() { * * @return boolean Un valor que indica si la instancia actual es válida. * */ - public function IsValid() { + public function isValid() + { // Validación de Major y Minor: $r = ($this->Major > 0 or $this->Minor > 0); //#1 @@ -211,12 +281,14 @@ public function IsValid() { $r = ($this->Build->IsNull() and $this->Revision->IsNull()); // #2 if (!$r) { - if ($this->Build->IsNotNull() and $this->Revision->IsNotNull()) { // Si ambos están definidos... + if ($this->Build->IsNotNull() and $this->Revision->IsNotNull()) { + // Si ambos están definidos... $r = (bool)($this->Build->StringValue == ''); //#5 if (!$r) { - $r = (bool)(($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); //#4 + //#4 + $r = (bool)(($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); if (!$r) { if ($this->Build->StringValue != '') { @@ -243,7 +315,8 @@ public function IsValid() { * * @return bool True si $other es igual esta instancia * */ - public function Equals($other) { + public function equals($other) + { if ($other instanceof Version) { if ($this->Major == $other->Major && $this->Minor == $other->Minor) { if ($this->Build->Equals($other->Build)) { @@ -267,7 +340,8 @@ public function Equals($other) { * @param Version $other * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. * */ - public function CompareTo($other){ + public function compareTo($other) + { $r = $this->Equals($other) ? 0 : 9999; @@ -291,6 +365,5 @@ public function CompareTo($other){ } #endregion - } } From 3175fd5885bbaa9b614d4389dbdfc08310eb8ba1 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 06:27:09 -0430 Subject: [PATCH 14/59] Convert tabs indentation to 4 spaces in Asset class. --- src/Utilities/Asset.php | 464 ++++++++++++++++++++-------------------- 1 file changed, 232 insertions(+), 232 deletions(-) diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index f40f742..9875392 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -18,236 +18,236 @@ * */ namespace NelsonMartell\Utilities { - use NelsonMartell\Object; - use NelsonMartell\Version; - use \InvalidArgumentException; - - /** - * Representa un recurso estático de una página, como elementos js y css, que poseen varias - * versiones y están organizadas en subdirectorios, proponiendo una estructura predeterminada. - * Contiene métodos y propiedades para obtener las rutas de los directorios y recursos de las - * diferentes versiones del framework. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class Asset extends Object { - /** - * Crea una nueva instancia de la clase Asset - * - * - * - * */ - public function __construct($name = null, $versions = null, $cdnUri = null) { - parent::__construct(); - unset($this->Name, $this->Versions, $this->ShortName, $this->CdnUri, $this->RootDirectory); - - if ($name == null) { - $this->_name = ''; - $this->_shortName = ''; - } else { - $this->Name = $name; - } - - if ($this->Name == '' && $versions != null) { - throw new InvalidArgumentException(dgettext('nml', 'Can not specify $versions argument if $name argument is null.')); - } - - if ($versions == null) { - $versions = array(); - } - - if (is_array($versions)) { - - $this->_versions = array(); - - if (count($versions) > 0) { - $i = 0; - foreach($versions as $version) { - $v = $version; - if (!($v instanceof Version)) { - try { - $v = Version::Parse($version); - } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$versions argument must be an array of Version objects or any objects parseable into Version.', 0, $e); - } - } - - $this->_versions[$i] = $v; - - $i += 1; - } - } - - } else { - // Trata de convertir $versions en un objeto Versión - try { - $v = Version::Parse($versions); - } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$versions argument must be an array of Version objects (or empty), a Version object or any object parseable into Version.', 0, $e); - } - - $this->_versions = array($v); - } - - $this->CdnUri = $cdnUri; - } - - - /** - * Obtiene o establece el nombre original del recurso. - * A partir de éste se determinará la ruta y el nombre real del archivo (que, por defecto, - * será éste mismo pero convertido en minúsculas y reemplazando sus espacios en blanco por - * guiones (' ' -> '-')). - * - * - * @see $ShortName - * @var string Nombre del recurso - * */ - public $Name; - private $_name; - - public function get_Name() { - return $this->_name; - } - - public function set_Name($value) { - if (!is_string($value)) { - throw new InvalidArgumentException('$value argument must be string.'); - } - - if (str_word_count($value) == 0) { - throw new InvalidArgumentException('$value argument can not be an empty or whitespace string.'); - } - - $this->_name = trim($value); - - $this->_shortName = str_replace(' ', '-', strtolower($this->_name)); - } - - /** - * Obtiene el nombre real del recurso, que representa al nombre real de . - * - * - * @var string Nombre del recurso en su forma generada - * */ - public $ShortName; - private $_shortName; - - public function get_ShortName() { - return $this->_shortName; - } - - /** - * Obtiene la lista de versiones - * - * - * @var List Lista de versiones del recurso - * */ - public $Versions; - private $_versions; - - public function get_Versions() { - return $this->_versions; - } - - /** - * Obtiene o establece el CDN del recurso. - * Debe modificarse la URL, colocando '{v}' en vez de la versión. - * @example Un CDN para el JavaScript de jQuery UI v1.11.2 es: - * "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js" - * Entonces el valor de esta propiedad debe ser: - * "//ajax.googleapis.com/ajax/libs/jqueryui/{v}/jquery-ui" - * - * - * @var string CDN - * */ - public $CdnUri; - private $_cdnUri; - - public function get_CdnUri() { - return $this->_cdnUri; - } - - public function set_CdnUri($value) { - $this->_cdnUri = (string) $value; - } - - - /** - * Obtiene el directorio principal del recurso. - * - * - * @var string Ruta inicial del recurso - * */ - public $RootDirectory; - public function get_RootDirectory() { - return $this->ShortName . '/'; - } - - const NEWEST = 'newest'; - - const OLDEST = 'oldest'; - - /** - * Obtiene la ruta del directorio de la versión especificada. Si no se especifica, - * se devuelve la versión más reciente. - * - * - * @param string|Version $version Versión a obtener. También puede tomar los valores - * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. - * @return string Ruta del directorio de la versión especificada. - * */ - public function GetDirectoryPath($version = self::NEWEST) { - $c = count($this->Versions); - - if ($c == 0) { - throw new LogicException(dgettext('nml', 'Asset has not versions.')); - } - $v = $version; - - if ($version == self::OLDEST or $version == self::NEWEST) { - $v = $this->Versions[0]; - - if ($c > 1) { - usort($this->_versions, array("NelsonMartell\\Version", "Compare")); - - $v = $this->Versions[0]; - - if ($version == self::NEWEST) { - $v = $this->Versions[$c - 1]; - } - } - } else { - try { - $v = Version::Parse($version); - } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$version argument must be an Version object or any object parseable into Version.', 0, $e); - } - - if (array_search($v, $this->Versions) === false) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Asset has not version %s.'), $v)); - } - } - - return sprintf('%s%s/', $this->RootDirectory, $v); - } - - - /** - * Obtiene la ruta del recurso de la versión especificada. Si no se especifica, se devuelve la - * versión más reciente. - * - * @param string|Version $version Versión a obtener. También puede tomar los valores - * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. - * @param string $append Texto que se le anezará a la cadena de salida - * @return string Ruta del recurso - * */ - public function GetResourcePath($version = self::NEWEST, $append = '') { - - $r = sprintf('%s%s%s', $this->GetDirectoryPath($version), $this->ShortName, $append); - - return $r; - } - } + use NelsonMartell\Object; + use NelsonMartell\Version; + use \InvalidArgumentException; + + /** + * Representa un recurso estático de una página, como elementos js y css, que poseen varias + * versiones y están organizadas en subdirectorios, proponiendo una estructura predeterminada. + * Contiene métodos y propiedades para obtener las rutas de los directorios y recursos de las + * diferentes versiones del framework. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + class Asset extends Object { + /** + * Crea una nueva instancia de la clase Asset + * + * + * + * */ + public function __construct($name = null, $versions = null, $cdnUri = null) { + parent::__construct(); + unset($this->Name, $this->Versions, $this->ShortName, $this->CdnUri, $this->RootDirectory); + + if ($name == null) { + $this->_name = ''; + $this->_shortName = ''; + } else { + $this->Name = $name; + } + + if ($this->Name == '' && $versions != null) { + throw new InvalidArgumentException(dgettext('nml', 'Can not specify $versions argument if $name argument is null.')); + } + + if ($versions == null) { + $versions = array(); + } + + if (is_array($versions)) { + + $this->_versions = array(); + + if (count($versions) > 0) { + $i = 0; + foreach($versions as $version) { + $v = $version; + if (!($v instanceof Version)) { + try { + $v = Version::Parse($version); + } catch (InvalidArgumentException $e) { + throw new InvalidArgumentException('$versions argument must be an array of Version objects or any objects parseable into Version.', 0, $e); + } + } + + $this->_versions[$i] = $v; + + $i += 1; + } + } + + } else { + // Trata de convertir $versions en un objeto Versión + try { + $v = Version::Parse($versions); + } catch (InvalidArgumentException $e) { + throw new InvalidArgumentException('$versions argument must be an array of Version objects (or empty), a Version object or any object parseable into Version.', 0, $e); + } + + $this->_versions = array($v); + } + + $this->CdnUri = $cdnUri; + } + + + /** + * Obtiene o establece el nombre original del recurso. + * A partir de éste se determinará la ruta y el nombre real del archivo (que, por defecto, + * será éste mismo pero convertido en minúsculas y reemplazando sus espacios en blanco por + * guiones (' ' -> '-')). + * + * + * @see $ShortName + * @var string Nombre del recurso + * */ + public $Name; + private $_name; + + public function get_Name() { + return $this->_name; + } + + public function set_Name($value) { + if (!is_string($value)) { + throw new InvalidArgumentException('$value argument must be string.'); + } + + if (str_word_count($value) == 0) { + throw new InvalidArgumentException('$value argument can not be an empty or whitespace string.'); + } + + $this->_name = trim($value); + + $this->_shortName = str_replace(' ', '-', strtolower($this->_name)); + } + + /** + * Obtiene el nombre real del recurso, que representa al nombre real de . + * + * + * @var string Nombre del recurso en su forma generada + * */ + public $ShortName; + private $_shortName; + + public function get_ShortName() { + return $this->_shortName; + } + + /** + * Obtiene la lista de versiones + * + * + * @var List Lista de versiones del recurso + * */ + public $Versions; + private $_versions; + + public function get_Versions() { + return $this->_versions; + } + + /** + * Obtiene o establece el CDN del recurso. + * Debe modificarse la URL, colocando '{v}' en vez de la versión. + * @example Un CDN para el JavaScript de jQuery UI v1.11.2 es: + * "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js" + * Entonces el valor de esta propiedad debe ser: + * "//ajax.googleapis.com/ajax/libs/jqueryui/{v}/jquery-ui" + * + * + * @var string CDN + * */ + public $CdnUri; + private $_cdnUri; + + public function get_CdnUri() { + return $this->_cdnUri; + } + + public function set_CdnUri($value) { + $this->_cdnUri = (string) $value; + } + + + /** + * Obtiene el directorio principal del recurso. + * + * + * @var string Ruta inicial del recurso + * */ + public $RootDirectory; + public function get_RootDirectory() { + return $this->ShortName . '/'; + } + + const NEWEST = 'newest'; + + const OLDEST = 'oldest'; + + /** + * Obtiene la ruta del directorio de la versión especificada. Si no se especifica, + * se devuelve la versión más reciente. + * + * + * @param string|Version $version Versión a obtener. También puede tomar los valores + * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. + * @return string Ruta del directorio de la versión especificada. + * */ + public function GetDirectoryPath($version = self::NEWEST) { + $c = count($this->Versions); + + if ($c == 0) { + throw new LogicException(dgettext('nml', 'Asset has not versions.')); + } + $v = $version; + + if ($version == self::OLDEST or $version == self::NEWEST) { + $v = $this->Versions[0]; + + if ($c > 1) { + usort($this->_versions, array("NelsonMartell\\Version", "Compare")); + + $v = $this->Versions[0]; + + if ($version == self::NEWEST) { + $v = $this->Versions[$c - 1]; + } + } + } else { + try { + $v = Version::Parse($version); + } catch (InvalidArgumentException $e) { + throw new InvalidArgumentException('$version argument must be an Version object or any object parseable into Version.', 0, $e); + } + + if (array_search($v, $this->Versions) === false) { + throw new InvalidArgumentException(sprintf(dgettext('nml', 'Asset has not version %s.'), $v)); + } + } + + return sprintf('%s%s/', $this->RootDirectory, $v); + } + + + /** + * Obtiene la ruta del recurso de la versión especificada. Si no se especifica, se devuelve la + * versión más reciente. + * + * @param string|Version $version Versión a obtener. También puede tomar los valores + * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. + * @param string $append Texto que se le anezará a la cadena de salida + * @return string Ruta del recurso + * */ + public function GetResourcePath($version = self::NEWEST, $append = '') { + + $r = sprintf('%s%s%s', $this->GetDirectoryPath($version), $this->ShortName, $append); + + return $r; + } + } } From 48312aff78c0c59f719288bb2e1a76baab4896fb Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:00:13 -0430 Subject: [PATCH 15/59] Applied PSR2 corrections to Asset class (incomplete). Missing: 7 ERRORS AND 4 WARNINGS AFFECTING 11 LINES ---------------------------------------------------------------------- 117 | WARNING | Property name "$_name" should not be prefixed with | | an underscore to indicate visibility 119 | ERROR | Method name "Asset::get_Name" is not in camel caps | | format 124 | ERROR | Method name "Asset::set_Name" is not in camel caps | | format 145 | WARNING | Property name "$_shortName" should not be prefixed | | with an underscore to indicate visibility 147 | ERROR | Method name "Asset::get_ShortName" is not in camel | | caps format 158 | WARNING | Property name "$_versions" should not be prefixed | | with an underscore to indicate visibility 160 | ERROR | Method name "Asset::get_Versions" is not in camel | | caps format 177 | WARNING | Property name "$_cdnUri" should not be prefixed with | | an underscore to indicate visibility 179 | ERROR | Method name "Asset::get_CdnUri" is not in camel caps | | format 184 | ERROR | Method name "Asset::set_CdnUri" is not in camel caps | | format 196 | ERROR | Method name "Asset::get_RootDirectory" is not in | | camel caps format --- src/Utilities/Asset.php | 110 +++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 9875392..4d47e3f 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -11,13 +11,14 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2014, 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Utilities { + use NelsonMartell\Object; use NelsonMartell\Version; use \InvalidArgumentException; @@ -28,17 +29,15 @@ * Contiene métodos y propiedades para obtener las rutas de los directorios y recursos de las * diferentes versiones del framework. * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ - class Asset extends Object { + class Asset extends Object + { /** * Crea una nueva instancia de la clase Asset - * - * - * * */ - public function __construct($name = null, $versions = null, $cdnUri = null) { + public function __construct($name = null, $versions = null, $cdnUri = null) + { parent::__construct(); unset($this->Name, $this->Versions, $this->ShortName, $this->CdnUri, $this->RootDirectory); @@ -50,7 +49,9 @@ public function __construct($name = null, $versions = null, $cdnUri = null) { } if ($this->Name == '' && $versions != null) { - throw new InvalidArgumentException(dgettext('nml', 'Can not specify $versions argument if $name argument is null.')); + throw new InvalidArgumentException( + dgettext('nml', 'Can not specify $versions argument if $name argument is null.') + ); } if ($versions == null) { @@ -58,18 +59,22 @@ public function __construct($name = null, $versions = null, $cdnUri = null) { } if (is_array($versions)) { - $this->_versions = array(); if (count($versions) > 0) { $i = 0; - foreach($versions as $version) { + foreach ($versions as $version) { $v = $version; if (!($v instanceof Version)) { try { $v = Version::Parse($version); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$versions argument must be an array of Version objects or any objects parseable into Version.', 0, $e); + throw new InvalidArgumentException( + '$versions argument must be an array of Version objects ' . + 'or any objects parseable into Version.', + 0, + $e + ); } } @@ -84,7 +89,12 @@ public function __construct($name = null, $versions = null, $cdnUri = null) { try { $v = Version::Parse($versions); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$versions argument must be an array of Version objects (or empty), a Version object or any object parseable into Version.', 0, $e); + throw new InvalidArgumentException( + '$versions argument must be an array of Version objects (or empty), a Version object ' . + 'or any object parseable into Version.', + 0, + $e + ); } $this->_versions = array($v); @@ -100,18 +110,19 @@ public function __construct($name = null, $versions = null, $cdnUri = null) { * será éste mismo pero convertido en minúsculas y reemplazando sus espacios en blanco por * guiones (' ' -> '-')). * - * - * @see $ShortName - * @var string Nombre del recurso + * @see $ShortName + * @var string Nombre del recurso * */ public $Name; private $_name; - public function get_Name() { + public function get_Name() + { return $this->_name; } - public function set_Name($value) { + public function set_Name($value) + { if (!is_string($value)) { throw new InvalidArgumentException('$value argument must be string.'); } @@ -128,48 +139,50 @@ public function set_Name($value) { /** * Obtiene el nombre real del recurso, que representa al nombre real de . * - * - * @var string Nombre del recurso en su forma generada + * @var string Nombre del recurso en su forma generada * */ public $ShortName; private $_shortName; - public function get_ShortName() { + public function get_ShortName() + { return $this->_shortName; } /** * Obtiene la lista de versiones * - * - * @var List Lista de versiones del recurso + * @var List Lista de versiones del recurso * */ public $Versions; private $_versions; - public function get_Versions() { + public function get_Versions() + { return $this->_versions; } /** * Obtiene o establece el CDN del recurso. * Debe modificarse la URL, colocando '{v}' en vez de la versión. - * @example Un CDN para el JavaScript de jQuery UI v1.11.2 es: + * + * @example Un CDN para el JavaScript de jQuery UI v1.11.2 es: * "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js" * Entonces el valor de esta propiedad debe ser: * "//ajax.googleapis.com/ajax/libs/jqueryui/{v}/jquery-ui" * - * - * @var string CDN + * @var string CDN * */ public $CdnUri; private $_cdnUri; - public function get_CdnUri() { + public function get_CdnUri() + { return $this->_cdnUri; } - public function set_CdnUri($value) { + public function set_CdnUri($value) + { $this->_cdnUri = (string) $value; } @@ -177,11 +190,11 @@ public function set_CdnUri($value) { /** * Obtiene el directorio principal del recurso. * - * - * @var string Ruta inicial del recurso + * @var string Ruta inicial del recurso * */ public $RootDirectory; - public function get_RootDirectory() { + public function get_RootDirectory() + { return $this->ShortName . '/'; } @@ -193,12 +206,12 @@ public function get_RootDirectory() { * Obtiene la ruta del directorio de la versión especificada. Si no se especifica, * se devuelve la versión más reciente. * - * - * @param string|Version $version Versión a obtener. También puede tomar los valores - * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. - * @return string Ruta del directorio de la versión especificada. + * @param string|Version $version Versión a obtener. También puede tomar los valores 'newest' u 'oldest' + * para representar a la versión más nueva o más vieja, respectivamente. + * @return string Ruta del directorio de la versión especificada. * */ - public function GetDirectoryPath($version = self::NEWEST) { + public function getDirectoryPath($version = self::NEWEST) + { $c = count($this->Versions); if ($c == 0) { @@ -222,7 +235,11 @@ public function GetDirectoryPath($version = self::NEWEST) { try { $v = Version::Parse($version); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException('$version argument must be an Version object or any object parseable into Version.', 0, $e); + throw new InvalidArgumentException( + '$version argument must be an Version object or any object parseable into Version.', + 0, + $e + ); } if (array_search($v, $this->Versions) === false) { @@ -238,12 +255,13 @@ public function GetDirectoryPath($version = self::NEWEST) { * Obtiene la ruta del recurso de la versión especificada. Si no se especifica, se devuelve la * versión más reciente. * - * @param string|Version $version Versión a obtener. También puede tomar los valores - * 'newest' u 'oldest' para representar a la versión más nueva o más vieja, respectivamente. - * @param string $append Texto que se le anezará a la cadena de salida - * @return string Ruta del recurso + * @param string|Version $version Versión a obtener. También puede tomar los valores 'newest' u 'oldest' para + * representar a la versión más nueva o más vieja, respectivamente. + * @param string $append Texto que se le anezará a la cadena de salida + * @return string Ruta del recurso * */ - public function GetResourcePath($version = self::NEWEST, $append = '') { + public function getResourcePath($version = self::NEWEST, $append = '') + { $r = sprintf('%s%s%s', $this->GetDirectoryPath($version), $this->ShortName, $append); From c17726acbca8fccfc53315a1d87733d586d33561 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:02:54 -0430 Subject: [PATCH 16/59] Convert tabs indentation to 4 spaces in Assert class. --- src/Utilities/UnitTesting/Assert.php | 418 +++++++++++++-------------- 1 file changed, 209 insertions(+), 209 deletions(-) diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index 385acc2..65d368b 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -18,253 +18,253 @@ * */ namespace NelsonMartell\Utilities\UnitTesting { - use NelsonMartell\Object; - use NelsonMartell\Version; - use \Exception; - - /** - * Comprueba condiciones de pruebas. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - final class Assert { - - private static function Equals($expected, $actual) { - if ($expected === $actual) { - return true; - } - - if ($expected instanceof Object || $expected instanceof IEquatable) { - if ($expected->Equals($actual)) { - return true; - } - } else { - if ($expected == $actual) { - return true; - } - } + use NelsonMartell\Object; + use NelsonMartell\Version; + use \Exception; + + /** + * Comprueba condiciones de pruebas. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + final class Assert { + + private static function Equals($expected, $actual) { + if ($expected === $actual) { + return true; + } + + if ($expected instanceof Object || $expected instanceof IEquatable) { + if ($expected->Equals($actual)) { + return true; + } + } else { + if ($expected == $actual) { + return true; + } + } - return false; - } + return false; + } - /** - * Comprueba si los dos objetos especificados son iguales. Caso contrario, emite una - * advertencia. - * - * - * @param string $msg Custom message to append on assert failed. - * @return boolean true si son iguales; false, en caso contrario. - * */ - public static function AreEqual($expected, $actual, $msg = '') { - - $equals = self::Equals($expected, $actual); - - if (!$equals) { - $a_string = $actual; - $e_string = $expected; - - if (is_array($actual)) { - $a_string = implode(', ', $actual); - } - - if (is_array($expected)) { - $e_string = implode(', ', $expected); - } - - if (is_bool($actual)) { - $a_string = $actual ? 'true' : 'false'; - } - - if (is_bool($expected)) { - $e_string = $expected ? 'true' : 'false'; - } - - $error = sprintf(dgettext('nml', '%5$s failed. Expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), typeof($actual), $a_string, typeof($expected), $e_string, __METHOD__); - - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } - - trigger_error($error, E_USER_WARNING); - } - - return $equals; - } - - - - /** - * Comprueba si los dos objetos especificados NO son iguales. En caso de que sí lo sean, - * emite una advertencia. - * - * - * @param string $msg Custom message to append on assert failed. - * @return boolean true si NO son iguales; false, en caso contrario. - * */ - public static function AreNotEqual($notExpected, $actual, $msg = '') { - $not_equals = !self::Equals($notExpected, $actual); - - if (!$not_equals) { - $a_string = $actual; - $ne_string = $notExpected; - - if (is_array($actual)) { - $a_string = implode(', ', $actual); - } - - if (is_array($notExpected)) { - $ne_string = implode(', ', $notExpected); - } - - if (is_bool($actual)) { - $a_string = $actual ? 'true' : 'false'; - } + /** + * Comprueba si los dos objetos especificados son iguales. Caso contrario, emite una + * advertencia. + * + * + * @param string $msg Custom message to append on assert failed. + * @return boolean true si son iguales; false, en caso contrario. + * */ + public static function AreEqual($expected, $actual, $msg = '') { + + $equals = self::Equals($expected, $actual); + + if (!$equals) { + $a_string = $actual; + $e_string = $expected; + + if (is_array($actual)) { + $a_string = implode(', ', $actual); + } + + if (is_array($expected)) { + $e_string = implode(', ', $expected); + } + + if (is_bool($actual)) { + $a_string = $actual ? 'true' : 'false'; + } + + if (is_bool($expected)) { + $e_string = $expected ? 'true' : 'false'; + } + + $error = sprintf(dgettext('nml', '%5$s failed. Expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), typeof($actual), $a_string, typeof($expected), $e_string, __METHOD__); + + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } + + trigger_error($error, E_USER_WARNING); + } + + return $equals; + } + + + + /** + * Comprueba si los dos objetos especificados NO son iguales. En caso de que sí lo sean, + * emite una advertencia. + * + * + * @param string $msg Custom message to append on assert failed. + * @return boolean true si NO son iguales; false, en caso contrario. + * */ + public static function AreNotEqual($notExpected, $actual, $msg = '') { + $not_equals = !self::Equals($notExpected, $actual); + + if (!$not_equals) { + $a_string = $actual; + $ne_string = $notExpected; + + if (is_array($actual)) { + $a_string = implode(', ', $actual); + } + + if (is_array($notExpected)) { + $ne_string = implode(', ', $notExpected); + } + + if (is_bool($actual)) { + $a_string = $actual ? 'true' : 'false'; + } - if (is_bool($notExpected)) { - $ne_string = $notExpected ? 'true' : 'false'; - } + if (is_bool($notExpected)) { + $ne_string = $notExpected ? 'true' : 'false'; + } - $error = sprintf(dgettext('nml', '%5$s failed. Not expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), Type::typeof($actual), $a_string, Type::typeof($notExpected), $ne_string, __METHOD__); + $error = sprintf(dgettext('nml', '%5$s failed. Not expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), Type::typeof($actual), $a_string, Type::typeof($notExpected), $ne_string, __METHOD__); - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } - - trigger_error($error, E_USER_WARNING); - } + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } + + trigger_error($error, E_USER_WARNING); + } - return $not_equals; - } + return $not_equals; + } - public static function IsTrue($actual) { - return self::AreEqual(true, $actual); - } + public static function IsTrue($actual) { + return self::AreEqual(true, $actual); + } - public static function IsFalse($actual) { - return self::AreEqual(false, $actual); - } + public static function IsFalse($actual) { + return self::AreEqual(false, $actual); + } - /** - * Comprueba que, si al llamar un método público de un objeto, se obtiene una excepción del - * tipo especificado. - * - * - * @param string $method_name Method name. - * @param mixed $obj Object to check. - * @param array $params Method params. - * @param Exception $expectedException Exception to check type. If null, checks any. - * @param string $msg Custom message to append on assert failed. - * @return boolean - * */ - public static function MethodThrowsException($method_name, $obj, $params = array(), Exception $expectedException = null, $msg = '') { + /** + * Comprueba que, si al llamar un método público de un objeto, se obtiene una excepción del + * tipo especificado. + * + * + * @param string $method_name Method name. + * @param mixed $obj Object to check. + * @param array $params Method params. + * @param Exception $expectedException Exception to check type. If null, checks any. + * @param string $msg Custom message to append on assert failed. + * @return boolean + * */ + public static function MethodThrowsException($method_name, $obj, $params = array(), Exception $expectedException = null, $msg = '') { - $equals = false; + $equals = false; - $expected = typeof($expectedException); - $actual = typeof(null); + $expected = typeof($expectedException); + $actual = typeof(null); - try { - call_user_func_array(array($obj, $method_name), $params); - } catch (Exception $e) { - $actual = typeof($e); - } + try { + call_user_func_array(array($obj, $method_name), $params); + } catch (Exception $e) { + $actual = typeof($e); + } - if ($actual->IsNotNull()) { - // Se lanzó la excepción... - if ($expected->IsNull()) { - // ...pero no se especificó el tipo de excepción, es decir, puede ser cualquiera - $equals = true; - } else { - // ...pero debe comprobarse si son del mismo tipo: - $equals = self::Equals($expected, $actual); + if ($actual->IsNotNull()) { + // Se lanzó la excepción... + if ($expected->IsNull()) { + // ...pero no se especificó el tipo de excepción, es decir, puede ser cualquiera + $equals = true; + } else { + // ...pero debe comprobarse si son del mismo tipo: + $equals = self::Equals($expected, $actual); - if (!$equals) { - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + if (!$equals) { + $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } - trigger_error($error, E_USER_WARNING); - } - } - } else { - // No se lanzó la excepción - $actual = "No exception"; + trigger_error($error, E_USER_WARNING); + } + } + } else { + // No se lanzó la excepción + $actual = "No exception"; - if ($expected->IsNull()) { - $expected = "Any exception"; - } + if ($expected->IsNull()) { + $expected = "Any exception"; + } - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } - trigger_error($error, E_USER_WARNING); - } + trigger_error($error, E_USER_WARNING); + } - return $equals; - } + return $equals; + } - public static function PropertyThrowsException($obj, $property_name, $value, Exception $expectedException = null, $msg = '') { - $equals = false; + public static function PropertyThrowsException($obj, $property_name, $value, Exception $expectedException = null, $msg = '') { + $equals = false; - $expected = typeof($expectedException); - $actual = typeof(null); + $expected = typeof($expectedException); + $actual = typeof(null); - try { - $obj->$property_name = $value; - } catch (Exception $e) { - $actual = typeof($e); - } + try { + $obj->$property_name = $value; + } catch (Exception $e) { + $actual = typeof($e); + } - if ($actual->IsNotNull()) { - // Se lanzó la excepción... - if ($expected->IsNull()) { - // ...pero no se especificó el tipo de excepción, es decir, puede ser cualquiera - $equals = true; - } else { - // ...pero debe comprobarse si son del mismo tipo: - $equals = self::Equals($expected, $actual); + if ($actual->IsNotNull()) { + // Se lanzó la excepción... + if ($expected->IsNull()) { + // ...pero no se especificó el tipo de excepción, es decir, puede ser cualquiera + $equals = true; + } else { + // ...pero debe comprobarse si son del mismo tipo: + $equals = self::Equals($expected, $actual); - if (!$equals) { - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + if (!$equals) { + $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } - trigger_error($error, E_USER_WARNING); - } - } - } else { - // No se lanzó la excepción - $actual = "No exception"; + trigger_error($error, E_USER_WARNING); + } + } + } else { + // No se lanzó la excepción + $actual = "No exception"; - if ($expected->IsNull()) { - $expected = "Any exception"; - } + if ($expected->IsNull()) { + $expected = "Any exception"; + } - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); - if ($msg) { - $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); - } + if ($msg) { + $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); + } - trigger_error($error, E_USER_WARNING); - } + trigger_error($error, E_USER_WARNING); + } - return $equals; - } + return $equals; + } - } + } } From 8c58aac22a83e8aff98dcc072b3259124b18fbb4 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:15:02 -0430 Subject: [PATCH 17/59] Applied PSR2 corrections to Assert class. --- src/Utilities/UnitTesting/Assert.php | 86 ++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index 65d368b..9d2b0a0 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -18,6 +18,7 @@ * */ namespace NelsonMartell\Utilities\UnitTesting { + use NelsonMartell\Object; use NelsonMartell\Version; use \Exception; @@ -28,9 +29,11 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - final class Assert { + final class Assert + { - private static function Equals($expected, $actual) { + private static function equals($expected, $actual) + { if ($expected === $actual) { return true; } @@ -57,7 +60,8 @@ private static function Equals($expected, $actual) { * @param string $msg Custom message to append on assert failed. * @return boolean true si son iguales; false, en caso contrario. * */ - public static function AreEqual($expected, $actual, $msg = '') { + public static function areEqual($expected, $actual, $msg = '') + { $equals = self::Equals($expected, $actual); @@ -81,7 +85,14 @@ public static function AreEqual($expected, $actual, $msg = '') { $e_string = $expected ? 'true' : 'false'; } - $error = sprintf(dgettext('nml', '%5$s failed. Expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), typeof($actual), $a_string, typeof($expected), $e_string, __METHOD__); + $error = sprintf( + dgettext('nml', '%5$s failed. Expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), + typeof($actual), + $a_string, + typeof($expected), + $e_string, + __METHOD__ + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -103,7 +114,8 @@ public static function AreEqual($expected, $actual, $msg = '') { * @param string $msg Custom message to append on assert failed. * @return boolean true si NO son iguales; false, en caso contrario. * */ - public static function AreNotEqual($notExpected, $actual, $msg = '') { + public static function areNotEqual($notExpected, $actual, $msg = '') + { $not_equals = !self::Equals($notExpected, $actual); if (!$not_equals) { @@ -126,7 +138,14 @@ public static function AreNotEqual($notExpected, $actual, $msg = '') { $ne_string = $notExpected ? 'true' : 'false'; } - $error = sprintf(dgettext('nml', '%5$s failed. Not expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), Type::typeof($actual), $a_string, Type::typeof($notExpected), $ne_string, __METHOD__); + $error = sprintf( + dgettext('nml', '%5$s failed. Not expected: (%3$s) "%4$s". Actual: (%1$s) "%2$s".'), + Type::typeof($actual), + $a_string, + Type::typeof($notExpected), + $ne_string, + __METHOD__ + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -139,12 +158,14 @@ public static function AreNotEqual($notExpected, $actual, $msg = '') { } - public static function IsTrue($actual) { - return self::AreEqual(true, $actual); + public static function isTrue($actual) + { + return self::areEqual(true, $actual); } - public static function IsFalse($actual) { - return self::AreEqual(false, $actual); + public static function isFalse($actual) + { + return self::areEqual(false, $actual); } /** @@ -159,7 +180,13 @@ public static function IsFalse($actual) { * @param string $msg Custom message to append on assert failed. * @return boolean * */ - public static function MethodThrowsException($method_name, $obj, $params = array(), Exception $expectedException = null, $msg = '') { + public static function methodThrowsException( + $method_name, + $obj, + $params = array(), + Exception $expectedException = null, + $msg = '' + ) { $equals = false; @@ -182,7 +209,12 @@ public static function MethodThrowsException($method_name, $obj, $params = array $equals = self::Equals($expected, $actual); if (!$equals) { - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf( + dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), + __METHOD__, + $expected, + $actual + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -199,7 +231,12 @@ public static function MethodThrowsException($method_name, $obj, $params = array $expected = "Any exception"; } - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf( + dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), + __METHOD__, + $expected, + $actual + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -214,7 +251,13 @@ public static function MethodThrowsException($method_name, $obj, $params = array - public static function PropertyThrowsException($obj, $property_name, $value, Exception $expectedException = null, $msg = '') { + public static function propertyThrowsException( + $obj, + $property_name, + $value, + Exception $expectedException = null, + $msg = '' + ) { $equals = false; $expected = typeof($expectedException); @@ -236,7 +279,12 @@ public static function PropertyThrowsException($obj, $property_name, $value, Exc $equals = self::Equals($expected, $actual); if (!$equals) { - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf( + dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), + __METHOD__, + $expected, + $actual + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -253,7 +301,12 @@ public static function PropertyThrowsException($obj, $property_name, $value, Exc $expected = "Any exception"; } - $error = sprintf(dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), __METHOD__, $expected, $actual); + $error = sprintf( + dgettext('nml', '%1$s failed. Expected: "%2$s". Actual: "%3$s".'), + __METHOD__, + $expected, + $actual + ); if ($msg) { $error .= ' ' . sprintf(dgettext('nml', 'Message: %s'), $msg); @@ -265,6 +318,5 @@ public static function PropertyThrowsException($obj, $property_name, $value, Exc return $equals; } - } } From 399aeebe33c67e276b33137271776680aae53041 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:17:33 -0430 Subject: [PATCH 18/59] Convert tabs indentation to 4 spaces in Extensions\String class. --- src/Extensions/String.php | 78 +++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index ddc799b..3c0c434 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -27,45 +27,45 @@ * */ class String extends \Cake\Utility\Text { - /** - * Replaces format elements in a string with the string representation of an object matching the - * list of arguments specified. You can give as many params as you need, or an array with values. - * - * ##Usage - * Using numbers as placeholders (encloses between `{` and `}`), you can get the matching string - * representation of each object given. Use `{0}` for the fist object, `{1}` for the second, - * and so on. - * Example: `String::Format('{0} is {1} years old, and have {2} cats.', 'Bob', 65, 101);` - * Returns: 'Bob is 65 years old, and have 101 cats.' - * - * You can also use an array to give objects values. - * Example: `String::Format('{0} is {1} years old.', ['Bob', 65, 101]);` - * Returns: 'Bob is 65 years old, and have 101 cats.' - * - * If give an key => value array, each key stands for a placeholder variable name to be replaced - * with value key. In this case, order of keys do not matter. - * Example: - * `$arg0 = ['name' => 'Bob', 'n' => 101, 'age' => 65];` - * `$format = '{name} is {age} years old, and have {n} cats.';` - * `String::Format($format, $arg0);` - * Returns: 'Bob is 65 years old, and have 101 cats.' - * - * - * @param string $format A string containing variable placeholders. - * @param array|mixed $args Object(s) to be replaced into $format placeholders. - * @return string - * @todo Implement php.net/functions.arguments.html#functions.variable-arg-list.new for PHP 5.6+ - * @todo Implement formatting, like IFormatProvider or something like that. - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - */ - public static function Format($format, $args) { - static $options = [ - 'before' => '{', - 'after' => '}', - ]; + /** + * Replaces format elements in a string with the string representation of an object matching the + * list of arguments specified. You can give as many params as you need, or an array with values. + * + * ##Usage + * Using numbers as placeholders (encloses between `{` and `}`), you can get the matching string + * representation of each object given. Use `{0}` for the fist object, `{1}` for the second, + * and so on. + * Example: `String::Format('{0} is {1} years old, and have {2} cats.', 'Bob', 65, 101);` + * Returns: 'Bob is 65 years old, and have 101 cats.' + * + * You can also use an array to give objects values. + * Example: `String::Format('{0} is {1} years old.', ['Bob', 65, 101]);` + * Returns: 'Bob is 65 years old, and have 101 cats.' + * + * If give an key => value array, each key stands for a placeholder variable name to be replaced + * with value key. In this case, order of keys do not matter. + * Example: + * `$arg0 = ['name' => 'Bob', 'n' => 101, 'age' => 65];` + * `$format = '{name} is {age} years old, and have {n} cats.';` + * `String::Format($format, $arg0);` + * Returns: 'Bob is 65 years old, and have 101 cats.' + * + * + * @param string $format A string containing variable placeholders. + * @param array|mixed $args Object(s) to be replaced into $format placeholders. + * @return string + * @todo Implement php.net/functions.arguments.html#functions.variable-arg-list.new for PHP 5.6+ + * @todo Implement formatting, like IFormatProvider or something like that. + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + */ + public static function Format($format, $args) { + static $options = [ + 'before' => '{', + 'after' => '}', + ]; - $data = func_num_args() === 2 ? (array) $args : array_slice(func_get_args(), 1); + $data = func_num_args() === 2 ? (array) $args : array_slice(func_get_args(), 1); - return parent::insert($format, $data, $options); - } + return parent::insert($format, $data, $options); + } } From f30a693af926a77596b97db96bc13c5759586937 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:20:42 -0430 Subject: [PATCH 19/59] Applied PSR2 corrections to Extensions\String class. --- src/Extensions/String.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 3c0c434..641a435 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -25,7 +25,8 @@ * @copyright This class is based on Cake\Utility\String of CakePHP(tm) class. * @see Original DOC of String based on: http://book.cakephp.org/3.0/en/core-libraries/string.html * */ -class String extends \Cake\Utility\Text { +class String extends \Cake\Utility\Text +{ /** * Replaces format elements in a string with the string representation of an object matching the @@ -58,7 +59,8 @@ class String extends \Cake\Utility\Text { * @todo Implement formatting, like IFormatProvider or something like that. * @author Nelson Martell (nelson6e65-dev@yahoo.es) */ - public static function Format($format, $args) { + public static function format($format, $args) + { static $options = [ 'before' => '{', 'after' => '}', From 8673ccb7ba3dff4c516a7189655ddad4dda68121 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:27:31 -0430 Subject: [PATCH 20/59] Convert tabs indentation to 4 spaces in Collections/* classes. --- src/Collections/Collection.php | 572 ++++++++++++++++---------------- src/Collections/ICollection.php | 106 +++--- src/Collections/IList.php | 68 ++-- 3 files changed, 373 insertions(+), 373 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index c8abced..accabcd 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -19,290 +19,290 @@ * */ namespace NelsonMartell\Collections { - use NelsonMartell\Object; - use NelsonMartell\Extensions\String; - - /** - * Implementa los métodos de la interfaz Iterator para una colección de objetos. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * @since v0.4.0 - * */ - trait CollectionIterator { - private $_iteratorPosition = 0; - - public function current() { - return $this->GetItem($this->_iteratorPosition); - } - - public function rewind() { - $this->_iteratorPosition = 0; - } - - public function key() { - return $this->_iteratorPosition; - } - - public function next() { - ++$this->_iteratorPosition; - } - - public function valid() { - $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); - return $v; - } - - protected abstract function GetItem($index); - } - - /** - * Clase base de una colección de objetos, que provee una implementación predeterminada de la - * interfaz ICollection. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - class Collection extends Object implements ICollection { - use CollectionIterator; //Implementación de la interfaz Iterator - - function __construct() { - parent::__construct(); - unset($this->Count); - } - - public final function __invoke($index, $value = null) { - if ($value == null) { - return $this->_items[$index]; - } - - $this->SetItem($index, $value); - } - - private $_items = array(); - - - /** - * Inserta un nuevo elemento a la colección, en el índice especificado. - * - * @param integer $index Índice del elemento a insertar. - * @param mixed $newItem Nuevo elemento a insertar a la colección. - * @access protected - * @return void - * */ - protected function InsertItem($index, $newItem) { - if ($index > $this->Count || $index < 0) { - throw new OutOfRangeException(); - } - - if ($index == $this->Count){ - $this->_items[$index] = null; - $this->_count++; - } - - $this->_items[$index] = $newItem; - } - - /** - * Quita todos los elementos de la colección. - * - * @return void - * */ - protected function ClearItems() { - $this->_items = array(); - $this->_count = 0; - } - - /** - * Establece un elemento en el índice especificado. - * - * @param integer $index Índice del elemento a establecer. - * @param mixed $newItem Nuevo valor con el que se va a reemplazar. - * @return void - * */ - protected function SetItem($index, $newItem) { - if ($index >= $this->Count || $index < 0) { - throw new OutOfRangeException(); - } - - $this->_items[$index] = $newItem; - } - - /** - * Obtiene el elemento almacenado en el índice especificado. - * Este método no lanza excepción en caso de indicar un índice fuera del rango; en cambio, - * devuelve NULL. - * El elemento obtenido es de sólo lectura. Para modificar el elemento dentro de la colección, - * tendría que utilizarse el método Collection::SetItem una vez modificado. - * - * @param integer $index Índice del elemento a obtener. - * @return mixed - * */ - protected function GetItem($index) { - if ($index >= $this->Count || $index < 0) { - return null; - } - - return $this->_items[$index]; - } - - protected function RemoveItem($index) { - if ($index >= $this->Count || $index < 0) { - throw new OutOfRangeException(); - } - - for($i = $index; $i < $this->Count - 1; $i++) { - $this->_items[$i] = $this->_items[$i + 1]; //Mueve los valores - } - - unset($this->_items[$this->Count - 1]); //Des-asigna el último elemento - - $this->_count--; - } - - /** - * Gets the string representation of this object collection. - * - * You can format the output, by setting $format param to one of this options: - * - `R` or `r`: All items, separated by comma and space (`, `). This is the default format. - * - `L` or `l`: Same as `r` option, but enclosed in braces (`{`, `}`). - * - `g`: A full string, containing class name, items count and items list (this list, like `L` option). - * - `G`: Same as `g`, but using a full class name (including namespace). - * - * You can also use a custom format instead, using this placeholders: - * - `{class}`: Short class name (without namespace part); - * - `{nsclass}`: Full class name (included namespace); - * - `{count}`: Items count; and - * - `{items}`: List of items, using comma and space (`, `) as separator. - * - * Example: For a instance with 10 elements (numbers: 1-10), using: - * `Collection::ToString('My collection ({count} items): { {items} }');` - * Result: 'My collection (10 items): { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }' - * - * - * @param string $format String format (optional). By default, `r`. - * @return string - * @see String::Format() - * */ - public function ToString($format = 'r') { - static $defaultFormats = [ - 'r' => '{items}', - 'l' => '{ {items} }', - 'g' => '{class} ({count} items): { {items} }', - 'G' => '{nsclass} ({count} items): { {items} }', - ]; - - if ($format == null or !is_string($format)) { - $format = 'r'; //Override if is not an string - } - - $str = ''; - switch ($format) { - case 'r': - case 'l': - case 'g': - case 'G': - $str = $defaultFormats[$format]; - break; - - default: - $str = $format; - } - - $t = $this->GetType(); - - $items = implode(', ', $this->_items); - - $placeHoldersValues = [ - 'class' => $t->ShortName, - 'nsclass' => $t->Name, - 'count' => $this->Count, - 'items' => $items, - ]; - - - $s = String::Format($str, $placeHoldersValues); - - return $s; - } - - - #region {Implementación de la interfaz ICollection} - - /** - * Obtiene el número de elementos incluidos en la colección. - * Ésta propiedad es de sólo lectura. - * - * @var integer - * */ - public $Count; - private $_count = 0; - - /** - * Obtiene el número de elementos incluidos en la colección. - * - * @return integer - * */ - public function get_Count() { - return $this->_count; - } - - /** - * Agrega un nuevo elemento al final de la colección. - * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien - * el método protegido 'InsertItem'. - * - * @param mixed Elemento que se va a agregar a la colección. - * @return void - * */ - public function Add($item) { - $this->InsertItem($this->Count, $item); - } - - /** - * Quita todos los elementos de la colección. - * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien - * el método protegido 'ClearItems'. - * - * @return void - * */ - public function Clear() { - $this->ClearItems(); - } - - /** - * Determina si la colección contiene al elemento especificado. - * - * @param mixed $item Objeto que se va a buscar. - * @return boolean true si $item se encuentra; en caso contrario, false. - * */ - public function Contains($item) { - foreach($this->_items as $i) { - if ($item === $i) { - return true; - } - } - - return false; - } - - /** - * Quita, si existe, la primera aparición de un objeto específico de la colección. - * - * @param mixed $item Objeto que se va a quitar. - * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. - * Este método también devuelve false si no se encontró $item. - * */ - public function Remove($item) { - for ($i = 0; $i < $this->Count; $i++) { - if ($this->_items[$i] === $item) { - $this->RemoveItem($i); - } - } - - return false; - } - - #end region - - - } + use NelsonMartell\Object; + use NelsonMartell\Extensions\String; + + /** + * Implementa los métodos de la interfaz Iterator para una colección de objetos. + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @since v0.4.0 + * */ + trait CollectionIterator { + private $_iteratorPosition = 0; + + public function current() { + return $this->GetItem($this->_iteratorPosition); + } + + public function rewind() { + $this->_iteratorPosition = 0; + } + + public function key() { + return $this->_iteratorPosition; + } + + public function next() { + ++$this->_iteratorPosition; + } + + public function valid() { + $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); + return $v; + } + + protected abstract function GetItem($index); + } + + /** + * Clase base de una colección de objetos, que provee una implementación predeterminada de la + * interfaz ICollection. + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + class Collection extends Object implements ICollection { + use CollectionIterator; //Implementación de la interfaz Iterator + + function __construct() { + parent::__construct(); + unset($this->Count); + } + + public final function __invoke($index, $value = null) { + if ($value == null) { + return $this->_items[$index]; + } + + $this->SetItem($index, $value); + } + + private $_items = array(); + + + /** + * Inserta un nuevo elemento a la colección, en el índice especificado. + * + * @param integer $index Índice del elemento a insertar. + * @param mixed $newItem Nuevo elemento a insertar a la colección. + * @access protected + * @return void + * */ + protected function InsertItem($index, $newItem) { + if ($index > $this->Count || $index < 0) { + throw new OutOfRangeException(); + } + + if ($index == $this->Count){ + $this->_items[$index] = null; + $this->_count++; + } + + $this->_items[$index] = $newItem; + } + + /** + * Quita todos los elementos de la colección. + * + * @return void + * */ + protected function ClearItems() { + $this->_items = array(); + $this->_count = 0; + } + + /** + * Establece un elemento en el índice especificado. + * + * @param integer $index Índice del elemento a establecer. + * @param mixed $newItem Nuevo valor con el que se va a reemplazar. + * @return void + * */ + protected function SetItem($index, $newItem) { + if ($index >= $this->Count || $index < 0) { + throw new OutOfRangeException(); + } + + $this->_items[$index] = $newItem; + } + + /** + * Obtiene el elemento almacenado en el índice especificado. + * Este método no lanza excepción en caso de indicar un índice fuera del rango; en cambio, + * devuelve NULL. + * El elemento obtenido es de sólo lectura. Para modificar el elemento dentro de la colección, + * tendría que utilizarse el método Collection::SetItem una vez modificado. + * + * @param integer $index Índice del elemento a obtener. + * @return mixed + * */ + protected function GetItem($index) { + if ($index >= $this->Count || $index < 0) { + return null; + } + + return $this->_items[$index]; + } + + protected function RemoveItem($index) { + if ($index >= $this->Count || $index < 0) { + throw new OutOfRangeException(); + } + + for($i = $index; $i < $this->Count - 1; $i++) { + $this->_items[$i] = $this->_items[$i + 1]; //Mueve los valores + } + + unset($this->_items[$this->Count - 1]); //Des-asigna el último elemento + + $this->_count--; + } + + /** + * Gets the string representation of this object collection. + * + * You can format the output, by setting $format param to one of this options: + * - `R` or `r`: All items, separated by comma and space (`, `). This is the default format. + * - `L` or `l`: Same as `r` option, but enclosed in braces (`{`, `}`). + * - `g`: A full string, containing class name, items count and items list (this list, like `L` option). + * - `G`: Same as `g`, but using a full class name (including namespace). + * + * You can also use a custom format instead, using this placeholders: + * - `{class}`: Short class name (without namespace part); + * - `{nsclass}`: Full class name (included namespace); + * - `{count}`: Items count; and + * - `{items}`: List of items, using comma and space (`, `) as separator. + * + * Example: For a instance with 10 elements (numbers: 1-10), using: + * `Collection::ToString('My collection ({count} items): { {items} }');` + * Result: 'My collection (10 items): { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }' + * + * + * @param string $format String format (optional). By default, `r`. + * @return string + * @see String::Format() + * */ + public function ToString($format = 'r') { + static $defaultFormats = [ + 'r' => '{items}', + 'l' => '{ {items} }', + 'g' => '{class} ({count} items): { {items} }', + 'G' => '{nsclass} ({count} items): { {items} }', + ]; + + if ($format == null or !is_string($format)) { + $format = 'r'; //Override if is not an string + } + + $str = ''; + switch ($format) { + case 'r': + case 'l': + case 'g': + case 'G': + $str = $defaultFormats[$format]; + break; + + default: + $str = $format; + } + + $t = $this->GetType(); + + $items = implode(', ', $this->_items); + + $placeHoldersValues = [ + 'class' => $t->ShortName, + 'nsclass' => $t->Name, + 'count' => $this->Count, + 'items' => $items, + ]; + + + $s = String::Format($str, $placeHoldersValues); + + return $s; + } + + + #region {Implementación de la interfaz ICollection} + + /** + * Obtiene el número de elementos incluidos en la colección. + * Ésta propiedad es de sólo lectura. + * + * @var integer + * */ + public $Count; + private $_count = 0; + + /** + * Obtiene el número de elementos incluidos en la colección. + * + * @return integer + * */ + public function get_Count() { + return $this->_count; + } + + /** + * Agrega un nuevo elemento al final de la colección. + * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien + * el método protegido 'InsertItem'. + * + * @param mixed Elemento que se va a agregar a la colección. + * @return void + * */ + public function Add($item) { + $this->InsertItem($this->Count, $item); + } + + /** + * Quita todos los elementos de la colección. + * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien + * el método protegido 'ClearItems'. + * + * @return void + * */ + public function Clear() { + $this->ClearItems(); + } + + /** + * Determina si la colección contiene al elemento especificado. + * + * @param mixed $item Objeto que se va a buscar. + * @return boolean true si $item se encuentra; en caso contrario, false. + * */ + public function Contains($item) { + foreach($this->_items as $i) { + if ($item === $i) { + return true; + } + } + + return false; + } + + /** + * Quita, si existe, la primera aparición de un objeto específico de la colección. + * + * @param mixed $item Objeto que se va a quitar. + * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. + * Este método también devuelve false si no se encontró $item. + * */ + public function Remove($item) { + for ($i = 0; $i < $this->Count; $i++) { + if ($this->_items[$i] === $item) { + $this->RemoveItem($i); + } + } + + return false; + } + + #end region + + + } } diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index e42ff68..7acceb2 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -18,64 +18,64 @@ * */ namespace NelsonMartell\Collections { - use \Iterator; + use \Iterator; - /** - * Define métodos para manipular colecciones de objetos. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - interface ICollection extends Iterator { + /** + * Define métodos para manipular colecciones de objetos. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + interface ICollection extends Iterator { - /** - * Obtiene el número de elementos incluidos en la colección. - * Si extiende la clase NelsonMartell.Object, debe definirse la propiedad 'public $Count'. - * - * - * @see NelsonMartell\Object - * @return integer - * */ - public function get_Count(); + /** + * Obtiene el número de elementos incluidos en la colección. + * Si extiende la clase NelsonMartell.Object, debe definirse la propiedad 'public $Count'. + * + * + * @see NelsonMartell\Object + * @return integer + * */ + public function get_Count(); - /** - * Agrega un elemento a la colección. - * - * - * @param mixed $item Objeto que se va a agregar. - * @return void - * */ - public function Add($item); + /** + * Agrega un elemento a la colección. + * + * + * @param mixed $item Objeto que se va a agregar. + * @return void + * */ + public function Add($item); - /** - * Quita todos los elementos de la colección. - * - * - * La propiedad Count se debe establecer en 0 y deben liberarse las referencias a otros - * objetos desde los elementos de la colección. - * - * @return void - * */ - public function Clear(); + /** + * Quita todos los elementos de la colección. + * + * + * La propiedad Count se debe establecer en 0 y deben liberarse las referencias a otros + * objetos desde los elementos de la colección. + * + * @return void + * */ + public function Clear(); - /** - * Determina si la colección contiene un valor específico. - * - * - * @param mixed $item Objeto que se va a buscar. - * @return boolean true si $item se encuentra; en caso contrario, false. - * */ - public function Contains($item); + /** + * Determina si la colección contiene un valor específico. + * + * + * @param mixed $item Objeto que se va a buscar. + * @return boolean true si $item se encuentra; en caso contrario, false. + * */ + public function Contains($item); - /** - * Quita la primera aparición de un objeto específico de la colección. - * - * - * @param $item Objeto que se va a quitar. - * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. - * Este método también devuelve false si no se encontró $item. - * */ - public function Remove($item); + /** + * Quita la primera aparición de un objeto específico de la colección. + * + * + * @param $item Objeto que se va a quitar. + * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. + * Este método también devuelve false si no se encontró $item. + * */ + public function Remove($item); - } + } } diff --git a/src/Collections/IList.php b/src/Collections/IList.php index 3086754..64a6b99 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -19,42 +19,42 @@ namespace NelsonMartell\Collections { - /** - * Representa una colección de objetos a los que se puede tener acceso por un índice. - * - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * */ - interface IList extends ICollection { + /** + * Representa una colección de objetos a los que se puede tener acceso por un índice. + * + * + * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * */ + interface IList extends ICollection { - /** - * Determina el índice de un elemento específico de la lista. - * Si un objeto aparece varias veces en la lista, el método IndexOf siempre devolverá la - * primera instancia encontrada. - * - * - * @param mixed $item Objeto que se va a buscar. - * @return integer Índice de $item si se encuentra en la lista; en caso contrario, -1. - * */ - public function IndexOf($item); + /** + * Determina el índice de un elemento específico de la lista. + * Si un objeto aparece varias veces en la lista, el método IndexOf siempre devolverá la + * primera instancia encontrada. + * + * + * @param mixed $item Objeto que se va a buscar. + * @return integer Índice de $item si se encuentra en la lista; en caso contrario, -1. + * */ + public function IndexOf($item); - /** - * Inserta un elemento en la lista, en el índice especificado. - * - * - * @param integer $index Índice de base cero en el que debe insertarse $item. - * @param mixed $item Objeto que se va a insertar. - * - * */ - public function Insert($index, $item); + /** + * Inserta un elemento en la lista, en el índice especificado. + * + * + * @param integer $index Índice de base cero en el que debe insertarse $item. + * @param mixed $item Objeto que se va a insertar. + * + * */ + public function Insert($index, $item); - /** - * Quita el elemento del índice especificado. - * - * - * @param integer $index Índice de base cero del elemento que se va a quitar. - * */ - public function RemoveAt($index); + /** + * Quita el elemento del índice especificado. + * + * + * @param integer $index Índice de base cero del elemento que se va a quitar. + * */ + public function RemoveAt($index); - } + } } From b11d8a2dc4bca175213abb3c8f1bcbd578a5fe75 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:40:17 -0430 Subject: [PATCH 21/59] Applied PSR2 corrections to Collections\* classes (incomplete). ###Remained violations: FILE: src/Collections/Collection.php ---------------------------------------------------------------------- FOUND 2 ERRORS AND 3 WARNINGS AFFECTING 5 LINES ---------------------------------------------------------------------- 34 | WARNING | Property name "$_iteratorPosition" should not be | | prefixed with an underscore to indicate visibility 71 | ERROR | Each trait must be in a file by itself 90 | WARNING | Property name "$_items" should not be prefixed with | | an underscore to indicate visibility 253 | WARNING | Property name "$_count" should not be prefixed with | | an underscore to indicate visibility 260 | ERROR | Method name "Collection::get_Count" is not in camel | | caps format ---------------------------------------------------------------------- FILE: src/Collections/ICollection.php ---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 41 | ERROR | Method name "ICollection::get_Count" is not in camel | | caps format ---------------------------------------------------------------------- --- src/Collections/Collection.php | 75 +++++++++++++++++++++------------ src/Collections/ICollection.php | 13 +++--- src/Collections/IList.php | 10 ++--- 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index accabcd..e1a38c4 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -19,6 +19,7 @@ * */ namespace NelsonMartell\Collections { + use NelsonMartell\Object; use NelsonMartell\Extensions\String; @@ -28,31 +29,37 @@ * @author Nelson Martell (nelson6e65-dev@yahoo.es) * @since v0.4.0 * */ - trait CollectionIterator { + trait CollectionIterator + { private $_iteratorPosition = 0; - public function current() { - return $this->GetItem($this->_iteratorPosition); + public function current() + { + return $this->getItem($this->_iteratorPosition); } - public function rewind() { + public function rewind() + { $this->_iteratorPosition = 0; } - public function key() { + public function key() + { return $this->_iteratorPosition; } - public function next() { + public function next() + { ++$this->_iteratorPosition; } - public function valid() { + public function valid() + { $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); return $v; } - protected abstract function GetItem($index); + protected abstract function getItem($index); } /** @@ -61,20 +68,23 @@ protected abstract function GetItem($index); * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - class Collection extends Object implements ICollection { + class Collection extends Object implements ICollection + { use CollectionIterator; //Implementación de la interfaz Iterator - function __construct() { + public function __construct() + { parent::__construct(); unset($this->Count); } - public final function __invoke($index, $value = null) { + final public function __invoke($index, $value = null) + { if ($value == null) { return $this->_items[$index]; } - $this->SetItem($index, $value); + $this->setItem($index, $value); } private $_items = array(); @@ -88,12 +98,13 @@ public final function __invoke($index, $value = null) { * @access protected * @return void * */ - protected function InsertItem($index, $newItem) { + protected function insertItem($index, $newItem) + { if ($index > $this->Count || $index < 0) { throw new OutOfRangeException(); } - if ($index == $this->Count){ + if ($index == $this->Count) { $this->_items[$index] = null; $this->_count++; } @@ -106,7 +117,8 @@ protected function InsertItem($index, $newItem) { * * @return void * */ - protected function ClearItems() { + protected function clearItems() + { $this->_items = array(); $this->_count = 0; } @@ -118,7 +130,8 @@ protected function ClearItems() { * @param mixed $newItem Nuevo valor con el que se va a reemplazar. * @return void * */ - protected function SetItem($index, $newItem) { + protected function setItem($index, $newItem) + { if ($index >= $this->Count || $index < 0) { throw new OutOfRangeException(); } @@ -136,7 +149,8 @@ protected function SetItem($index, $newItem) { * @param integer $index Índice del elemento a obtener. * @return mixed * */ - protected function GetItem($index) { + protected function getItem($index) + { if ($index >= $this->Count || $index < 0) { return null; } @@ -144,12 +158,13 @@ protected function GetItem($index) { return $this->_items[$index]; } - protected function RemoveItem($index) { + protected function removeItem($index) + { if ($index >= $this->Count || $index < 0) { throw new OutOfRangeException(); } - for($i = $index; $i < $this->Count - 1; $i++) { + for ($i = $index; $i < $this->Count - 1; $i++) { $this->_items[$i] = $this->_items[$i + 1]; //Mueve los valores } @@ -182,7 +197,8 @@ protected function RemoveItem($index) { * @return string * @see String::Format() * */ - public function ToString($format = 'r') { + public function toString($format = 'r') + { static $defaultFormats = [ 'r' => '{items}', 'l' => '{ {items} }', @@ -241,7 +257,8 @@ public function ToString($format = 'r') { * * @return integer * */ - public function get_Count() { + public function get_Count() + { return $this->_count; } @@ -253,7 +270,8 @@ public function get_Count() { * @param mixed Elemento que se va a agregar a la colección. * @return void * */ - public function Add($item) { + public function add($item) + { $this->InsertItem($this->Count, $item); } @@ -264,7 +282,8 @@ public function Add($item) { * * @return void * */ - public function Clear() { + public function clear() + { $this->ClearItems(); } @@ -274,8 +293,9 @@ public function Clear() { * @param mixed $item Objeto que se va a buscar. * @return boolean true si $item se encuentra; en caso contrario, false. * */ - public function Contains($item) { - foreach($this->_items as $i) { + public function contains($item) + { + foreach ($this->_items as $i) { if ($item === $i) { return true; } @@ -291,7 +311,8 @@ public function Contains($item) { * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. * Este método también devuelve false si no se encontró $item. * */ - public function Remove($item) { + public function remove($item) + { for ($i = 0; $i < $this->Count; $i++) { if ($this->_items[$i] === $item) { $this->RemoveItem($i); @@ -302,7 +323,5 @@ public function Remove($item) { } #end region - - } } diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 7acceb2..4077842 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -18,6 +18,7 @@ * */ namespace NelsonMartell\Collections { + use \Iterator; /** @@ -26,7 +27,8 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - interface ICollection extends Iterator { + interface ICollection extends Iterator + { /** * Obtiene el número de elementos incluidos en la colección. @@ -45,7 +47,7 @@ public function get_Count(); * @param mixed $item Objeto que se va a agregar. * @return void * */ - public function Add($item); + public function add($item); /** * Quita todos los elementos de la colección. @@ -56,7 +58,7 @@ public function Add($item); * * @return void * */ - public function Clear(); + public function clear(); /** * Determina si la colección contiene un valor específico. @@ -65,7 +67,7 @@ public function Clear(); * @param mixed $item Objeto que se va a buscar. * @return boolean true si $item se encuentra; en caso contrario, false. * */ - public function Contains($item); + public function contains($item); /** * Quita la primera aparición de un objeto específico de la colección. @@ -75,7 +77,6 @@ public function Contains($item); * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. * Este método también devuelve false si no se encontró $item. * */ - public function Remove($item); - + public function remove($item); } } diff --git a/src/Collections/IList.php b/src/Collections/IList.php index 64a6b99..05373a2 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -25,7 +25,8 @@ * * @author Nelson Martell (nelson6e65-dev@yahoo.es) * */ - interface IList extends ICollection { + interface IList extends ICollection + { /** * Determina el índice de un elemento específico de la lista. @@ -36,7 +37,7 @@ interface IList extends ICollection { * @param mixed $item Objeto que se va a buscar. * @return integer Índice de $item si se encuentra en la lista; en caso contrario, -1. * */ - public function IndexOf($item); + public function indexOf($item); /** * Inserta un elemento en la lista, en el índice especificado. @@ -46,7 +47,7 @@ public function IndexOf($item); * @param mixed $item Objeto que se va a insertar. * * */ - public function Insert($index, $item); + public function insert($index, $item); /** * Quita el elemento del índice especificado. @@ -54,7 +55,6 @@ public function Insert($index, $item); * * @param integer $index Índice de base cero del elemento que se va a quitar. * */ - public function RemoveAt($index); - + public function removeAt($index); } } From e072f1a61ecf80d4ce2cf05d350def395ad16d2a Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 07:51:39 -0430 Subject: [PATCH 22/59] Moved CollectionIterator trait to new file. Remained PSR2 violations: FILE: src/Collections/Collection.php ---------------------------------------------------------------------- FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES ---------------------------------------------------------------------- 51 | WARNING | Property name "$_items" should not be prefixed with | | an underscore to indicate visibility 214 | WARNING | Property name "$_count" should not be prefixed with | | an underscore to indicate visibility 221 | ERROR | Method name "Collection::get_Count" is not in camel | | caps format ---------------------------------------------------------------------- FILE: src/Collections/CollectionIterator.php ---------------------------------------------------------------------- FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE ---------------------------------------------------------------------- 31 | WARNING | Property name "$_iteratorPosition" should not be | | prefixed with an underscore to indicate visibility ---------------------------------------------------------------------- --- src/Collections/Collection.php | 39 ----------------- src/Collections/CollectionIterator.php | 60 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 src/Collections/CollectionIterator.php diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index e1a38c4..560e1a1 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -23,45 +23,6 @@ use NelsonMartell\Object; use NelsonMartell\Extensions\String; - /** - * Implementa los métodos de la interfaz Iterator para una colección de objetos. - * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) - * @since v0.4.0 - * */ - trait CollectionIterator - { - private $_iteratorPosition = 0; - - public function current() - { - return $this->getItem($this->_iteratorPosition); - } - - public function rewind() - { - $this->_iteratorPosition = 0; - } - - public function key() - { - return $this->_iteratorPosition; - } - - public function next() - { - ++$this->_iteratorPosition; - } - - public function valid() - { - $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); - return $v; - } - - protected abstract function getItem($index); - } - /** * Clase base de una colección de objetos, que provee una implementación predeterminada de la * interfaz ICollection. diff --git a/src/Collections/CollectionIterator.php b/src/Collections/CollectionIterator.php new file mode 100644 index 0000000..441c4ea --- /dev/null +++ b/src/Collections/CollectionIterator.php @@ -0,0 +1,60 @@ +getItem($this->_iteratorPosition); + } + + public function rewind() + { + $this->_iteratorPosition = 0; + } + + public function key() + { + return $this->_iteratorPosition; + } + + public function next() + { + ++$this->_iteratorPosition; + } + + public function valid() + { + $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); + return $v; + } + + protected abstract function getItem($index); +} From c5b0e8177069249aaf6aba206948d9d768741d02 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 23 May 2015 09:53:39 -0430 Subject: [PATCH 23/59] fix: @author tag format --- src/Collections/Collection.php | 2 +- src/Collections/CollectionIterator.php | 2 +- src/Collections/ICollection.php | 2 +- src/Collections/IList.php | 2 +- src/Extensions/String.php | 2 +- src/IComparable.php | 2 +- src/IEquatable.php | 2 +- src/IntString.php | 2 +- src/Object.php | 2 +- src/Type.php | 2 +- src/Utilities/UnitTesting/Assert.php | 2 +- src/Version.php | 2 +- src/VersionComponent.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 560e1a1..c6887b1 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -27,7 +27,7 @@ * Clase base de una colección de objetos, que provee una implementación predeterminada de la * interfaz ICollection. * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ class Collection extends Object implements ICollection { diff --git a/src/Collections/CollectionIterator.php b/src/Collections/CollectionIterator.php index 441c4ea..6fe3961 100644 --- a/src/Collections/CollectionIterator.php +++ b/src/Collections/CollectionIterator.php @@ -23,7 +23,7 @@ /** * Implementa los métodos de la interfaz Iterator para una colección de objetos. * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * @since v0.4.0 * */ trait CollectionIterator diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 4077842..0889484 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -25,7 +25,7 @@ * Define métodos para manipular colecciones de objetos. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ interface ICollection extends Iterator { diff --git a/src/Collections/IList.php b/src/Collections/IList.php index 05373a2..bd6a8d8 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -23,7 +23,7 @@ * Representa una colección de objetos a los que se puede tener acceso por un índice. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ interface IList extends ICollection { diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 641a435..c7d643f 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -57,7 +57,7 @@ class String extends \Cake\Utility\Text * @return string * @todo Implement php.net/functions.arguments.html#functions.variable-arg-list.new for PHP 5.6+ * @todo Implement formatting, like IFormatProvider or something like that. - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell */ public static function format($format, $args) { diff --git a/src/IComparable.php b/src/IComparable.php index 8e9ddfa..5312846 100644 --- a/src/IComparable.php +++ b/src/IComparable.php @@ -22,7 +22,7 @@ /** * Provee un método para compara igualdad entre objetos del mismo tipo. * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ interface IComparable { diff --git a/src/IEquatable.php b/src/IEquatable.php index 5e9fe43..3f3f35d 100644 --- a/src/IEquatable.php +++ b/src/IEquatable.php @@ -22,7 +22,7 @@ /** * Provee un método para compara igualdad entre objetos del mismo tipo. * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ interface IEquatable { diff --git a/src/IntString.php b/src/IntString.php index ec09299..8c71e59 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -24,7 +24,7 @@ * El método ToString obtiene esa cadena compuesta. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ class IntString extends Object implements IEquatable, IComparable { diff --git a/src/Object.php b/src/Object.php index b5c51b6..54f9939 100644 --- a/src/Object.php +++ b/src/Object.php @@ -51,7 +51,7 @@ * unset($this->Nombre); * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ class Object { diff --git a/src/Type.php b/src/Type.php index abc2401..567c550 100644 --- a/src/Type.php +++ b/src/Type.php @@ -28,7 +28,7 @@ * Represents a PHP object type, and provides some properties and methods to describe some info * about itself. * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ final class Type extends Object { diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index 9d2b0a0..7311577 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -27,7 +27,7 @@ * Comprueba condiciones de pruebas. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ final class Assert { diff --git a/src/Version.php b/src/Version.php index 7304033..4baca23 100644 --- a/src/Version.php +++ b/src/Version.php @@ -27,7 +27,7 @@ * No se puede heredar esta clase. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ final class Version extends Object implements IEquatable, IComparable { diff --git a/src/VersionComponent.php b/src/VersionComponent.php index d32dfe8..ca3e45c 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -26,7 +26,7 @@ * Extiende la clase IntString, pero restringe los valores que puede tomar. * * - * @author Nelson Martell (nelson6e65-dev@yahoo.es) + * @author Nelson Martell * */ class VersionComponent extends IntString implements IEquatable { From 4606bbd4c71cb7a739e2e59bc679551799dcaf81 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sun, 24 May 2015 07:28:24 -0430 Subject: [PATCH 24/59] fix: PSR2 violation: getters and setters methods name. --- src/Collections/Collection.php | 2 +- src/Collections/ICollection.php | 2 +- src/IntString.php | 4 ++-- src/Object.php | 8 ++++---- src/Type.php | 10 +++++----- src/Utilities/Asset.php | 14 +++++++------- src/Version.php | 8 ++++---- src/VersionComponent.php | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index c6887b1..00e8385 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -218,7 +218,7 @@ public function toString($format = 'r') * * @return integer * */ - public function get_Count() + public function getCount() { return $this->_count; } diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 0889484..1e25e5c 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -38,7 +38,7 @@ interface ICollection extends Iterator * @see NelsonMartell\Object * @return integer * */ - public function get_Count(); + public function getCount(); /** * Agrega un elemento a la colección. diff --git a/src/IntString.php b/src/IntString.php index 8c71e59..e8af666 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -68,13 +68,13 @@ public static function parse($value) protected $_stringValue; public $IntValue; - public function get_IntValue() + public function getIntValue() { return (int) $this->_intValue; } public $StringValue; - public function get_StringValue() + public function getStringValue() { return $this->_stringValue; } diff --git a/src/Object.php b/src/Object.php index 54f9939..2a6fa21 100644 --- a/src/Object.php +++ b/src/Object.php @@ -37,11 +37,11 @@ * Luego, las respectivas funciones siguiendo el formato "get_" o "set_", seguido del nombre de * la propiedad. * - * public function get_Nombre() { + * public function getNombre() { * return $this->_nombre; * } * - * public function set_Nombre(string $value) { + * public function setNombre(string $value) { * // Validaciones * $this->_nombre = $value; * } @@ -75,7 +75,7 @@ public function __get($name) $error = dgettext('nml', 'Property do not exists') . '.'; } - $getter = 'get_' . $name; + $getter = 'get' . $name; if (!$error) { if (!method_exists($this, $getter)) { @@ -115,7 +115,7 @@ public function __set($name, $value) $error = dgettext('nml', 'Property do not exists') . '.'; } - $setter = 'set_' . $name; + $setter = 'set' . $name; if (!$error) { if (!method_exists($this, $setter)) { diff --git a/src/Type.php b/src/Type.php index 567c550..a71d064 100644 --- a/src/Type.php +++ b/src/Type.php @@ -95,7 +95,7 @@ public function __construct($obj) * * @return string * */ - public function get_Name() + public function getName() { return $this->_name; } @@ -115,7 +115,7 @@ public function get_Name() * @return string * @see Type::ShortName * */ - public function get_ShortName() + public function getShortName() { return $this->_shortName; } @@ -136,7 +136,7 @@ public function get_ShortName() * @return string|NULL * @see Type::Namespace * */ - public function get_Namespace() + public function getNamespace() { return $this->_namespace; } @@ -150,7 +150,7 @@ public function get_Namespace() * */ public $Vars; private $_vars = null; - public function get_Vars() + public function getVars() { if ($this->_vars == null) { $this->_vars = $this->_reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); @@ -167,7 +167,7 @@ public function get_Vars() * */ public $Methods; private $_methods = null; - public function get_Methods() + public function getMethods() { if ($this->_methods == null) { $this->_methods = $this->_reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 4d47e3f..792bc91 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -116,12 +116,12 @@ public function __construct($name = null, $versions = null, $cdnUri = null) public $Name; private $_name; - public function get_Name() + public function getName() { return $this->_name; } - public function set_Name($value) + public function setName($value) { if (!is_string($value)) { throw new InvalidArgumentException('$value argument must be string.'); @@ -144,7 +144,7 @@ public function set_Name($value) public $ShortName; private $_shortName; - public function get_ShortName() + public function getShortName() { return $this->_shortName; } @@ -157,7 +157,7 @@ public function get_ShortName() public $Versions; private $_versions; - public function get_Versions() + public function getVersions() { return $this->_versions; } @@ -176,12 +176,12 @@ public function get_Versions() public $CdnUri; private $_cdnUri; - public function get_CdnUri() + public function getCdnUri() { return $this->_cdnUri; } - public function set_CdnUri($value) + public function setCdnUri($value) { $this->_cdnUri = (string) $value; } @@ -193,7 +193,7 @@ public function set_CdnUri($value) * @var string Ruta inicial del recurso * */ public $RootDirectory; - public function get_RootDirectory() + public function getRootDirectory() { return $this->ShortName . '/'; } diff --git a/src/Version.php b/src/Version.php index 4baca23..3019082 100644 --- a/src/Version.php +++ b/src/Version.php @@ -176,7 +176,7 @@ public static function parse($value) public $Major; private $_major; - public function get_Major() + public function getMajor() { return $this->_major; } @@ -192,7 +192,7 @@ public function get_Major() public $Minor; private $_minor; - public function get_Minor() + public function getMinor() { return $this->_minor; } @@ -207,7 +207,7 @@ public function get_Minor() public $Build; private $_build; - public function get_Build() + public function getBuild() { return $this->_build; } @@ -222,7 +222,7 @@ public function get_Build() public $Revision; private $_revision; - public function get_Revision() + public function getRevision() { return $this->_revision; } diff --git a/src/VersionComponent.php b/src/VersionComponent.php index ca3e45c..09a92f2 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -125,7 +125,7 @@ public function isDefault() * * @return integer|NULL * */ - public function get_IntValue() + public function getIntValue() { return $this->_intValue; } From 12ba033efe45c0482b341d112e2617e4b8c6f0aa Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sun, 24 May 2015 12:26:19 +0000 Subject: [PATCH 25/59] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- autoload.php | 8 ++++---- src/Collections/Collection.php | 5 ++++- src/IntString.php | 2 +- src/Object.php | 16 ++++++++-------- src/Type.php | 4 ++-- src/Utilities/Asset.php | 9 ++++++--- src/Utilities/UnitTesting/Assert.php | 7 ++++--- src/functions.php | 2 +- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/autoload.php b/autoload.php index f20f088..7180d13 100644 --- a/autoload.php +++ b/autoload.php @@ -1,9 +1,9 @@ _items[$index]; } + /** + * @param integer $index + */ protected function removeItem($index) { if ($index >= $this->Count || $index < 0) { diff --git a/src/IntString.php b/src/IntString.php index e8af666..9ba6329 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -81,7 +81,7 @@ public function getStringValue() public function toString() { - return $this->IntValue . $this->StringValue; + return $this->IntValue.$this->StringValue; } public function equals($other) diff --git a/src/Object.php b/src/Object.php index 2a6fa21..88f7c96 100644 --- a/src/Object.php +++ b/src/Object.php @@ -72,14 +72,14 @@ public function __get($name) $error = false; if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists') . '.'; + $error = dgettext('nml', 'Property do not exists').'.'; } - $getter = 'get' . $name; + $getter = 'get'.$name; if (!$error) { if (!method_exists($this, $getter)) { - $error = dgettext('nml', 'Property is write only') . '.'; //? + $error = dgettext('nml', 'Property is write only').'.'; //? } } @@ -112,15 +112,15 @@ public function __set($name, $value) $error = false; if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists') . '.'; + $error = dgettext('nml', 'Property do not exists').'.'; } - $setter = 'set' . $name; + $setter = 'set'.$name; if (!$error) { if (!method_exists($this, $setter)) { //La propiedad existe, pero no tiene establecido el método setter. - $error = dgettext('nml', 'Property is read only') . '.'; + $error = dgettext('nml', 'Property is read only').'.'; } } @@ -172,7 +172,7 @@ public function toString() sprintf( dgettext( 'nml', - 'Using default %s method. ' . + 'Using default %s method. '. 'You can replace its behavior, overriding it by creating %s::ToString() public method.' ), __METHOD__, @@ -183,7 +183,7 @@ public function toString() } } - return '{ ' . $type . ' }'; + return '{ '.$type.' }'; } /** diff --git a/src/Type.php b/src/Type.php index a71d064..b4a2681 100644 --- a/src/Type.php +++ b/src/Type.php @@ -60,7 +60,7 @@ public function __construct($obj) case 'resource': $shortName = get_resource_type($obj); - $name = 'resource: ' . $shortName; + $name = 'resource: '.$shortName; $vars = []; $methods = []; break; @@ -258,7 +258,7 @@ public function isScalar() * */ public function isValueType() { - switch($this->Name){ + switch ($this->Name) { case 'string': case 'integer': case 'double': diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 792bc91..9f00276 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -68,7 +68,8 @@ public function __construct($name = null, $versions = null, $cdnUri = null) if (!($v instanceof Version)) { try { $v = Version::Parse($version); - } catch (InvalidArgumentException $e) { + } + catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$versions argument must be an array of Version objects ' . 'or any objects parseable into Version.', @@ -88,7 +89,8 @@ public function __construct($name = null, $versions = null, $cdnUri = null) // Trata de convertir $versions en un objeto Versión try { $v = Version::Parse($versions); - } catch (InvalidArgumentException $e) { + } + catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$versions argument must be an array of Version objects (or empty), a Version object ' . 'or any object parseable into Version.', @@ -234,7 +236,8 @@ public function getDirectoryPath($version = self::NEWEST) } else { try { $v = Version::Parse($version); - } catch (InvalidArgumentException $e) { + } + catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$version argument must be an Version object or any object parseable into Version.', 0, diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index 7311577..69a5dc1 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -20,7 +20,6 @@ namespace NelsonMartell\Utilities\UnitTesting { use NelsonMartell\Object; - use NelsonMartell\Version; use \Exception; /** @@ -195,7 +194,8 @@ public static function methodThrowsException( try { call_user_func_array(array($obj, $method_name), $params); - } catch (Exception $e) { + } + catch (Exception $e) { $actual = typeof($e); } @@ -265,7 +265,8 @@ public static function propertyThrowsException( try { $obj->$property_name = $value; - } catch (Exception $e) { + } + catch (Exception $e) { $actual = typeof($e); } diff --git a/src/functions.php b/src/functions.php index 51ce6dd..f0f5a86 100644 --- a/src/functions.php +++ b/src/functions.php @@ -18,8 +18,8 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ -use NelsonMartell\Type; use NelsonMartell\Extensions\String; +use NelsonMartell\Type; define('NML_GETTEXT_DOMAIN', 'nml'); From 018d16cec4553387b3aa53fe581e0f6dcdd66a9c Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sun, 24 May 2015 09:04:03 -0430 Subject: [PATCH 26/59] fix #3 --- src/Extensions/String.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index c7d643f..6111bcd 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -68,6 +68,6 @@ public static function format($format, $args) $data = func_num_args() === 2 ? (array) $args : array_slice(func_get_args(), 1); - return parent::insert($format, $data, $options); + return static::insert($format, $data, $options); } } From 8d7a2e260899efabb2fc249ea2c1ec21315256a7 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 28 May 2015 10:22:06 -0430 Subject: [PATCH 27/59] add: Move properties handler to a trait. add: :new: trait called NelsonMartell\PropertiesHandler --- src/Object.php | 86 +-------------------------- src/PropertiesHandler.php | 118 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 84 deletions(-) create mode 100644 src/PropertiesHandler.php diff --git a/src/Object.php b/src/Object.php index 88f7c96..a345565 100644 --- a/src/Object.php +++ b/src/Object.php @@ -21,8 +21,6 @@ use \BadMethodCallException; - spl_autoload_call('NelsonMartell\Type'); - /** * Clase base de objetos, para encapsular propiedades y otros métodos básicos. * @@ -55,90 +53,10 @@ * */ class Object { - public function __construct() - { - } - - /** - * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este - * modelo: 'get_' + $name + '()'. - * Restringe la obtención de una propiedad no definida dentro de la clase si no posee su - * método getter. - * - * - * */ - public function __get($name) - { - $error = false; - - if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists').'.'; - } - - $getter = 'get'.$name; - - if (!$error) { - if (!method_exists($this, $getter)) { - $error = dgettext('nml', 'Property is write only').'.'; //? - } - } - - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to access to '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); - } - - return $this->$getter(); - } + use PropertiesHandler; - /** - * Establece el valor de una propiedad según el modelo: 'set_' + $name + '(' + $value + ')' - * Restringe la asignación de una propiedad no definida dentro de la clase si no posee su - * método setter. - * - * - * */ - public function __set($name, $value) + public function __construct() { - $error = false; - - if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists').'.'; - } - - $setter = 'set'.$name; - - if (!$error) { - if (!method_exists($this, $setter)) { - //La propiedad existe, pero no tiene establecido el método setter. - $error = dgettext('nml', 'Property is read only').'.'; - } - } - - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to assign '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); - } - - $this->$setter($value); } /** diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php new file mode 100644 index 0000000..f3fa817 --- /dev/null +++ b/src/PropertiesHandler.php @@ -0,0 +1,118 @@ + + * */ + trait PropertiesHandler + { + /** + * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este + * modelo: 'get_' + $name + '()'. + * Restringe la obtención de una propiedad no definida dentro de la clase si no posee su + * método getter. + * + * + * */ + public function __get($name) + { + $error = false; + + if (!property_exists($this, $name)) { + $error = dgettext('nml', 'Property do not exists').'.'; + } + + $getter = 'get'.$name; + + if (!$error) { + if (!method_exists($this, $getter)) { + $error = dgettext('nml', 'Property is write only').'.'; //? + } + } + + if ($error) { + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to access to '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); + } + + return $this->$getter(); + } + + /** + * Establece el valor de una propiedad según el modelo: 'set_' + $name + '(' + $value + ')' + * Restringe la asignación de una propiedad no definida dentro de la clase si no posee su + * método setter. + * + * + * */ + public function __set($name, $value) + { + $error = false; + + if (!property_exists($this, $name)) { + $error = dgettext('nml', 'Property do not exists').'.'; + } + + $setter = 'set'.$name; + + if (!$error) { + if (!method_exists($this, $setter)) { + //La propiedad existe, pero no tiene establecido el método setter. + $error = dgettext('nml', 'Property is read only').'.'; + } + } + + if ($error) { + throw new BadMethodCallException( + sprintf( + dgettext( + 'nml', + "Unable to assign '%s' property in '%s' class. Reason: %s" + ), + $name, + $this->GetType()->Name, + $error + ) + ); + } + + $this->$setter($value); + } + + } +} From cb292e7b8507d00fd605c7d43947719a0d10f069 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 28 May 2015 11:52:27 -0430 Subject: [PATCH 28/59] add: :new: constant to use as prefix getters/setters methods. --- src/PropertiesHandler.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php index f3fa817..e4f4f20 100644 --- a/src/PropertiesHandler.php +++ b/src/PropertiesHandler.php @@ -32,6 +32,20 @@ * */ trait PropertiesHandler { + /** + * Prefix for methods witch get properties value. + * You can override to use another prefix. + * @var string + */ + const GETTER_PREFIX = 'get'; + + /** + * Prefix for methods witch set properties value. + * You can override to use another prefix. + * @var string + */ + const SETTER_PREFIX = 'set'; + /** * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este * modelo: 'get_' + $name + '()'. From 62c11392e0da393445f745d594d2156828a5b3b2 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Thu, 28 May 2015 16:31:15 +0000 Subject: [PATCH 29/59] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Object.php | 2 +- src/Utilities/Asset.php | 6 +++--- src/Utilities/UnitTesting/Assert.php | 1 + src/Version.php | 9 +++++---- src/VersionComponent.php | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Object.php b/src/Object.php index a345565..450251e 100644 --- a/src/Object.php +++ b/src/Object.php @@ -50,7 +50,7 @@ * * * @author Nelson Martell - * */ + * */ class Object { use PropertiesHandler; diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 9f00276..1744a44 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -71,7 +71,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } catch (InvalidArgumentException $e) { throw new InvalidArgumentException( - '$versions argument must be an array of Version objects ' . + '$versions argument must be an array of Version objects '. 'or any objects parseable into Version.', 0, $e @@ -92,7 +92,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } catch (InvalidArgumentException $e) { throw new InvalidArgumentException( - '$versions argument must be an array of Version objects (or empty), a Version object ' . + '$versions argument must be an array of Version objects (or empty), a Version object '. 'or any object parseable into Version.', 0, $e @@ -197,7 +197,7 @@ public function setCdnUri($value) public $RootDirectory; public function getRootDirectory() { - return $this->ShortName . '/'; + return $this->ShortName.'/'; } const NEWEST = 'newest'; diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index 69a5dc1..c1447bf 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -57,6 +57,7 @@ private static function equals($expected, $actual) * * * @param string $msg Custom message to append on assert failed. + * @param boolean $expected * @return boolean true si son iguales; false, en caso contrario. * */ public static function areEqual($expected, $actual, $msg = '') diff --git a/src/Version.php b/src/Version.php index 3019082..5082a91 100644 --- a/src/Version.php +++ b/src/Version.php @@ -54,7 +54,7 @@ public function __construct($major, $minor, $build = null, $revision = null) sprintf( dgettext( 'nml', - "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. " . + "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. ". "Convert value or use the static method Version::parse." ), "major", @@ -70,7 +70,7 @@ public function __construct($major, $minor, $build = null, $revision = null) sprintf( dgettext( 'nml', - "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. " . + "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. ". "Convert value or use the static method Version::parse." ), "minor", @@ -284,11 +284,11 @@ public function isValid() if ($this->Build->IsNotNull() and $this->Revision->IsNotNull()) { // Si ambos están definidos... - $r = (bool)($this->Build->StringValue == ''); //#5 + $r = (bool) ($this->Build->StringValue == ''); //#5 if (!$r) { //#4 - $r = (bool)(($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); + $r = (bool) (($this->Build->StringValue == '') and ($this->Revision->StringValue == '')); if (!$r) { if ($this->Build->StringValue != '') { @@ -313,6 +313,7 @@ public function isValid() * Determina si el objeto $other especificado es igual a la instancia actual. * * + * @param Version $other * @return bool True si $other es igual esta instancia * */ public function equals($other) diff --git a/src/VersionComponent.php b/src/VersionComponent.php index 09a92f2..943fa07 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -63,7 +63,7 @@ public function __construct($intValue = null, $stringValue = null) $middle = '([a-z]|[0-9]|-)*'; $end = '([a-z]|[0-9])$~'; - $pattern = $start . $middle . $end; + $pattern = $start.$middle.$end; } $correct = (boolean) preg_match($pattern, $this->StringValue); From 976d92591ebab94653e05da77daa8bf39441963e Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 28 May 2015 12:15:11 -0430 Subject: [PATCH 30/59] :memo: Updated documentation of __get/set methods. --- src/PropertiesHandler.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php index e4f4f20..00a00a1 100644 --- a/src/PropertiesHandler.php +++ b/src/PropertiesHandler.php @@ -47,12 +47,14 @@ trait PropertiesHandler const SETTER_PREFIX = 'set'; /** - * Obtiene el valor de una propiedad. Ésta debe definir un método getter, que sigue este - * modelo: 'get_' + $name + '()'. - * Restringe la obtención de una propiedad no definida dentro de la clase si no posee su - * método getter. + * Obtiene el valor de una propiedad, usando automáticamente el método + * `GETTER_PREFIX + nombre_propiedad` (getter). * + * Restringe la obtención de una propiedad no definida dentro de la clase + * si no posee su método getter. * + * @param string $name Property name. + * @see PropertiesHandler::GETTER_PREFIX * */ public function __get($name) { @@ -88,10 +90,13 @@ public function __get($name) } /** - * Establece el valor de una propiedad según el modelo: 'set_' + $name + '(' + $value + ')' - * Restringe la asignación de una propiedad no definida dentro de la clase si no posee su - * método setter. + * Establece el valor de una propiedad, usando automáticamente el método + * `SETTER_PREFIX + nombre_propiedad` (setter). + * Restringe la asignación de una propiedad no definida dentro de la clase + * si no posee su método setter. * + * @param string $name Property name- + * @param mixed $value Property value. * * */ public function __set($name, $value) From c7f113cde7c9845a82ebbf7bc1bb253f654ba9ac Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 28 May 2015 12:28:53 -0430 Subject: [PATCH 31/59] fix: traits can't define constants. Use of :new: static fields instead of :fire: consts :memo: Updated doc --- src/PropertiesHandler.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php index 00a00a1..dddb557 100644 --- a/src/PropertiesHandler.php +++ b/src/PropertiesHandler.php @@ -37,24 +37,24 @@ trait PropertiesHandler * You can override to use another prefix. * @var string */ - const GETTER_PREFIX = 'get'; + protected static $getterPrefix = 'get'; /** * Prefix for methods witch set properties value. * You can override to use another prefix. * @var string */ - const SETTER_PREFIX = 'set'; + protected static $setterPrefix = 'set'; /** * Obtiene el valor de una propiedad, usando automáticamente el método - * `GETTER_PREFIX + nombre_propiedad` (getter). + * `$getterPrefix + nombre_propiedad` (getter). * * Restringe la obtención de una propiedad no definida dentro de la clase * si no posee su método getter. * * @param string $name Property name. - * @see PropertiesHandler::GETTER_PREFIX + * @see PropertiesHandler::$getterPrefix * */ public function __get($name) { @@ -64,7 +64,7 @@ public function __get($name) $error = dgettext('nml', 'Property do not exists').'.'; } - $getter = 'get'.$name; + $getter = static::$getterPrefix.$name; if (!$error) { if (!method_exists($this, $getter)) { @@ -91,13 +91,14 @@ public function __get($name) /** * Establece el valor de una propiedad, usando automáticamente el método - * `SETTER_PREFIX + nombre_propiedad` (setter). + * `$setterPrefix + nombre_propiedad` (setter). * Restringe la asignación de una propiedad no definida dentro de la clase * si no posee su método setter. * * @param string $name Property name- * @param mixed $value Property value. - * + * @see PropertiesHandler::$setterPrefix + * @return void * */ public function __set($name, $value) { @@ -107,7 +108,7 @@ public function __set($name, $value) $error = dgettext('nml', 'Property do not exists').'.'; } - $setter = 'set'.$name; + $setter = static::$setterPrefix.$name; if (!$error) { if (!method_exists($this, $setter)) { From d0a8db3fc658f30c714c4421d872303e63441dce Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 02:01:58 -0430 Subject: [PATCH 32/59] fix: nml_msg args handle. Now is able to use $args as placeholders (`{name}`, `{age}`, etc) array or just 1 arg as `{0}` placeholder, 2 args `{0}` and `{1}` placeholder and so on. --- src/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index f0f5a86..3574032 100644 --- a/src/functions.php +++ b/src/functions.php @@ -33,11 +33,15 @@ * incluir en las cadenas de formato del mensaje. * @return string * @see dgettext - * @see String::Format + * @see String::format * */ function nml_msg($message, $args = null) { - $s = String::Format($message, array_slice(func_get_args(), 1)); + if (func_num_args() > 2) { + $args = array_slice(func_get_args(), 1); + } + + $s = String::format($message, $args); return dgettext(NML_GETTEXT_DOMAIN, $s); } From 5c1d0e5106bf31e08b8f0986900c2c9792238cb0 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 02:34:11 -0430 Subject: [PATCH 33/59] add: :new: methods to ensure strings. - String::ensureIsNotNull - String::ensureIsString - String::ensureIsNotEmpty - String::ensureIsNotWhiteSpaces That methods thows InvalidArgumentException in case of wrong data. Signed-off-by: Nelson Martell --- src/Extensions/String.php | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 6111bcd..fc0e8a6 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -70,4 +70,72 @@ public static function format($format, $args) return static::insert($format, $data, $options); } + + /** + * Ensures that object given is not null. If is `null`, throws and exception. + * + * @param mixed $string Object to validate + * @throws InvalidArgumentException if object is `null`. + * @return mixed Same object + */ + public static function ensureIsNotNull($obj) + { + if (is_null($obj)) { + $msg = nml_msg('Provided object must not be NULL.'); + throw new InvalidArgumentException($msg); + } + + return $obj; + } + + /** + * Ensures that object given is an string. Else, thows an exception + * + * @param mixed $obj Object to validate. + * @return string Same object given, but ensured that is an string. + * @throws InvalidArgumentException if object is not an `string`. + */ + public static function ensureIsString($obj) + { + if (is_null($obj)) { + $msg = nml_msg('Provided object must to be an string; "{0}" given.', typeof($obj)); + throw new InvalidArgumentException($msg); + } + + return $obj; + } + + /** + * Ensures that given string is not empty. + * + * @param string $string String to validate. + * @return string Same string given, but ensured that is not empty. + * @throws InvalidArgumentException if string is null or empty. + */ + public static function ensureIsNotEmpty($string) + { + if (static::ensureIsString($string) === '') { + $msg = nml_msg('Provided string must not be empty.'); + throw new InvalidArgumentException($msg); + } + + return $string; + } + + /** + * Ensures that given string is not empty or whitespaces. + * + * @param string $string String to validate. + * @return string Same string given, but ensured that is not whitespaces. + * @see trim + */ + public static function ensureIsNotWhiteSpaces($string) + { + if (trim(static::ensureIsString($string)) === '') { + $msg = nml_msg('Provided string must not be white spaces.'); + throw new InvalidArgumentException($msg); + } + + return $string; + } } From 39ba33c83ee6854f6bc79292db11168d70060066 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 04:56:04 -0430 Subject: [PATCH 34/59] fix (m): :memo: param name --- src/Extensions/String.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index fc0e8a6..5aae964 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -74,7 +74,7 @@ public static function format($format, $args) /** * Ensures that object given is not null. If is `null`, throws and exception. * - * @param mixed $string Object to validate + * @param mixed $obj Object to validate * @throws InvalidArgumentException if object is `null`. * @return mixed Same object */ From bc773e07958758f52ab6699ce6e7273448cf0d7a Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 06:27:29 -0430 Subject: [PATCH 35/59] fix: ensureIsString validation --- src/Extensions/String.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 5aae964..70dcb8e 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -97,7 +97,7 @@ public static function ensureIsNotNull($obj) */ public static function ensureIsString($obj) { - if (is_null($obj)) { + if (!is_string(static::ensureIsNotNull($obj))) { $msg = nml_msg('Provided object must to be an string; "{0}" given.', typeof($obj)); throw new InvalidArgumentException($msg); } From 6425d5b046fc34229dee6f7917e3cddfdd63e781 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 06:29:10 -0430 Subject: [PATCH 36/59] add: :new: method to ensure php naming convention. --- src/Extensions/String.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 70dcb8e..c942ea5 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -138,4 +138,22 @@ public static function ensureIsNotWhiteSpaces($string) return $string; } + + /** + * Ensures that an string follows the PHP variables naming convention. + * + * @param string $string [description] + * @return [type] [description] + */ + public static function ensureIsValidVarName($string) + { + $pattern = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/'; + + if (!preg_match($pattern, static::ensureIsString($string))) { + $msg = nml_msg('Provided string do not follows PHP variables naming convention: "{0}".', $string); + throw new InvalidArgumentException($msg); + } + + return $string; + } } From b49f1501f2b3455ec0025c055467ef68b55b4aee Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 29 May 2015 07:22:17 -0430 Subject: [PATCH 37/59] add: :new: methods to validate properties (maybe solved #4 ?) - ensurePropertyExists - ensureMethodExists - ensurePropertyHasSetter - ensurePropertyHasGetter - getPropertySetter - getPropertyGetter Change default implementation of __get and __set methods, using those methods Signed-off-by: Nelson Martell --- src/PropertiesHandler.php | 197 ++++++++++++++++++++++++++++---------- 1 file changed, 147 insertions(+), 50 deletions(-) diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php index dddb557..78c4b53 100644 --- a/src/PropertiesHandler.php +++ b/src/PropertiesHandler.php @@ -3,7 +3,7 @@ * PHP: Nelson Martell Library file * * Content: - * - Class definition: [NelsonMartell] PropertiesHandler + * - Trait definition: [NelsonMartell] PropertiesHandler * * Copyright © 2015 Nelson Martell (http://nelson6e65.github.io) * @@ -19,9 +19,9 @@ namespace NelsonMartell { + use NelsonMartell\Extensions\String; use \BadMethodCallException; - /** * Permite encapsular propiedades para usar setters y getters automáticamente. * Por defecto, esta funcionalidad viene por defecto en la clase Object. @@ -29,7 +29,7 @@ * * * @author Nelson Martell - * */ + * */ trait PropertiesHandler { /** @@ -58,32 +58,11 @@ trait PropertiesHandler * */ public function __get($name) { - $error = false; - - if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists').'.'; - } - - $getter = static::$getterPrefix.$name; - - if (!$error) { - if (!method_exists($this, $getter)) { - $error = dgettext('nml', 'Property is write only').'.'; //? - } - } - - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to access to '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); + try { + $getter = $this->getPropertyGetter($name); + } catch (BadMethodCallException $error) { + $msg = nml_msg('Unable to get the property value in "{0}" class.', typeof($this)->Name); + throw new BadMethodCallException($msg, 31, $error); } return $this->$getter(); @@ -102,37 +81,155 @@ public function __get($name) * */ public function __set($name, $value) { - $error = false; + try { + $setter = $this->getPropertySetter($name); + } catch (BadMethodCallException $error) { + $msg = nml_msg('Unable to set the property value in "{0}" class.', typeof($this)->Name); + throw new BadMethodCallException($msg, 41, $error); + } + + $this->$setter($value); + } + + /** + * Ensures that property provided exists in this class. + * + * @param string $name Property name. + * @return string Same property name, but validated. + * @throws BadMethodCallException if property do not exists or name is invalid. + */ + private function ensurePropertyExists($name) + { + try { + $pName = String::ensureIsValidVarName($name); + } catch (InvalidArgumentException $error) { + $msg = nml_msg('Property name is not valid.'); + throw new BadMethodCallException($msg, 10, $error); + } if (!property_exists($this, $name)) { - $error = dgettext('nml', 'Property do not exists').'.'; + $args = [ + 'class' => typeof($this)->Name, + 'property' => $name, + ]; + + $msg = nml_msg('Property "{class}::{property}" do not exists.', $args); + + throw new BadMethodCallException($msg, 11); } - $setter = static::$setterPrefix.$name; + return $name; + } - if (!$error) { - if (!method_exists($this, $setter)) { - //La propiedad existe, pero no tiene establecido el método setter. - $error = dgettext('nml', 'Property is read only').'.'; - } + /** + * Ensures that method provided exists in this class. + * + * @param string $name Method name + * @return string Same method name, but validated. + */ + private function ensureMethodExists($name) + { + try { + $mName = String::ensureIsValidVarName($name); + } catch (InvalidArgumentException $error) { + $msg = nml_msg('Method name is not valid.'); + throw new BadMethodCallException($msg, 20, $error); } - if ($error) { - throw new BadMethodCallException( - sprintf( - dgettext( - 'nml', - "Unable to assign '%s' property in '%s' class. Reason: %s" - ), - $name, - $this->GetType()->Name, - $error - ) - ); + if (!method_exists($this, $name)) { + $args = [ + 'class' => typeof($this)->Name, + 'method' => $name, + ]; + + $msg = nml_msg('Method "{class}::{method}" do not exists.', $args); + + throw new BadMethodCallException($msg, 21); } - $this->$setter($value); + return $name; } + /** + * Ensures that there is a setter for the provided property name. + * + * @param string $name Property name. + * @return string Same property name, after checks that setter exists. + * @throws BadMethodCallException if property is not writable or inexistent. + */ + private function ensurePropertyHasSetter($name) + { + $setter = static::$setterPrefix.$this->ensurePropertyExists($name); + + try { + $setter = $this->ensureMethodExists($setter); + } catch (BadMethodCallException $error) { + $args = [ + 'class' => typeof($this)->Name, + 'name' => $name, + ]; + + $msg = nml_msg('Property "{class}::{name}" has not a setter.', $args); + + throw new BadMethodCallException($msg, 40, $error); + } + + return $name; + } + + /** + * Ensures that there is a getter for the provided property name. + * + * @param string $name Property name. + * @return string Same property name, after checks that getter exists. + * @throws BadMethodCallException if or inexistent. + */ + private function ensurePropertyHasGetter($name) + { + $getter = static::$getterPrefix.$this->ensurePropertyExists($name); + + try { + $getter = $this->ensureMethodExists($getter); + } catch (BadMethodCallException $error) { + $args = [ + 'class' => typeof($this)->Name, + 'name' => $name, + ]; + + $msg = nml_msg('Property "{class}::{name}" has not a getter.', $args); + + throw new BadMethodCallException($msg, 30, $error); + } + + return $name; + } + + /** + * Gets the property setter method name. + * + * @param string $name Property name. + * @return string + * @throws BadMethodCallException if property is not valid or has not setter. + */ + private function getPropertySetter($name) + { + $setter = static::$setterPrefix.$this->ensurePropertyHasSetter($name); + + return $setter; + } + + /** + * Gets the property getter method name. + * + * @param string $name Property name. + * @return string + * @throws BadMethodCallException if property is not valid or has not getter. + */ + private function getPropertyGetter($name) + { + $setter = static::$getterPrefix.$this->ensurePropertyHasGetter($name); + + return $setter; + } } } From e1ca5821ac7fea4a8429d8ada885a8a04c2b510b Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 11 Jun 2015 08:21:50 -0430 Subject: [PATCH 38/59] Improve PHP Docs in src/PropertiesHandler.php Applied some Squiz coding standard recomentations. --- src/PropertiesHandler.php | 101 ++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.php index 78c4b53..6bca4cc 100644 --- a/src/PropertiesHandler.php +++ b/src/PropertiesHandler.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.5.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.5.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { @@ -26,9 +26,7 @@ * Permite encapsular propiedades para usar setters y getters automáticamente. * Por defecto, esta funcionalidad viene por defecto en la clase Object. * - * - * - * @author Nelson Martell + * @author Nelson Martell * */ trait PropertiesHandler { @@ -46,6 +44,7 @@ trait PropertiesHandler */ protected static $setterPrefix = 'set'; + /** * Obtiene el valor de una propiedad, usando automáticamente el método * `$getterPrefix + nombre_propiedad` (getter). @@ -53,8 +52,11 @@ trait PropertiesHandler * Restringe la obtención de una propiedad no definida dentro de la clase * si no posee su método getter. * - * @param string $name Property name. - * @see PropertiesHandler::$getterPrefix + * @param string $name Property name. + * + * @see PropertiesHandler::$getterPrefix + * @return mixed + * @throws BadMethodCallException If unable to get the property value. * */ public function __get($name) { @@ -68,16 +70,19 @@ public function __get($name) return $this->$getter(); } + /** * Establece el valor de una propiedad, usando automáticamente el método * `$setterPrefix + nombre_propiedad` (setter). * Restringe la asignación de una propiedad no definida dentro de la clase * si no posee su método setter. * - * @param string $name Property name- - * @param mixed $value Property value. - * @see PropertiesHandler::$setterPrefix + * @param string $name Property name. + * @param mixed $value Property value. + * + * @see PropertiesHandler::$setterPrefix * @return void + * @throws BadMethodCallException If unable to set property value. * */ public function __set($name, $value) { @@ -89,14 +94,17 @@ public function __set($name, $value) } $this->$setter($value); + } + /** * Ensures that property provided exists in this class. * - * @param string $name Property name. - * @return string Same property name, but validated. - * @throws BadMethodCallException if property do not exists or name is invalid. + * @param string $name Property name. + * + * @return string Same property name, but validated. + * @throws BadMethodCallException If property do not exists or name is invalid. */ private function ensurePropertyExists($name) { @@ -107,11 +115,11 @@ private function ensurePropertyExists($name) throw new BadMethodCallException($msg, 10, $error); } - if (!property_exists($this, $name)) { + if (property_exists($this, $name) === false) { $args = [ - 'class' => typeof($this)->Name, - 'property' => $name, - ]; + 'class' => typeof($this)->Name, + 'property' => $name, + ]; $msg = nml_msg('Property "{class}::{property}" do not exists.', $args); @@ -121,11 +129,14 @@ private function ensurePropertyExists($name) return $name; } + /** * Ensures that method provided exists in this class. * - * @param string $name Method name - * @return string Same method name, but validated. + * @param string $name Method name. + * + * @return string Same method name, but validated. + * @throws BadMethodCallException If method name is invalid or do not exists. */ private function ensureMethodExists($name) { @@ -136,11 +147,11 @@ private function ensureMethodExists($name) throw new BadMethodCallException($msg, 20, $error); } - if (!method_exists($this, $name)) { + if (method_exists($this, $name) === false) { $args = [ - 'class' => typeof($this)->Name, - 'method' => $name, - ]; + 'class' => typeof($this)->Name, + 'method' => $name, + ]; $msg = nml_msg('Method "{class}::{method}" do not exists.', $args); @@ -150,12 +161,14 @@ private function ensureMethodExists($name) return $name; } + /** * Ensures that there is a setter for the provided property name. * - * @param string $name Property name. - * @return string Same property name, after checks that setter exists. - * @throws BadMethodCallException if property is not writable or inexistent. + * @param string $name Property name. + * + * @return string Same property name, after checks that setter exists. + * @throws BadMethodCallException If property is not writable or do not exists. */ private function ensurePropertyHasSetter($name) { @@ -165,9 +178,9 @@ private function ensurePropertyHasSetter($name) $setter = $this->ensureMethodExists($setter); } catch (BadMethodCallException $error) { $args = [ - 'class' => typeof($this)->Name, - 'name' => $name, - ]; + 'class' => typeof($this)->Name, + 'name' => $name, + ]; $msg = nml_msg('Property "{class}::{name}" has not a setter.', $args); @@ -177,12 +190,14 @@ private function ensurePropertyHasSetter($name) return $name; } + /** * Ensures that there is a getter for the provided property name. * - * @param string $name Property name. - * @return string Same property name, after checks that getter exists. - * @throws BadMethodCallException if or inexistent. + * @param string $name Property name. + * + * @return string Same property name, after checks that getter exists. + * @throws BadMethodCallException If property is not readable or do not exists. */ private function ensurePropertyHasGetter($name) { @@ -192,9 +207,9 @@ private function ensurePropertyHasGetter($name) $getter = $this->ensureMethodExists($getter); } catch (BadMethodCallException $error) { $args = [ - 'class' => typeof($this)->Name, - 'name' => $name, - ]; + 'class' => typeof($this)->Name, + 'name' => $name, + ]; $msg = nml_msg('Property "{class}::{name}" has not a getter.', $args); @@ -204,12 +219,14 @@ private function ensurePropertyHasGetter($name) return $name; } + /** * Gets the property setter method name. * - * @param string $name Property name. + * @param string $name Property name. + * * @return string - * @throws BadMethodCallException if property is not valid or has not setter. + * @throws BadMethodCallException If property is not valid or has not setter. */ private function getPropertySetter($name) { @@ -218,12 +235,14 @@ private function getPropertySetter($name) return $setter; } + /** * Gets the property getter method name. * - * @param string $name Property name. + * @param string $name Property name. + * * @return string - * @throws BadMethodCallException if property is not valid or has not getter. + * @throws BadMethodCallException If property is not valid or has not getter. */ private function getPropertyGetter($name) { From 06747ac8d704621110ecfd2dd1e96108e42c29d7 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 11 Jun 2015 08:34:32 -0430 Subject: [PATCH 39/59] Updated autoload.php Improved to include '*.inc' files too. --- autoload.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/autoload.php b/autoload.php index 7180d13..ba10a06 100644 --- a/autoload.php +++ b/autoload.php @@ -35,13 +35,17 @@ function autoload_NML($class) return; // Only checks for NelsonMartell namespace. } - $path = sprintf('%s'.DIRECTORY_SEPARATOR.'%s.php', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); + $path = sprintf('%s'.DIRECTORY_SEPARATOR.'%s', __DIR__, implode(DIRECTORY_SEPARATOR, $classArray)); - if (is_file($path)) { - require_once($path); + if (is_file($path.'.php')) { + $path .= '.php'; + } elseif (is_file($path.'.inc')) { + $path .= '.inc'; } else { throw new Exception(sprintf(dgettext('nml', 'Unable to auto-load "%s" class in Nelson Martell Library (NML): "%s" file was not found. You can see the API documentation (http://nelson6e65.github.io/php_nml/api) in order to check availability of all classes/namespaces in NML. Note: If you are using "NelsonMartell" as main namespace in a file that not belongs to NML, you should include it before to load "NML/autoload.php" or, using SPL autoload features, register autoload function for that class(es) using "prepend" argument for spl_autoload_register function set to TRUE.'), $class, $path)); } + + require_once($path); } spl_autoload_register('autoload_NML'); From 260172f8d67d43ef050223041494782698574024 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 11 Jun 2015 08:38:01 -0430 Subject: [PATCH 40/59] Change file extension of traits to '.inc' --- .../{CollectionIterator.php => CollectionIterator.inc} | 0 src/{PropertiesHandler.php => PropertiesHandler.inc} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/Collections/{CollectionIterator.php => CollectionIterator.inc} (100%) rename src/{PropertiesHandler.php => PropertiesHandler.inc} (100%) diff --git a/src/Collections/CollectionIterator.php b/src/Collections/CollectionIterator.inc similarity index 100% rename from src/Collections/CollectionIterator.php rename to src/Collections/CollectionIterator.inc diff --git a/src/PropertiesHandler.php b/src/PropertiesHandler.inc similarity index 100% rename from src/PropertiesHandler.php rename to src/PropertiesHandler.inc From 1019df4a30fddec9a7cd15bc721a4c0a87c566b1 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 11 Jun 2015 09:09:46 -0430 Subject: [PATCH 41/59] PSR2 autofixes --- src/Utilities/Asset.php | 9 +++------ src/Utilities/UnitTesting/Assert.php | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 1744a44..8453d05 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -68,8 +68,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) if (!($v instanceof Version)) { try { $v = Version::Parse($version); - } - catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$versions argument must be an array of Version objects '. 'or any objects parseable into Version.', @@ -89,8 +88,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) // Trata de convertir $versions en un objeto Versión try { $v = Version::Parse($versions); - } - catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$versions argument must be an array of Version objects (or empty), a Version object '. 'or any object parseable into Version.', @@ -236,8 +234,7 @@ public function getDirectoryPath($version = self::NEWEST) } else { try { $v = Version::Parse($version); - } - catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { throw new InvalidArgumentException( '$version argument must be an Version object or any object parseable into Version.', 0, diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index c1447bf..e8743ae 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -195,8 +195,7 @@ public static function methodThrowsException( try { call_user_func_array(array($obj, $method_name), $params); - } - catch (Exception $e) { + } catch (Exception $e) { $actual = typeof($e); } @@ -266,8 +265,7 @@ public static function propertyThrowsException( try { $obj->$property_name = $value; - } - catch (Exception $e) { + } catch (Exception $e) { $actual = typeof($e); } From f516947ec830a82075c24b7256d6a22eb478fc53 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 3 Jul 2015 19:49:37 -0430 Subject: [PATCH 42/59] fix: typo. --- tests/README.md | 1 - tests/README.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 tests/README.md create mode 100644 tests/README.txt diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index d33b482..0000000 --- a/tests/README.md +++ /dev/null @@ -1 +0,0 @@ -Here are located de unit tests diff --git a/tests/README.txt b/tests/README.txt new file mode 100644 index 0000000..71fc78a --- /dev/null +++ b/tests/README.txt @@ -0,0 +1 @@ +Here are located the unit tests. From 35903b194490c435b76a76481cf51eb8d61bc2c4 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 3 Jul 2015 20:15:10 -0430 Subject: [PATCH 43/59] fix: PSR2 violations: Private/protected property names. Refactorized property names, removing '_' prefix. --- src/Collections/Collection.php | 34 ++++++++++----------- src/Collections/CollectionIterator.inc | 12 ++++---- src/IntString.php | 14 ++++----- src/Type.php | 42 +++++++++++++------------- src/Utilities/Asset.php | 34 ++++++++++----------- src/Version.php | 24 +++++++-------- src/VersionComponent.php | 2 +- 7 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index fec687c..2a2a1d5 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -42,13 +42,13 @@ public function __construct() final public function __invoke($index, $value = null) { if ($value == null) { - return $this->_items[$index]; + return $this->items[$index]; } $this->setItem($index, $value); } - private $_items = array(); + private $items = array(); /** @@ -66,11 +66,11 @@ protected function insertItem($index, $newItem) } if ($index == $this->Count) { - $this->_items[$index] = null; - $this->_count++; + $this->items[$index] = null; + $this->count++; } - $this->_items[$index] = $newItem; + $this->items[$index] = $newItem; } /** @@ -80,8 +80,8 @@ protected function insertItem($index, $newItem) * */ protected function clearItems() { - $this->_items = array(); - $this->_count = 0; + $this->items = array(); + $this->count = 0; } /** @@ -97,7 +97,7 @@ protected function setItem($index, $newItem) throw new OutOfRangeException(); } - $this->_items[$index] = $newItem; + $this->items[$index] = $newItem; } /** @@ -116,7 +116,7 @@ protected function getItem($index) return null; } - return $this->_items[$index]; + return $this->items[$index]; } /** @@ -129,12 +129,12 @@ protected function removeItem($index) } for ($i = $index; $i < $this->Count - 1; $i++) { - $this->_items[$i] = $this->_items[$i + 1]; //Mueve los valores + $this->items[$i] = $this->items[$i + 1]; //Mueve los valores } - unset($this->_items[$this->Count - 1]); //Des-asigna el último elemento + unset($this->items[$this->Count - 1]); //Des-asigna el último elemento - $this->_count--; + $this->count--; } /** @@ -189,7 +189,7 @@ public function toString($format = 'r') $t = $this->GetType(); - $items = implode(', ', $this->_items); + $items = implode(', ', $this->items); $placeHoldersValues = [ 'class' => $t->ShortName, @@ -214,7 +214,7 @@ public function toString($format = 'r') * @var integer * */ public $Count; - private $_count = 0; + private $count = 0; /** * Obtiene el número de elementos incluidos en la colección. @@ -223,7 +223,7 @@ public function toString($format = 'r') * */ public function getCount() { - return $this->_count; + return $this->count; } /** @@ -259,7 +259,7 @@ public function clear() * */ public function contains($item) { - foreach ($this->_items as $i) { + foreach ($this->items as $i) { if ($item === $i) { return true; } @@ -278,7 +278,7 @@ public function contains($item) public function remove($item) { for ($i = 0; $i < $this->Count; $i++) { - if ($this->_items[$i] === $item) { + if ($this->items[$i] === $item) { $this->RemoveItem($i); } } diff --git a/src/Collections/CollectionIterator.inc b/src/Collections/CollectionIterator.inc index 6fe3961..b1e613c 100644 --- a/src/Collections/CollectionIterator.inc +++ b/src/Collections/CollectionIterator.inc @@ -28,31 +28,31 @@ namespace NelsonMartell\Collections; * */ trait CollectionIterator { - private $_iteratorPosition = 0; + private $iteratorPosition = 0; public function current() { - return $this->getItem($this->_iteratorPosition); + return $this->getItem($this->iteratorPosition); } public function rewind() { - $this->_iteratorPosition = 0; + $this->iteratorPosition = 0; } public function key() { - return $this->_iteratorPosition; + return $this->iteratorPosition; } public function next() { - ++$this->_iteratorPosition; + ++$this->iteratorPosition; } public function valid() { - $v = (bool) ($this->GetItem($this->_iteratorPosition) != null); + $v = (bool) ($this->GetItem($this->iteratorPosition) != null); return $v; } diff --git a/src/IntString.php b/src/IntString.php index 9ba6329..7201e56 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -34,13 +34,13 @@ public function __construct($intValue = 0, $stringValue = '') unset($this->IntValue, $this->StringValue); if (is_integer($intValue) or $intValue == null) { - $this->_intValue = $intValue; + $this->intValue = $intValue; } else { //Try convert to integer - $this->_intValue = (integer) $intValue; + $this->intValue = (integer) $intValue; } - $this->_stringValue = (string) $stringValue; + $this->stringValue = (string) $stringValue; } public static function parse($value) @@ -64,19 +64,19 @@ public static function parse($value) } - protected $_intValue; - protected $_stringValue; + protected $intValue; + protected $stringValue; public $IntValue; public function getIntValue() { - return (int) $this->_intValue; + return (int) $this->intValue; } public $StringValue; public function getStringValue() { - return $this->_stringValue; + return $this->stringValue; } public function toString() diff --git a/src/Type.php b/src/Type.php index b4a2681..fe02b4e 100644 --- a/src/Type.php +++ b/src/Type.php @@ -71,15 +71,15 @@ public function __construct($obj) $methods = []; } - $this->_name = $name; - $this->_shortName = $shortName; - $this->_namespace = $namespace; - $this->_vars = $vars; - $this->_methods = $methods; - $this->_reflectionObject = $ref; + $this->name = $name; + $this->shortName = $shortName; + $this->namespace = $namespace; + $this->vars = $vars; + $this->methods = $methods; + $this->reflectionObject = $ref; } - private $_reflectionObject = null; + private $reflectionObject = null; /** * Gets the name of this Type. @@ -88,7 +88,7 @@ public function __construct($obj) * @var string * */ public $Name; - private $_name; + private $name; /** * Getter for Type::Name property. @@ -97,7 +97,7 @@ public function __construct($obj) * */ public function getName() { - return $this->_name; + return $this->name; } /** @@ -107,7 +107,7 @@ public function getName() * @var string * */ public $ShortName; - private $_shortName = null; + private $shortName = null; /** * Getter for Type::ShortName property. @@ -117,7 +117,7 @@ public function getName() * */ public function getShortName() { - return $this->_shortName; + return $this->shortName; } /** @@ -128,7 +128,7 @@ public function getShortName() * @var string|NULL * */ public $Namespace; - private $_namespace; + private $namespace; /** * Getter for Type::Namespace property. @@ -138,7 +138,7 @@ public function getShortName() * */ public function getNamespace() { - return $this->_namespace; + return $this->namespace; } /** @@ -149,13 +149,13 @@ public function getNamespace() * @var array * */ public $Vars; - private $_vars = null; + private $vars = null; public function getVars() { - if ($this->_vars == null) { - $this->_vars = $this->_reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); + if ($this->vars == null) { + $this->vars = $this->reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); } - return $this->_vars; + return $this->vars; } /** @@ -166,13 +166,13 @@ public function getVars() * @var array * */ public $Methods; - private $_methods = null; + private $methods = null; public function getMethods() { - if ($this->_methods == null) { - $this->_methods = $this->_reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); + if ($this->methods == null) { + $this->methods = $this->reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); } - return $this->_methods; + return $this->methods; } /** diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index 8453d05..db9171f 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -42,8 +42,8 @@ public function __construct($name = null, $versions = null, $cdnUri = null) unset($this->Name, $this->Versions, $this->ShortName, $this->CdnUri, $this->RootDirectory); if ($name == null) { - $this->_name = ''; - $this->_shortName = ''; + $this->name = ''; + $this->shortName = ''; } else { $this->Name = $name; } @@ -59,7 +59,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } if (is_array($versions)) { - $this->_versions = array(); + $this->versions = array(); if (count($versions) > 0) { $i = 0; @@ -78,7 +78,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } } - $this->_versions[$i] = $v; + $this->versions[$i] = $v; $i += 1; } @@ -97,7 +97,7 @@ public function __construct($name = null, $versions = null, $cdnUri = null) ); } - $this->_versions = array($v); + $this->versions = array($v); } $this->CdnUri = $cdnUri; @@ -114,11 +114,11 @@ public function __construct($name = null, $versions = null, $cdnUri = null) * @var string Nombre del recurso * */ public $Name; - private $_name; + private $name; public function getName() { - return $this->_name; + return $this->name; } public function setName($value) @@ -131,9 +131,9 @@ public function setName($value) throw new InvalidArgumentException('$value argument can not be an empty or whitespace string.'); } - $this->_name = trim($value); + $this->name = trim($value); - $this->_shortName = str_replace(' ', '-', strtolower($this->_name)); + $this->shortName = str_replace(' ', '-', strtolower($this->name)); } /** @@ -142,11 +142,11 @@ public function setName($value) * @var string Nombre del recurso en su forma generada * */ public $ShortName; - private $_shortName; + private $shortName; public function getShortName() { - return $this->_shortName; + return $this->shortName; } /** @@ -155,11 +155,11 @@ public function getShortName() * @var List Lista de versiones del recurso * */ public $Versions; - private $_versions; + private $versions; public function getVersions() { - return $this->_versions; + return $this->versions; } /** @@ -174,16 +174,16 @@ public function getVersions() * @var string CDN * */ public $CdnUri; - private $_cdnUri; + private $cdnUri; public function getCdnUri() { - return $this->_cdnUri; + return $this->cdnUri; } public function setCdnUri($value) { - $this->_cdnUri = (string) $value; + $this->cdnUri = (string) $value; } @@ -223,7 +223,7 @@ public function getDirectoryPath($version = self::NEWEST) $v = $this->Versions[0]; if ($c > 1) { - usort($this->_versions, array("NelsonMartell\\Version", "Compare")); + usort($this->versions, array("NelsonMartell\\Version", "Compare")); $v = $this->Versions[0]; diff --git a/src/Version.php b/src/Version.php index 5082a91..5cebb29 100644 --- a/src/Version.php +++ b/src/Version.php @@ -109,10 +109,10 @@ public function __construct($major, $minor, $build = null, $revision = null) ); } - $this->_major = $major; - $this->_minor = $minor; - $this->_build = VersionComponent::Parse($build); - $this->_revision = VersionComponent::Parse($revision); + $this->major = $major; + $this->minor = $minor; + $this->build = VersionComponent::Parse($build); + $this->revision = VersionComponent::Parse($revision); } /** @@ -174,11 +174,11 @@ public static function parse($value) * @var int Componente principal del número de versión * */ public $Major; - private $_major; + private $major; public function getMajor() { - return $this->_major; + return $this->major; } @@ -190,11 +190,11 @@ public function getMajor() * @var int Componente secundario del número de versión * */ public $Minor; - private $_minor; + private $minor; public function getMinor() { - return $this->_minor; + return $this->minor; } /** @@ -205,11 +205,11 @@ public function getMinor() * @var VersionComponent Componente de compilación del número de versión * */ public $Build; - private $_build; + private $build; public function getBuild() { - return $this->_build; + return $this->build; } /** @@ -220,11 +220,11 @@ public function getBuild() * @var VersionComponent Componente de revisión del número de versión * */ public $Revision; - private $_revision; + private $revision; public function getRevision() { - return $this->_revision; + return $this->revision; } diff --git a/src/VersionComponent.php b/src/VersionComponent.php index 943fa07..bb22a06 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -127,7 +127,7 @@ public function isDefault() * */ public function getIntValue() { - return $this->_intValue; + return $this->intValue; } From 08020cdbf080390bff93c355b746e4ef00212781 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 3 Jul 2015 20:23:52 -0430 Subject: [PATCH 44/59] fix: PSR2 violations: Line exceeds 120 characters. --- src/Type.php | 8 +++-- src/VersionComponent.php | 64 ++++++++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/Type.php b/src/Type.php index fe02b4e..3ca486e 100644 --- a/src/Type.php +++ b/src/Type.php @@ -153,7 +153,9 @@ public function getNamespace() public function getVars() { if ($this->vars == null) { - $this->vars = $this->reflectionObject->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); + $this->vars = $this->reflectionObject->getProperties( + ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED + ); } return $this->vars; } @@ -170,7 +172,9 @@ public function getVars() public function getMethods() { if ($this->methods == null) { - $this->methods = $this->reflectionObject->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); + $this->methods = $this->reflectionObject->getMethods( + ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED + ); } return $this->methods; } diff --git a/src/VersionComponent.php b/src/VersionComponent.php index bb22a06..db28f3b 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -38,24 +38,50 @@ public function __construct($intValue = null, $stringValue = null) if (is_integer($intValue)) { //Validaciones: if ($this->IntValue < 0) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) must be positive; "%s" given.'), '$intValue', 1, $intValue)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + 'Invalid argument value. "%s" (argument %s) must be positive; "%s" given.' + ), + '$intValue', + 1, + $intValue + ) + ); } } else { if ($intValue === null) { if ($stringValue != null) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" must be NULL when "%s" is NULL; "%s" given.'), '$stringValue', '$intValue', $stringValue)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + 'Invalid argument type. "%s" must be NULL when "%s" is NULL; "%s" given.' + ), + '$stringValue', + '$intValue', + $stringValue + ) + ); } } else { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an integer or NULL; "%s" given.'), '$intValue', 1, $intValue)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + 'Invalid argument type. "%s" (argument %s) must be an integer or NULL; "%s" given.' + ), + '$intValue', + 1, + $intValue + ) + ); } } //Only integer or null if (is_string($stringValue)) { if ($this->StringValue != '') { - // if ($this->IntValue == 0) { - // throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid format: "%s". VersionComponent can not be a text-only value. $intValue must be > 0 to append it text.'), '$stringValue', 2, $stringValue)); - // } Sí puede ser 0 - $pattern = '~^([a-z])$~'; // 1 char if (strlen($this->StringValue) > 1) { @@ -74,13 +100,33 @@ public function __construct($intValue = null, $stringValue = null) } if (!$correct) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument value. "%s" (argument %s) has invalid chars: "%s".'), '$stringValue', 2, $stringValue)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + 'Invalid argument value. "%s" (argument %s) has invalid chars: "%s".' + ), + '$stringValue', + 2, + $stringValue + ) + ); } } } else { if ($stringValue != null) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Invalid argument type. "%s" (argument %s) must be an string or NULL; "%s" given.'), '$stringValue', 2, $stringValue)); + throw new InvalidArgumentException( + sprintf( + dgettext( + 'nml', + 'Invalid argument type. "%s" (argument %s) must be an string or NULL; "%s" given.' + ), + '$stringValue', + 2, + $stringValue + ) + ); } } // Only integer or null } From 326147c103bf82cbd9b62631c2143c5daa4a222c Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Fri, 3 Jul 2015 20:30:50 -0430 Subject: [PATCH 45/59] add: Note in PropertiesHandler. :memo: --- src/PropertiesHandler.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PropertiesHandler.inc b/src/PropertiesHandler.inc index 6bca4cc..1d9c065 100644 --- a/src/PropertiesHandler.inc +++ b/src/PropertiesHandler.inc @@ -26,6 +26,10 @@ namespace NelsonMartell { * Permite encapsular propiedades para usar setters y getters automáticamente. * Por defecto, esta funcionalidad viene por defecto en la clase Object. * + * Nota: Los nombres de las propiedades deberían estar en CamelCase (primera + * letra en mayúscula) para que, por ejemplo, los getters queden `getName()` + * y se accedan $obj->Name. + * * @author Nelson Martell * */ trait PropertiesHandler From 85dd914c751351c731e7be72fe47280e53ee611d Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 4 Jul 2015 11:21:33 -0430 Subject: [PATCH 46/59] fix: $args, in nml_nmsg function. --- src/functions.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 3574032..3ee2f26 100644 --- a/src/functions.php +++ b/src/functions.php @@ -57,12 +57,16 @@ function nml_msg($message, $args = null) * incluir en las cadenas de formato del mensaje. * @return string * @see dngettext - * @see String::Format + * @see String::format * */ function nml_nmsg($singular, $plural, $n, $args = null) { - $s = String::Format($singular, array_slice(func_get_args(), 1)); - $p = String::Format($plural, array_slice(func_get_args(), 1)); + if (func_num_args() > 4) { + $args = array_slice(func_get_args(), 3); + } + + $s = String::Format($singular, $args); + $p = String::Format($plural, $args); return dngettext(NML_GETTEXT_DOMAIN, $s, $p, $n); } From 6827096f62220545e39801fbf0705a47b50ad1d5 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 4 Jul 2015 16:06:45 -0430 Subject: [PATCH 47/59] fix: Getting untranslated resources. Use gettext in format message before to replace values into placeholders. --- src/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/functions.php b/src/functions.php index 3ee2f26..10fd22b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -37,12 +37,13 @@ * */ function nml_msg($message, $args = null) { + $translated = dgettext(NML_GETTEXT_DOMAIN, $message); + if (func_num_args() > 2) { $args = array_slice(func_get_args(), 1); } - $s = String::format($message, $args); - return dgettext(NML_GETTEXT_DOMAIN, $s); + return String::format($translated, $args); } @@ -61,14 +62,13 @@ function nml_msg($message, $args = null) * */ function nml_nmsg($singular, $plural, $n, $args = null) { + $translated = dngettext(NML_GETTEXT_DOMAIN, $singular, $plural, $n); + if (func_num_args() > 4) { $args = array_slice(func_get_args(), 3); } - $s = String::Format($singular, $args); - $p = String::Format($plural, $args); - - return dngettext(NML_GETTEXT_DOMAIN, $s, $p, $n); + return String::format($translated, $args); } if (!function_exists('typeof')) { From 6421a293c48f80c7f0c3f20b9ae636a53e3e0ca1 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 4 Jul 2015 22:03:21 -0430 Subject: [PATCH 48/59] add: Implementation of nml_msg in 'Object'. + minor fixxes. --- Locale/es/LC_MESSAGES/nml.mo | Bin 5316 -> 2109 bytes Locale/es/LC_MESSAGES/nml.po | 266 ++++++++++++++++++++++------------- Locale/nml.pot | 178 +++++++++++++++++++++++ src/Object.php | 58 ++++---- 4 files changed, 383 insertions(+), 119 deletions(-) create mode 100644 Locale/nml.pot diff --git a/Locale/es/LC_MESSAGES/nml.mo b/Locale/es/LC_MESSAGES/nml.mo index 3d804df80c2bf12ac211e77bf4d4c8d8f74dfb29..e2871258cab5d1380b6948f12af33dbf323552f8 100644 GIT binary patch delta 369 zcmXZXy-EW?6o%n%*VQEJvKS3$L?sa{wlMJ*C5b`N!X}{L4~T8>CISg!Ct`6B?7WDz z4OrMI_F}NrE3o$6BnLj8!_07I<~8b0w7)042T=i;BQ268J(5(xkxE#^8Xn;;-eDd; za2kJc2jxopP{%{O#$$ZLahx9+oQrVARa;jy>uhvJr9FJc1N_4Xt7Fmm*6PAv653Q7}Si%B~u5182>GF(!ICcbpbj@^5+*7RQN yCSA8~rjgoOUfC$Dtyv9j=AtWgg3h*DfGYSQ%xEJnc*pFQFZ;l1;qC$WDgXi2#A3n(msJ+U>6D z?W%U{@HlZnAjE|W5{DckEeDj_N(gD^fRK!i&-9G#kfoLJH{D(J ztKX}>`X>K8^ZYLvu9xxoB0m4Zr-jek&*2ZQtM6m%3&3l@2>3nV72wZ+SAl;7(%hx@ zGxj;)S>Pt{3h?*9hrsK=_<6=|0)GVjCh!lyj{;x*0Ars8wt$}jUYXqA0bazt0(ODF z26ljd25tcV1H26U+6NhX5k8baTKC5vW=sR$1^yJ+{Rm?(;r;J`U&8(0uqfI6H}D$p zD<5O*1~3Dz0DlW?0sju%1wQw2#{LSt4crH|J`wzX2>cH2{{*Bs&b<)gxCrF9{|0aw z_$H9-{~Y)#@GrpEfM-4#p5F!1{jY%Eg`fWb-o<_VDaL*R`~~na@bjOBFF?u_Qpym% zzcAcilzX_s5H>@o4DR|1)27$b^jq*5C16;Ry@(IonqE|g4^8fn28PtKGx)$2Uu%HB zUZTIP?pe#*tqW&UuAI#6O3c5{TNm;0hvD5os7$62-#RR0;$#~0WsJ7V5xD>|X0>T$dhCtOPrhXwm(%s0&A>HlrQ;)ExyI}RSz2W@Z`p{Q z_y*6f3+=~R1f~W@{On|s<)R!`xzvuU0Y9rnE*no^zsjLe7#Du-}4!a^bPQw=>Wo4huKg5-T!ZZvbrcBQpqC}VU0 z>y@TJUXOTce8J_Rvaa!1S&o#Y-019RHW*JIl-LvD@xI|h^j9c>UG=5eN5$iK*H^{z zqF#lH4092i%%KWW6E!E@qNX}^#sPBN9DNV>Cyc(UML$D_7%q|o@zOV+v4-LBAjyQa z5x*maHQMK-G1po()c?=K%9&1PkT~Bnehu^qza=xQ!godKWR~$A)h|VP#M`%acfc-w z>;Rm?A58Y@z*HIp^KDb{gc?+aroYzPM!^!l5z+pz*d94o#A|EXFYt&!P zGHb=CxUchUO%!T{yf9@dOTQgPGI^7W1MryWt4yH}u=@l&^BzmPM#Zs(KnlJ4yE_pF z1EF`e2mA(L-Myq+r#Xv?Ehx zpj@3~RVqQfAc%p%Iw)aCDTb~IWSH(E1h?rueF)=C8t z5)OviQh~0MsV8Mmet|JzKNl|c9f#RIqErqLCHG`tVg#k8^`-*&$D8Cg%?#nn{sEwsLNDdWRmzDzHM*4RSD zzjBlO)Q;Wmzk%Z~j%j#iVK*>AaMP39#3OQab>5rloCRONOJuaOopx$Y=e?V~__Q6= zjm|IiZtr)l6TxFcbZ&s>V}9X$cfE7|Lg&Id?_P@6@%_?88rZob4-}n(CyZN<&v(PP z9bsK(zZBYL!kO~e;#X$7t>b8z8py+|M`C15B<-t9J3BLYw#Qbt!xutJ) zzAm*aLr6U%Q*=o;`fAk0n{eBCO;}k7H;Q?*)XS<;WS!U1nmFBb;cxBcg$*9QZnic5 z@+R-DY|Q5GnW{|Wbvh6w+Bx_&wZ11snT&d{-#L#JqP6hPmPy0HY)p4HW~nL4Waw0L zT$qi(Ghi{1nuza7WD{qc=!=;?1KTgEvs33RXsj^xB#G9vaLa(K8w)>+kvlS}N=xT3 zcM28a*kDSlRPam$)i!<-WZSWk*zwfOVCi}eL|pKps3cgFQUE2V5>axQO$p63l$})z zZ-}`uaU$yWRbfEN2jfSOb_VOrj4Vn!1EN{M2nah1%B{4(M6d3Ypow%4AD4FuIt1%w zr13zr1}r1!HXlEB1}jSI#*d)&%+pmKh*o%x2@C5=9xNvDA^Xs2rK0ogbSJ#L zY?x^7DN>dsq!!lpxs{qWEh&o7?hu&bA-1m;UJ7%YVKeAmK( zr;E)kVu56&4nmJnxd-@ZC2>}09A-qFJ)#a|i7JMTTMN!a5f5P>;~^>0XV;!#Z;s?! z71-U|RJJf$k@lpPgH3F86o!i9gPBvH6w^e3g3I^7S40Vxh(d!P78Ph>a$*grSL`F0 z4&6e(7N9LvAu>f`k1^hr4u-OJ9v2 zqw*P^(Jy;yf`<8G{0`|`;=`uwjo3{pWi52ccjRfJa33~Q?<%#z\n" "Language-Team: \n" "Language: es\n" @@ -16,141 +16,94 @@ msgstr "" "X-Poedit-SearchPath-0: ../../../src\n" "X-Poedit-SearchPath-1: ../../..\n" -#: ../../../autoload.php:39 -#, php-format -msgid "" -"Unable to auto-load \"%s\" class in Nelson Martell Library (NML): \"%s\" " -"file was not found. You can see the API documentation (http://nelson6e65." -"github.io/php_nml/api) in order to check availability of all classes/" -"namespaces in NML. Note: If you are using \"NelsonMartell\" as main " -"namespace in a file that not belongs to NML, you should include it before to " -"load \"NML/autoload.php\" or, using SPL autoload features, register autoload " -"function for that class(es) using \"prepend\" argument for " -"spl_autoload_register function set to TRUE." -msgstr "" -"No se puede cargar la clase \"%s\" en Nelson Martell Library (NML): El " -"archivo \"%s\" no fue encontrado. Puedes ver la documentación de la API " -"(http://nelson6e65.github.io/php_nml/api) para chequear la disponibilidad de " -"todas las clases/namespaces en NML. Nota: Si estás usando \"NelsonMartell\" " -"como espacio de nombres principal en un archivo que no pertenece a NML, " -"deberías incluirlo antes de cargar \"NML/autoload.php\" ó, usando las " -"funciones de autocarga de SPL, registrar la función autoload para esa(s) " -"clase(s) usando el argumento \"prepend\" de la función spl_autoload_register " -"establecido en TRUE." - -#: ../../../src/Collections/Collection.php:168 -#, php-format -msgid "%1$s (%2$d items): { %3$s }" -msgstr "%1$s (%2$d elementos): { %3$s }" +#: src/Extensions/String.php:84 +msgid "Provided object must not be NULL." +msgstr "" -#: ../../../src/Object.php:67 ../../../src/Object.php:96 -msgid "Property do not exists" -msgstr "La propiedad no existe" +#: src/Extensions/String.php:101 +msgid "Provided object must to be an string; \"{0}\" given." +msgstr "" -#: ../../../src/Object.php:74 -msgid "Property is write only" -msgstr "La propiedad es de sólo escritura" +#: src/Extensions/String.php:118 +msgid "Provided string must not be empty." +msgstr "" -#: ../../../src/Object.php:79 -#, php-format -msgid "Unable to access to '%s' property in '%s' class. Reason: %s" -msgstr "No se puede acceder a la propiedad '%s' en la clase '%s'. Razón: %s" +#: src/Extensions/String.php:135 +msgid "Provided string must not be white spaces." +msgstr "" -#: ../../../src/Object.php:103 -msgid "Property is read only" -msgstr "La propiedad es de sólo lectura" +#: src/Extensions/String.php:153 +msgid "" +"Provided string do not follows PHP variables naming convention: \"{0}\"." +msgstr "" -#: ../../../src/Object.php:108 -#, php-format -msgid "Unable to assign '%s' property in '%s' class. Reason: %s" -msgstr "No se puede asignar la propiedad '%s' en la clase '%s'. Razón: %s" +#: src/Object.php:96 +msgid "Using default \"{base_class}::{function}\" ({access}) method." +msgstr "" -#: ../../../src/Object.php:137 -#, php-format +#: src/Object.php:98 src/Object.php:139 msgid "" -"Using default %s method. You can replace its behavior, overriding it by " -"creating %s::ToString() public method." +" You can replace (override) its behavior by creating \"{class}::" +"{function}\" ({access}) method." msgstr "" -"Usando el método %s predeterminado. Puedes reemplazar su comportamiento, " -"sobrescribiéndolo, creando el método público %s::ToString()." -#: ../../../src/Object.php:157 -#, php-format +#: src/Object.php:134 msgid "" -"You implemented IEquatable interface, but using default Object::Equals() " -"method. You must override it, creating %s::Equals() public method." +"You implemented IEquatable, but using default \"{base_class}::" +"{function}\" ({access}) method." msgstr "" -"Has implementado la interfaz IEquatable, pero se está usando el método " -"predeterminado Object::Equals(). Debes sobreescribirlo creando el método " -"público %s::Equals()." - -#: ../../../src/Type.php:75 -msgid "To get the name, use Type::Name property instead." -msgstr "Para obtener el nombre, usa la propiedad Type::Name más bien." - -#: ../../../src/Type.php:93 -msgid "To get vars, use Type::Vars property instead." -msgstr "Para obtener las variables, usa la propiedad Type::Vars más bien." - -#: ../../../src/Type.php:111 -msgid "To get methods, use Type::Methods property instead." -msgstr "Para obtener los métodos, usa la propiedad Type::Methods más bien." -#: ../../../src/Utilities/Asset.php:52 +#: src/Utilities/Asset.php:53 msgid "Can not specify $versions argument if $name argument is null." msgstr "" "No se puede especificar el argumento $versions si el argumento $name es null." -#: ../../../src/Utilities/Asset.php:204 +#: src/Utilities/Asset.php:218 msgid "Asset has not versions." msgstr "Recurso no tiene versiones definidas." -#: ../../../src/Utilities/Asset.php:228 +#: src/Utilities/Asset.php:246 #, php-format msgid "Asset has not version %s." msgstr "Recurso no tiene definida la versión %s." -#: ../../../src/Utilities/UnitTesting/Assert.php:83 +#: src/Utilities/UnitTesting/Assert.php:89 #, php-format msgid "%5$s failed. Expected: (%3$s) \"%4$s\". Actual: (%1$s) \"%2$s\"." msgstr "%5$s ha fallado. Se esperaba: (%3$s) \"%4$s\". Real: (%1$s) \"%2$s\"." -#: ../../../src/Utilities/UnitTesting/Assert.php:86 -#: ../../../src/Utilities/UnitTesting/Assert.php:131 -#: ../../../src/Utilities/UnitTesting/Assert.php:187 -#: ../../../src/Utilities/UnitTesting/Assert.php:204 -#: ../../../src/Utilities/UnitTesting/Assert.php:241 -#: ../../../src/Utilities/UnitTesting/Assert.php:258 +#: src/Utilities/UnitTesting/Assert.php:98 +#: src/Utilities/UnitTesting/Assert.php:151 +#: src/Utilities/UnitTesting/Assert.php:220 +#: src/Utilities/UnitTesting/Assert.php:242 +#: src/Utilities/UnitTesting/Assert.php:290 +#: src/Utilities/UnitTesting/Assert.php:312 #, php-format msgid "Message: %s" msgstr "Mensaje: %s" -#: ../../../src/Utilities/UnitTesting/Assert.php:128 +#: src/Utilities/UnitTesting/Assert.php:142 #, php-format msgid "%5$s failed. Not expected: (%3$s) \"%4$s\". Actual: (%1$s) \"%2$s\"." msgstr "" "%5$s ha fallado. No se esperaba: (%3$s) \"%4$s\". Real: (%1$s) \"%2$s\"." -#: ../../../src/Utilities/UnitTesting/Assert.php:184 -#: ../../../src/Utilities/UnitTesting/Assert.php:201 -#: ../../../src/Utilities/UnitTesting/Assert.php:238 -#: ../../../src/Utilities/UnitTesting/Assert.php:255 +#: src/Utilities/UnitTesting/Assert.php:213 +#: src/Utilities/UnitTesting/Assert.php:235 +#: src/Utilities/UnitTesting/Assert.php:283 +#: src/Utilities/UnitTesting/Assert.php:305 #, php-format msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "%1$s ha fallado. Se esperaba: \"%2$s\". Real: \"%3$s\"." -#: ../../../src/Version.php:49 ../../../src/Version.php:53 +#: src/Version.php:57 src/Version.php:73 #, php-format msgid "" "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' " -"given. Convert value or use the static method Version::Parse(string|mixed) " -"to create a new instance from an string." +"given. Convert value or use the static method Version::parse." msgstr "" -"Tipo inválido de argumento. '%s' (argumento %s) debe ser una instancia de " -"'%s', '%s' given. Convierte el valor o usa el método estático Version::" -"Parse(string|mixed) para crear una nueva instancia de una cadena." -#: ../../../src/Version.php:57 ../../../src/Version.php:61 +#: src/Version.php:89 src/Version.php:103 #, php-format msgid "" "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' " @@ -159,14 +112,14 @@ msgstr "" "Valor inválido de argumento. '%s' (argumento %s) debe ser un número " "positivo; '%s' dado." -#: ../../../src/Version.php:90 +#: src/Version.php:143 #, php-format msgid "Unable to parse. Argument passed has an invalid format: '%s'." msgstr "" "No se puede convertir. El argumento que se ha pasado tiene un formato " "inválido '%s'." -#: ../../../src/VersionComponent.php:36 +#: src/VersionComponent.php:45 #, php-format msgid "" "Invalid argument value. \"%s\" (argument %s) must be positive; \"%s\" given." @@ -174,13 +127,136 @@ msgstr "" "Valor inválido de argumento. \"%s\" (argumento %s) debe ser positivo; se dio " "\"%s\"." -#: ../../../src/VersionComponent.php:62 +#: src/VersionComponent.php:60 +#, php-format +msgid "" +"Invalid argument type. \"%s\" must be NULL when \"%s\" is NULL; \"%s\" given." +msgstr "" + +#: src/VersionComponent.php:73 +#, php-format +msgid "" +"Invalid argument type. \"%s\" (argument %s) must be an integer or NULL; \"%s" +"\" given." +msgstr "" + +#: src/VersionComponent.php:107 #, php-format msgid "Invalid argument value. \"%s\" (argument %s) has invalid chars: \"%s\"." msgstr "" "Valor inválido de argumento. \"%s\" (argumento %s) tiene caracteres " "inválidos: \"%s\"." +#: src/VersionComponent.php:123 +#, php-format +msgid "" +"Invalid argument type. \"%s\" (argument %s) must be an string or NULL; \"%s" +"\" given." +msgstr "" + +#: src/PropertiesHandler.inc:70 +msgid "Unable to get the property value in \"{0}\" class." +msgstr "" + +#: src/PropertiesHandler.inc:96 +msgid "Unable to set the property value in \"{0}\" class." +msgstr "" + +#: src/PropertiesHandler.inc:118 +msgid "Property name is not valid." +msgstr "" + +#: src/PropertiesHandler.inc:128 +msgid "Property \"{class}::{property}\" do not exists." +msgstr "" + +#: src/PropertiesHandler.inc:150 +msgid "Method name is not valid." +msgstr "" + +#: src/PropertiesHandler.inc:160 +msgid "Method \"{class}::{method}\" do not exists." +msgstr "" + +#: src/PropertiesHandler.inc:189 +msgid "Property \"{class}::{name}\" has not a setter." +msgstr "" + +#: src/PropertiesHandler.inc:218 +msgid "Property \"{class}::{name}\" has not a getter." +msgstr "" + +#~ msgid "" +#~ "Using default \"{0}\" method. You can replace its behavior, overriding it " +#~ "by creating \"{1}::{2}\" public method." +#~ msgstr "" +#~ "Usando el método predeterminado \"{0}\". You can replace its behavior, " +#~ "overriding it by creating \"{1}::{2}\" public method." + +#~ msgid "" +#~ "You implemented IEquatable interface, but using default Object::Equals() " +#~ "method. You must override it, creating %s::Equals() public method." +#~ msgstr "" +#~ "Has implementado la interfaz IEquatable, pero se está usando el método " +#~ "predeterminado Object::Equals(). Debes sobreescribirlo creando el método " +#~ "público %s::Equals()." + +#~ msgid "" +#~ "Unable to auto-load \"%s\" class in Nelson Martell Library (NML): \"%s\" " +#~ "file was not found. You can see the API documentation (http://nelson6e65." +#~ "github.io/php_nml/api) in order to check availability of all classes/" +#~ "namespaces in NML. Note: If you are using \"NelsonMartell\" as main " +#~ "namespace in a file that not belongs to NML, you should include it before " +#~ "to load \"NML/autoload.php\" or, using SPL autoload features, register " +#~ "autoload function for that class(es) using \"prepend\" argument for " +#~ "spl_autoload_register function set to TRUE." +#~ msgstr "" +#~ "No se puede cargar la clase \"%s\" en Nelson Martell Library (NML): El " +#~ "archivo \"%s\" no fue encontrado. Puedes ver la documentación de la API " +#~ "(http://nelson6e65.github.io/php_nml/api) para chequear la disponibilidad " +#~ "de todas las clases/namespaces en NML. Nota: Si estás usando " +#~ "\"NelsonMartell\" como espacio de nombres principal en un archivo que no " +#~ "pertenece a NML, deberías incluirlo antes de cargar \"NML/autoload.php\" " +#~ "ó, usando las funciones de autocarga de SPL, registrar la función " +#~ "autoload para esa(s) clase(s) usando el argumento \"prepend\" de la " +#~ "función spl_autoload_register establecido en TRUE." + +#~ msgid "%1$s (%2$d items): { %3$s }" +#~ msgstr "%1$s (%2$d elementos): { %3$s }" + +#~ msgid "Property do not exists" +#~ msgstr "La propiedad no existe" + +#~ msgid "Property is write only" +#~ msgstr "La propiedad es de sólo escritura" + +#~ msgid "Unable to access to '%s' property in '%s' class. Reason: %s" +#~ msgstr "No se puede acceder a la propiedad '%s' en la clase '%s'. Razón: %s" + +#~ msgid "Property is read only" +#~ msgstr "La propiedad es de sólo lectura" + +#~ msgid "Unable to assign '%s' property in '%s' class. Reason: %s" +#~ msgstr "No se puede asignar la propiedad '%s' en la clase '%s'. Razón: %s" + +#~ msgid "To get the name, use Type::Name property instead." +#~ msgstr "Para obtener el nombre, usa la propiedad Type::Name más bien." + +#~ msgid "To get vars, use Type::Vars property instead." +#~ msgstr "Para obtener las variables, usa la propiedad Type::Vars más bien." + +#~ msgid "To get methods, use Type::Methods property instead." +#~ msgstr "Para obtener los métodos, usa la propiedad Type::Methods más bien." + +#~ msgid "" +#~ "Invalid argument type. '%s' (argument %s) must be an instance of '%s', " +#~ "'%s' given. Convert value or use the static method Version::Parse(string|" +#~ "mixed) to create a new instance from an string." +#~ msgstr "" +#~ "Tipo inválido de argumento. '%s' (argumento %s) debe ser una instancia de " +#~ "'%s', '%s' given. Convierte el valor o usa el método estático Version::" +#~ "Parse(string|mixed) para crear una nueva instancia de una cadena." + #~ msgid "" #~ "Unable to auto-load \"%s\" class: File \"%s\" do not exists. See the API " #~ "documentation (http://nelson6e65.github.io/php_nml/api) in order to " diff --git a/Locale/nml.pot b/Locale/nml.pot new file mode 100644 index 0000000..2754636 --- /dev/null +++ b/Locale/nml.pot @@ -0,0 +1,178 @@ +msgid "" +msgstr "" +"Project-Id-Version: PHP: Nelson Martell Library 1.0\n" +"POT-Creation-Date: 2015-07-04 21:55-0430\n" +"PO-Revision-Date: 2015-07-04 21:55-0430\n" +"Last-Translator: Nelson Martell \n" +"Language-Team: \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.7.1\n" +"X-Poedit-Basepath: ..\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-KeywordsList: nml_msg;nml_nmsg\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-SearchPath-0: src\n" +"X-Poedit-SearchPath-1: tests\n" + +#: src/Extensions/String.php:84 +msgid "Provided object must not be NULL." +msgstr "" + +#: src/Extensions/String.php:101 +msgid "Provided object must to be an string; \"{0}\" given." +msgstr "" + +#: src/Extensions/String.php:118 +msgid "Provided string must not be empty." +msgstr "" + +#: src/Extensions/String.php:135 +msgid "Provided string must not be white spaces." +msgstr "" + +#: src/Extensions/String.php:153 +msgid "" +"Provided string do not follows PHP variables naming convention: \"{0}\"." +msgstr "" + +#: src/Object.php:96 +msgid "Using default \"{base_class}::{function}\" ({access}) method." +msgstr "" + +#: src/Object.php:98 src/Object.php:139 +msgid "" +" You can replace (override) its behavior by creating \"{class}::" +"{function}\" ({access}) method." +msgstr "" + +#: src/Object.php:134 +msgid "" +"You implemented IEquatable, but using default \"{base_class}::" +"{function}\" ({access}) method." +msgstr "" + +#: src/Utilities/Asset.php:53 +msgid "Can not specify $versions argument if $name argument is null." +msgstr "" + +#: src/Utilities/Asset.php:218 +msgid "Asset has not versions." +msgstr "" + +#: src/Utilities/Asset.php:246 +#, php-format +msgid "Asset has not version %s." +msgstr "" + +#: src/Utilities/UnitTesting/Assert.php:89 +#, php-format +msgid "%5$s failed. Expected: (%3$s) \"%4$s\". Actual: (%1$s) \"%2$s\"." +msgstr "" + +#: src/Utilities/UnitTesting/Assert.php:98 +#: src/Utilities/UnitTesting/Assert.php:151 +#: src/Utilities/UnitTesting/Assert.php:220 +#: src/Utilities/UnitTesting/Assert.php:242 +#: src/Utilities/UnitTesting/Assert.php:290 +#: src/Utilities/UnitTesting/Assert.php:312 +#, php-format +msgid "Message: %s" +msgstr "" + +#: src/Utilities/UnitTesting/Assert.php:142 +#, php-format +msgid "%5$s failed. Not expected: (%3$s) \"%4$s\". Actual: (%1$s) \"%2$s\"." +msgstr "" + +#: src/Utilities/UnitTesting/Assert.php:213 +#: src/Utilities/UnitTesting/Assert.php:235 +#: src/Utilities/UnitTesting/Assert.php:283 +#: src/Utilities/UnitTesting/Assert.php:305 +#, php-format +msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." +msgstr "" + +#: src/Version.php:57 src/Version.php:73 +#, php-format +msgid "" +"Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' " +"given. Convert value or use the static method Version::parse." +msgstr "" + +#: src/Version.php:89 src/Version.php:103 +#, php-format +msgid "" +"Invalid argument value. '%s' (argument %s) must be a positive number; '%s' " +"given." +msgstr "" + +#: src/Version.php:143 +#, php-format +msgid "Unable to parse. Argument passed has an invalid format: '%s'." +msgstr "" + +#: src/VersionComponent.php:45 +#, php-format +msgid "" +"Invalid argument value. \"%s\" (argument %s) must be positive; \"%s\" given." +msgstr "" + +#: src/VersionComponent.php:60 +#, php-format +msgid "" +"Invalid argument type. \"%s\" must be NULL when \"%s\" is NULL; \"%s\" given." +msgstr "" + +#: src/VersionComponent.php:73 +#, php-format +msgid "" +"Invalid argument type. \"%s\" (argument %s) must be an integer or NULL; \"%s" +"\" given." +msgstr "" + +#: src/VersionComponent.php:107 +#, php-format +msgid "Invalid argument value. \"%s\" (argument %s) has invalid chars: \"%s\"." +msgstr "" + +#: src/VersionComponent.php:123 +#, php-format +msgid "" +"Invalid argument type. \"%s\" (argument %s) must be an string or NULL; \"%s" +"\" given." +msgstr "" + +#: src/PropertiesHandler.inc:70 +msgid "Unable to get the property value in \"{0}\" class." +msgstr "" + +#: src/PropertiesHandler.inc:96 +msgid "Unable to set the property value in \"{0}\" class." +msgstr "" + +#: src/PropertiesHandler.inc:118 +msgid "Property name is not valid." +msgstr "" + +#: src/PropertiesHandler.inc:128 +msgid "Property \"{class}::{property}\" do not exists." +msgstr "" + +#: src/PropertiesHandler.inc:150 +msgid "Method name is not valid." +msgstr "" + +#: src/PropertiesHandler.inc:160 +msgid "Method \"{class}::{method}\" do not exists." +msgstr "" + +#: src/PropertiesHandler.inc:189 +msgid "Property \"{class}::{name}\" has not a setter." +msgstr "" + +#: src/PropertiesHandler.inc:218 +msgid "Property \"{class}::{name}\" has not a getter." +msgstr "" diff --git a/src/Object.php b/src/Object.php index 450251e..6e42435 100644 --- a/src/Object.php +++ b/src/Object.php @@ -71,7 +71,7 @@ final public function __toString() { //$args = null; //list($args) = func_get_args(); - return $this->ToString(); + return $this->toString(); } /** @@ -82,22 +82,24 @@ final public function __toString() * */ public function toString() { - $type = $this->GetType(); + $type = $this->getType(); if (defined('CODE_ANALYSIS')) { if ($type->Name != 'NelsonMartell\Object') { - trigger_error( - sprintf( - dgettext( - 'nml', - 'Using default %s method. '. - 'You can replace its behavior, overriding it by creating %s::ToString() public method.' - ), - __METHOD__, - $type->Name - ), - E_USER_NOTICE + $args = [ + 'access' => 'public', + 'base_class' => __CLASS__, + 'class' => $type->Name, + 'function' => __FUNCTION__, + ]; + + $msg = nml_msg('Using default "{base_class}::{function}" ({access}) method.', $args); + $msg .= nml_msg( + ' You can replace (override) its behavior by creating "{class}::{function}" ({access}) method.', + $args ); + + trigger_error($msg, E_USER_NOTICE); } } @@ -119,18 +121,26 @@ public function equals($other) { if (defined('CODE_ANALYSIS')) { if ($this instanceof IEquatable) { - $type = $this->GetType(); - trigger_error( - sprintf( - dgettext( - 'nml', - 'You implemented IEquatable interface, but using default Object::Equals() method. '. - 'You must override it, creating %s::Equals() public method.' - ), - $type->Name - ), - E_USER_NOTICE + $type = $this->getType(); + + $args = [ + 'access' => 'public', + 'base_class' => __CLASS__, + 'class' => $type->Name, + 'function' => __FUNCTION__, + ]; + + $msg = nml_msg( + 'You implemented IEquatable, but using default "{base_class}::{function}" ({access}) method.', + $args ); + + $msg .= nml_msg( + ' You can replace (override) its behavior by creating "{class}::{function}" ({access}) method.', + $args + ); + + trigger_error($msg, E_USER_NOTICE); } } From eedc31236821ca9c3391bc2b25ce91f6fcff72fb Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 4 Jul 2015 22:50:12 -0430 Subject: [PATCH 49/59] add: Implementation of nml_msg in 'Version' constructor. --- src/Version.php | 98 +++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/src/Version.php b/src/Version.php index 5cebb29..58157e8 100644 --- a/src/Version.php +++ b/src/Version.php @@ -50,63 +50,73 @@ public function __construct($major, $minor, $build = null, $revision = null) unset($this->Major, $this->Minor, $this->Build, $this->Revision); if (!is_integer($major)) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. ". - "Convert value or use the static method Version::parse." - ), - "major", - 1, - typeof(0), - typeof($major) - ) + $args = [ + 'class' => $this->getType()->Name, + 'name' => 'major', + 'pos' => 0, + 'expected' => typeof(0), + 'actual' => typeof($major), + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', + $args ); + $msg .= nml_msg(' Convert value or use the "{class}::parse" (static) method.', $args); + + throw new InvalidArgumentException($msg); } if (!is_integer($minor)) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - "Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' given. ". - "Convert value or use the static method Version::parse." - ), - "minor", - 2, - typeof(0), - typeof($minor) - ) + $args = [ + 'class' => $this->getType()->Name, + 'name' => 'minor', + 'pos' => 1, + 'expected' => typeof(0), + 'actual' => typeof($minor), + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', + $args ); + $msg .= nml_msg(' Convert value or use the "{class}::parse" (static) method.', $args); + + throw new InvalidArgumentException($msg); } if ($major < 0) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given." - ), - "major", - 1, - $major - ) + $args = [ + 'name' => 'major', + 'pos' => 0, + 'actual' => $major, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be a positive number; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } if ($minor < 0) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - "Invalid argument value. '%s' (argument %s) must be a positive number; '%s' given." - ), - "minor", - 2, - $minor - ) + $args = [ + 'name' => 'minor', + 'pos' => 1, + 'actual' => $minor, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be a positive number; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } $this->major = $major; From 6ddee3b0f3aadc35d6c9082c01a90ae76a5c6ddc Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sat, 4 Jul 2015 23:21:25 -0430 Subject: [PATCH 50/59] add: Version::parse tries to convert from int, float and array. add: Some parsing errors. --- Locale/nml.pot | 37 +++++++++++++++++++++++++------------ src/Version.php | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/Locale/nml.pot b/Locale/nml.pot index 2754636..7f28c4f 100644 --- a/Locale/nml.pot +++ b/Locale/nml.pot @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: PHP: Nelson Martell Library 1.0\n" -"POT-Creation-Date: 2015-07-04 21:55-0430\n" -"PO-Revision-Date: 2015-07-04 21:55-0430\n" +"POT-Creation-Date: 2015-07-04 23:19-0430\n" +"PO-Revision-Date: 2015-07-04 23:20-0430\n" "Last-Translator: Nelson Martell \n" "Language-Team: \n" "Language: en\n" @@ -95,23 +95,36 @@ msgstr "" msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "" -#: src/Version.php:57 src/Version.php:73 -#, php-format +#: src/Version.php:61 src/Version.php:80 +msgid "Invalid argument type." +msgstr "" + +#: src/Version.php:63 src/Version.php:82 msgid "" -"Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' " -"given. Convert value or use the static method Version::parse." +" \"{name}\" (position {pos}) must to be an instance of \"{expected}\"; " +"\"{actual}\" given." msgstr "" -#: src/Version.php:89 src/Version.php:103 -#, php-format +#: src/Version.php:66 src/Version.php:85 +msgid " Convert value or use the \"{class}::parse\" (static) method." +msgstr "" + +#: src/Version.php:97 src/Version.php:113 +msgid "Invalid argument value." +msgstr "" + +#: src/Version.php:99 src/Version.php:115 msgid "" -"Invalid argument value. '%s' (argument %s) must be a positive number; '%s' " +" \"{name}\" (position {pos}) must to be a positive number; \"{actual}\" " "given." msgstr "" -#: src/Version.php:143 -#, php-format -msgid "Unable to parse. Argument passed has an invalid format: '%s'." +#: src/Version.php:161 +msgid "Unable to parse. Argument passed has an invalid type: \"{0}\"." +msgstr "" + +#: src/Version.php:169 +msgid "Unable to parse. Argument passed has an invalid format: \"{0}\"." msgstr "" #: src/VersionComponent.php:45 diff --git a/src/Version.php b/src/Version.php index 58157e8..281a614 100644 --- a/src/Version.php +++ b/src/Version.php @@ -129,7 +129,7 @@ public function __construct($major, $minor, $build = null, $revision = null) * Convierte una cadena a su representación del tipo Version. * * - * @param string Cadena a convertir. + * @param Version|string|int|float|array Objeto a convertir. * @return Version Objeto convertido desde $value. * */ public static function parse($value) @@ -138,23 +138,37 @@ public static function parse($value) return $value; } - $version = (string) $value; + $version = []; - $version = explode('.', $version); + // Try to convert into an array + if (is_integer($value)) { + // Integer for major value + $version = [$value, 0]; + } elseif (is_float($value)) { + // Integer part as major, and decimal part as minor + $version = sprintf("%F", $value); + $version = explode('.', $version); + + } elseif (is_array($value)) { + // Implode first 4 places for major, minor, build and revision respectivally. + $version = array_slice($value, 0, 4); + + } elseif (is_string($value)) { + $version = explode('.', $value); + + } else { + $msg = nml_msg('Unable to parse. Argument passed has an invalid type: "{0}".', typeof($value)); + throw new InvalidArgumentException($msg); + } + + // $value ya debería ser un array. $c = count($version); if ($c > 4 || $c < 2) { + $msg = nml_msg('Unable to parse. Argument passed has an invalid format: "{0}".', $value); //var_dump($version); - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - "Unable to parse. Argument passed has an invalid format: '%s'." - ), - $value - ) - ); + throw new InvalidArgumentException($msg); } @@ -171,8 +185,6 @@ public static function parse($value) } } - - return new Version($major, $minor, $build, $revision); } From b975b92068fb21ea74409580385031462174a96c Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sun, 5 Jul 2015 00:12:26 -0430 Subject: [PATCH 51/59] Implementation of nml_msg in 'VersionComponent'. --- Locale/es/LC_MESSAGES/nml.mo | Bin 2109 -> 1392 bytes Locale/es/LC_MESSAGES/nml.po | 90 +++++++++++++++-------------- Locale/nml.pot | 46 ++++----------- src/VersionComponent.php | 107 +++++++++++++++++------------------ 4 files changed, 112 insertions(+), 131 deletions(-) diff --git a/Locale/es/LC_MESSAGES/nml.mo b/Locale/es/LC_MESSAGES/nml.mo index e2871258cab5d1380b6948f12af33dbf323552f8..01082a364985fbd0e02c50e0768ff8f75ef85665 100644 GIT binary patch delta 262 zcmXwzuL{Co6i4qib>a+S@DC_#VZkC3v52CA*cR-Tfm1M823GM6gkkdm>}HLkFJUwf zEk=*ZesDPVyWD&EPPr(vzULD=A!(?<1Ps{2H&>{`4Lb0KKC~2(GG5^#-r_Dk;P3te zmsF7_Zt^w~A_LsRL%hK?k&#>|Y#I@EaUuCXFvaW&ZP6i)M#0_Rhf|m_kz-Y{6vOp{ lz?=JR(+Ol;XnQwV=?eH@By#`d<6U+cnkO&@I&A~z!s3b&e%5KA@C{iTi_SKUxDueKY1hA z)qo#iZwOq&{);ym+XDU!d<^^-SOYfSVyp@zU>o=yunYVh=y~ItjC}=s0rdQT0FQuw z1Cf$Xham(59m7^xCxE?;QSp<>cLNB@l4H8}j-ON;%a#v>%qWfd&Ph&vM`^;Bs;kR( zDdt;!SBT87*Zi7QH?A~a@y9h-t)KH+@$7!PBs=fCuN|jZyz3EcSxb(Ogyjm}$7HP3 zidSvSt~|m1wos+5MPYJq%9kfjmJ2g1#-tpV1HP=pm=<=xUu0R#cGa=SWI8{=vY;3R z*(JU*W2mA=pOl=K_ea85-!tE_SKt^I*6|+kTwCenF*QS=A*Sl(M0cw8&V^*AL}EsT zg2p{EOR)pnb~ZckVjb&XIq6Hc2;!5^qHnR|3^BXZtM4(R03 zsTgS;lYLm(6KYtXA5oXYIN|)d_6a9jY45go=C%9!wzYD2Us3loM`?~u+}%7AQZ;$` zKFGC>x=*6bxt&jGKqlHzeVs}*O!#I`y2_W)XQar4k~*4F>CnIXaRVn|8GR}&<-&~; z9#=Y9VMG=^!TsP3s=Qp<)@qZ7X=_FC+b!OxHRt|^x-fm(_Rp4Zry;Ky`ymO_A9cVV z)e#}S8~&{6FEGq)8grXUke88w!ep69b<7V5-O5o;Ps~;3fG%mwOMNaVMR2`JXcigv zHMfg_uS0S`{lZuc`QT3C26##Xsbng6CW7{y{S?IKlI28X$j*EqMInd0pfqFxJ(7K4 zIAt?^(F^)y<%N?{qd*y?>6ys1@xR8iAE8hhf#xh11xn)wUYitwhyoICKs0lnY1ONf zrUbpRWTrx+o4(Ph)D!jlf5!9D71EqB7Etc9U&dr0NkI@nUV5bdC9yUsE1n1STI_9K jEA-z\n" "Language-Team: \n" "Language: es\n" @@ -96,62 +96,43 @@ msgstr "" msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "%1$s ha fallado. Se esperaba: \"%2$s\". Real: \"%3$s\"." -#: src/Version.php:57 src/Version.php:73 -#, php-format -msgid "" -"Invalid argument type. '%s' (argument %s) must be an instance of '%s', '%s' " -"given. Convert value or use the static method Version::parse." +#: src/Version.php:61 src/Version.php:80 src/VersionComponent.php:67 +#: src/VersionComponent.php:122 +msgid "Invalid argument type." msgstr "" -#: src/Version.php:89 src/Version.php:103 -#, php-format +#: src/Version.php:63 src/Version.php:82 src/VersionComponent.php:69 +#: src/VersionComponent.php:124 msgid "" -"Invalid argument value. '%s' (argument %s) must be a positive number; '%s' " -"given." +" \"{name}\" (position {pos}) must to be an instance of \"{expected}\"; " +"\"{actual}\" given." msgstr "" -"Valor inválido de argumento. '%s' (argumento %s) debe ser un número " -"positivo; '%s' dado." -#: src/Version.php:143 -#, php-format -msgid "Unable to parse. Argument passed has an invalid format: '%s'." +#: src/Version.php:66 src/Version.php:85 +msgid " Convert value or use the \"{class}::parse\" (static) method." msgstr "" -"No se puede convertir. El argumento que se ha pasado tiene un formato " -"inválido '%s'." -#: src/VersionComponent.php:45 -#, php-format -msgid "" -"Invalid argument value. \"%s\" (argument %s) must be positive; \"%s\" given." +#: src/Version.php:97 src/Version.php:113 src/VersionComponent.php:47 +#: src/VersionComponent.php:103 +msgid "Invalid argument value." msgstr "" -"Valor inválido de argumento. \"%s\" (argumento %s) debe ser positivo; se dio " -"\"%s\"." -#: src/VersionComponent.php:60 -#, php-format +#: src/Version.php:99 src/Version.php:115 src/VersionComponent.php:49 msgid "" -"Invalid argument type. \"%s\" must be NULL when \"%s\" is NULL; \"%s\" given." +" \"{name}\" (position {pos}) must to be a positive number; \"{actual}\" " +"given." msgstr "" -#: src/VersionComponent.php:73 -#, php-format -msgid "" -"Invalid argument type. \"%s\" (argument %s) must be an integer or NULL; \"%s" -"\" given." +#: src/Version.php:161 +msgid "Unable to parse. Argument passed has an invalid type: \"{0}\"." msgstr "" -#: src/VersionComponent.php:107 -#, php-format -msgid "Invalid argument value. \"%s\" (argument %s) has invalid chars: \"%s\"." +#: src/Version.php:169 +msgid "Unable to parse. Argument passed has an invalid format: \"{0}\"." msgstr "" -"Valor inválido de argumento. \"%s\" (argumento %s) tiene caracteres " -"inválidos: \"%s\"." -#: src/VersionComponent.php:123 -#, php-format -msgid "" -"Invalid argument type. \"%s\" (argument %s) must be an string or NULL; \"%s" -"\" given." +#: src/VersionComponent.php:105 +msgid " \"{name}\" (position {pos}) has invalid chars; \"{actual}\" given." msgstr "" #: src/PropertiesHandler.inc:70 @@ -186,6 +167,31 @@ msgstr "" msgid "Property \"{class}::{name}\" has not a getter." msgstr "" +#~ msgid "" +#~ "Invalid argument value. '%s' (argument %s) must be a positive number; " +#~ "'%s' given." +#~ msgstr "" +#~ "Valor inválido de argumento. '%s' (argumento %s) debe ser un número " +#~ "positivo; '%s' dado." + +#~ msgid "Unable to parse. Argument passed has an invalid format: '%s'." +#~ msgstr "" +#~ "No se puede convertir. El argumento que se ha pasado tiene un formato " +#~ "inválido '%s'." + +#~ msgid "" +#~ "Invalid argument value. \"%s\" (argument %s) must be positive; \"%s\" " +#~ "given." +#~ msgstr "" +#~ "Valor inválido de argumento. \"%s\" (argumento %s) debe ser positivo; se " +#~ "dio \"%s\"." + +#~ msgid "" +#~ "Invalid argument value. \"%s\" (argument %s) has invalid chars: \"%s\"." +#~ msgstr "" +#~ "Valor inválido de argumento. \"%s\" (argumento %s) tiene caracteres " +#~ "inválidos: \"%s\"." + #~ msgid "" #~ "Using default \"{0}\" method. You can replace its behavior, overriding it " #~ "by creating \"{1}::{2}\" public method." diff --git a/Locale/nml.pot b/Locale/nml.pot index 7f28c4f..8f3f0ff 100644 --- a/Locale/nml.pot +++ b/Locale/nml.pot @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: PHP: Nelson Martell Library 1.0\n" -"POT-Creation-Date: 2015-07-04 23:19-0430\n" -"PO-Revision-Date: 2015-07-04 23:20-0430\n" +"POT-Creation-Date: 2015-07-05 00:10-0430\n" +"PO-Revision-Date: 2015-07-05 00:10-0430\n" "Last-Translator: Nelson Martell \n" "Language-Team: \n" "Language: en\n" @@ -95,11 +95,13 @@ msgstr "" msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "" -#: src/Version.php:61 src/Version.php:80 +#: src/Version.php:61 src/Version.php:80 src/VersionComponent.php:67 +#: src/VersionComponent.php:122 msgid "Invalid argument type." msgstr "" -#: src/Version.php:63 src/Version.php:82 +#: src/Version.php:63 src/Version.php:82 src/VersionComponent.php:69 +#: src/VersionComponent.php:124 msgid "" " \"{name}\" (position {pos}) must to be an instance of \"{expected}\"; " "\"{actual}\" given." @@ -109,11 +111,12 @@ msgstr "" msgid " Convert value or use the \"{class}::parse\" (static) method." msgstr "" -#: src/Version.php:97 src/Version.php:113 +#: src/Version.php:97 src/Version.php:113 src/VersionComponent.php:47 +#: src/VersionComponent.php:103 msgid "Invalid argument value." msgstr "" -#: src/Version.php:99 src/Version.php:115 +#: src/Version.php:99 src/Version.php:115 src/VersionComponent.php:49 msgid "" " \"{name}\" (position {pos}) must to be a positive number; \"{actual}\" " "given." @@ -127,35 +130,8 @@ msgstr "" msgid "Unable to parse. Argument passed has an invalid format: \"{0}\"." msgstr "" -#: src/VersionComponent.php:45 -#, php-format -msgid "" -"Invalid argument value. \"%s\" (argument %s) must be positive; \"%s\" given." -msgstr "" - -#: src/VersionComponent.php:60 -#, php-format -msgid "" -"Invalid argument type. \"%s\" must be NULL when \"%s\" is NULL; \"%s\" given." -msgstr "" - -#: src/VersionComponent.php:73 -#, php-format -msgid "" -"Invalid argument type. \"%s\" (argument %s) must be an integer or NULL; \"%s" -"\" given." -msgstr "" - -#: src/VersionComponent.php:107 -#, php-format -msgid "Invalid argument value. \"%s\" (argument %s) has invalid chars: \"%s\"." -msgstr "" - -#: src/VersionComponent.php:123 -#, php-format -msgid "" -"Invalid argument type. \"%s\" (argument %s) must be an string or NULL; \"%s" -"\" given." +#: src/VersionComponent.php:105 +msgid " \"{name}\" (position {pos}) has invalid chars; \"{actual}\" given." msgstr "" #: src/PropertiesHandler.inc:70 diff --git a/src/VersionComponent.php b/src/VersionComponent.php index db28f3b..accf790 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -38,45 +38,39 @@ public function __construct($intValue = null, $stringValue = null) if (is_integer($intValue)) { //Validaciones: if ($this->IntValue < 0) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - 'Invalid argument value. "%s" (argument %s) must be positive; "%s" given.' - ), - '$intValue', - 1, - $intValue - ) + $args = [ + 'name' => 'intValue', + 'pos' => 0, + 'actual' => $intValue, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be a positive number; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } } else { if ($intValue === null) { - if ($stringValue != null) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - 'Invalid argument type. "%s" must be NULL when "%s" is NULL; "%s" given.' - ), - '$stringValue', - '$intValue', - $stringValue - ) - ); - } + // Ignore string value id intValue is null. + $this->stringValue = $stringValue = ''; } else { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - 'Invalid argument type. "%s" (argument %s) must be an integer or NULL; "%s" given.' - ), - '$intValue', - 1, - $intValue - ) + $args = [ + 'name' => 'intValue', + 'pos' => 0, + 'expected' => typeof(0).' or '.typeof(null), + 'actual' => typeof($intValue), + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } } //Only integer or null @@ -100,35 +94,40 @@ public function __construct($intValue = null, $stringValue = null) } if (!$correct) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - 'Invalid argument value. "%s" (argument %s) has invalid chars: "%s".' - ), - '$stringValue', - 2, - $stringValue - ) + $args = [ + 'name' => 'stringValue', + 'pos' => 1, + 'actual' => $stringValue, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) has invalid chars; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } } } else { if ($stringValue != null) { - throw new InvalidArgumentException( - sprintf( - dgettext( - 'nml', - 'Invalid argument type. "%s" (argument %s) must be an string or NULL; "%s" given.' - ), - '$stringValue', - 2, - $stringValue - ) + $args = [ + 'name' => 'stringValue', + 'pos' => 1, + 'expected' => typeof('string').' or '.typeof(null), + 'actual' => typeof($stringValue), + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an instance of "{expected}"; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } - } // Only integer or null + } // Only string or null } public static function parse($value = null) From 9b0679689aa1a2428a935c4fdeea26482d38f75b Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sun, 5 Jul 2015 01:23:27 -0430 Subject: [PATCH 52/59] Implementation of nml_msg in 'Utilities\Asset'. --- Locale/es/LC_MESSAGES/nml.mo | Bin 1392 -> 1058 bytes Locale/es/LC_MESSAGES/nml.po | 87 +++++++++++++++++++------- Locale/nml.pot | 71 +++++++++++++++------ src/Utilities/Asset.php | 116 ++++++++++++++++++++++++++++------- 4 files changed, 210 insertions(+), 64 deletions(-) diff --git a/Locale/es/LC_MESSAGES/nml.mo b/Locale/es/LC_MESSAGES/nml.mo index 01082a364985fbd0e02c50e0768ff8f75ef85665..f808b4691764704c69bf177fbc06db6e6656f6c8 100644 GIT binary patch delta 177 zcmeyswTPqso)F7a1|VPsVi_QI0b+I_&H-W&=m26pAnpWW8z9~R#126G6^OZk*o={Z zL4t{a!3jtk1NqU+3=EDyx*te`%(@7qLF&X<7#M&`7=T?qPJYH1 j&unOAG}(hml?6x}ZZ2dBW#aKo%_~mKO0`l@EoJ}!#@-gx delta 528 zcmZvXJxc>Y5QgWHsKIm=et^XkNg+arh)qy5_|ZjzU}v-BCUNDm7jEwYRw0GG5(En? zD_hAg5JB`$SXu`wOW)*@5Y&N}XLojH_ML}xf4=>(kh&#A8d`*F5|wHRSnYT9U5v8Q5_FTL31pURONv6CKnKK9uPHzRR{B{r_BDq!&@7X7J3 U)~){aG~5O=$4eNiF5)GA03$eqb^rhX diff --git a/Locale/es/LC_MESSAGES/nml.po b/Locale/es/LC_MESSAGES/nml.po index 5be3472..acaca90 100644 --- a/Locale/es/LC_MESSAGES/nml.po +++ b/Locale/es/LC_MESSAGES/nml.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: PHP: Nelson Martell Library 1.0\n" -"POT-Creation-Date: 2015-07-05 00:10-0430\n" -"PO-Revision-Date: 2015-07-05 00:10-0430\n" +"POT-Creation-Date: 2015-07-05 01:20-0430\n" +"PO-Revision-Date: 2015-07-05 01:21-0430\n" "Last-Translator: Nelson Martell \n" "Language-Team: \n" "Language: es\n" @@ -53,19 +53,61 @@ msgid "" "{function}\" ({access}) method." msgstr "" -#: src/Utilities/Asset.php:53 -msgid "Can not specify $versions argument if $name argument is null." +#: src/Utilities/Asset.php:59 src/Utilities/Asset.php:90 +#: src/Utilities/Asset.php:119 src/Utilities/Asset.php:182 +#: src/Utilities/Asset.php:313 src/Version.php:97 src/Version.php:113 +#: src/VersionComponent.php:47 src/VersionComponent.php:103 +msgid "Invalid argument value." msgstr "" -"No se puede especificar el argumento $versions si el argumento $name es null." -#: src/Utilities/Asset.php:218 -msgid "Asset has not versions." -msgstr "Recurso no tiene versiones definidas." +#: src/Utilities/Asset.php:61 +msgid "" +" \"{name}\" (position {pos}) can not be specified if \"{name2}\" (position " +"{pos2}) is \"null\"." +msgstr "" -#: src/Utilities/Asset.php:246 -#, php-format -msgid "Asset has not version %s." -msgstr "Recurso no tiene definida la versión %s." +#: src/Utilities/Asset.php:92 +msgid "" +" \"{name}\" (position {pos}) must to be an array of \"{expected}\" elements " +"(or any parseable into \"{expected}\"); the array given has an invalid " +"\"{actual}\" element." +msgstr "" + +#: src/Utilities/Asset.php:121 +msgid "" +" \"{name}\" (position {pos}) must to be an array of \"{expected}\" elements, " +"an instance of \"{expected}\" or any object parseable into \"{expected}\"; " +"\"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:164 src/Utilities/Asset.php:302 src/Version.php:61 +#: src/Version.php:80 src/VersionComponent.php:67 src/VersionComponent.php:122 +msgid "Invalid argument type." +msgstr "" + +#: src/Utilities/Asset.php:166 +msgid "" +" \"{class}::{property}\" must to be an instance of \"{expected}\"; " +"\"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:184 +msgid " \"{class}::{property}\" value can not be empty or whitespace." +msgstr "" + +#: src/Utilities/Asset.php:275 +msgid "This Asset has not versions." +msgstr "" + +#: src/Utilities/Asset.php:304 +msgid "" +" \"{name}\" (position {pos}) must to be an instance of \"{expected}\" (or " +"compatible); \"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:314 +msgid " Asset has not the version \"{version}\"." +msgstr "" #: src/Utilities/UnitTesting/Assert.php:89 #, php-format @@ -96,11 +138,6 @@ msgstr "" msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "%1$s ha fallado. Se esperaba: \"%2$s\". Real: \"%3$s\"." -#: src/Version.php:61 src/Version.php:80 src/VersionComponent.php:67 -#: src/VersionComponent.php:122 -msgid "Invalid argument type." -msgstr "" - #: src/Version.php:63 src/Version.php:82 src/VersionComponent.php:69 #: src/VersionComponent.php:124 msgid "" @@ -112,11 +149,6 @@ msgstr "" msgid " Convert value or use the \"{class}::parse\" (static) method." msgstr "" -#: src/Version.php:97 src/Version.php:113 src/VersionComponent.php:47 -#: src/VersionComponent.php:103 -msgid "Invalid argument value." -msgstr "" - #: src/Version.php:99 src/Version.php:115 src/VersionComponent.php:49 msgid "" " \"{name}\" (position {pos}) must to be a positive number; \"{actual}\" " @@ -167,6 +199,17 @@ msgstr "" msgid "Property \"{class}::{name}\" has not a getter." msgstr "" +#~ msgid "Can not specify $versions argument if $name argument is null." +#~ msgstr "" +#~ "No se puede especificar el argumento $versions si el argumento $name es " +#~ "null." + +#~ msgid "Asset has not versions." +#~ msgstr "Recurso no tiene versiones definidas." + +#~ msgid "Asset has not version %s." +#~ msgstr "Recurso no tiene definida la versión %s." + #~ msgid "" #~ "Invalid argument value. '%s' (argument %s) must be a positive number; " #~ "'%s' given." diff --git a/Locale/nml.pot b/Locale/nml.pot index 8f3f0ff..814e79b 100644 --- a/Locale/nml.pot +++ b/Locale/nml.pot @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: PHP: Nelson Martell Library 1.0\n" -"POT-Creation-Date: 2015-07-05 00:10-0430\n" -"PO-Revision-Date: 2015-07-05 00:10-0430\n" +"POT-Creation-Date: 2015-07-05 01:20-0430\n" +"PO-Revision-Date: 2015-07-05 01:21-0430\n" "Last-Translator: Nelson Martell \n" "Language-Team: \n" "Language: en\n" @@ -54,17 +54,60 @@ msgid "" "{function}\" ({access}) method." msgstr "" -#: src/Utilities/Asset.php:53 -msgid "Can not specify $versions argument if $name argument is null." +#: src/Utilities/Asset.php:59 src/Utilities/Asset.php:90 +#: src/Utilities/Asset.php:119 src/Utilities/Asset.php:182 +#: src/Utilities/Asset.php:313 src/Version.php:97 src/Version.php:113 +#: src/VersionComponent.php:47 src/VersionComponent.php:103 +msgid "Invalid argument value." msgstr "" -#: src/Utilities/Asset.php:218 -msgid "Asset has not versions." +#: src/Utilities/Asset.php:61 +msgid "" +" \"{name}\" (position {pos}) can not be specified if \"{name2}\" (position " +"{pos2}) is \"null\"." msgstr "" -#: src/Utilities/Asset.php:246 -#, php-format -msgid "Asset has not version %s." +#: src/Utilities/Asset.php:92 +msgid "" +" \"{name}\" (position {pos}) must to be an array of \"{expected}\" elements " +"(or any parseable into \"{expected}\"); the array given has an invalid " +"\"{actual}\" element." +msgstr "" + +#: src/Utilities/Asset.php:121 +msgid "" +" \"{name}\" (position {pos}) must to be an array of \"{expected}\" elements, " +"an instance of \"{expected}\" or any object parseable into \"{expected}\"; " +"\"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:164 src/Utilities/Asset.php:302 src/Version.php:61 +#: src/Version.php:80 src/VersionComponent.php:67 src/VersionComponent.php:122 +msgid "Invalid argument type." +msgstr "" + +#: src/Utilities/Asset.php:166 +msgid "" +" \"{class}::{property}\" must to be an instance of \"{expected}\"; " +"\"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:184 +msgid " \"{class}::{property}\" value can not be empty or whitespace." +msgstr "" + +#: src/Utilities/Asset.php:275 +msgid "This Asset has not versions." +msgstr "" + +#: src/Utilities/Asset.php:304 +msgid "" +" \"{name}\" (position {pos}) must to be an instance of \"{expected}\" (or " +"compatible); \"{actual}\" given." +msgstr "" + +#: src/Utilities/Asset.php:314 +msgid " Asset has not the version \"{version}\"." msgstr "" #: src/Utilities/UnitTesting/Assert.php:89 @@ -95,11 +138,6 @@ msgstr "" msgid "%1$s failed. Expected: \"%2$s\". Actual: \"%3$s\"." msgstr "" -#: src/Version.php:61 src/Version.php:80 src/VersionComponent.php:67 -#: src/VersionComponent.php:122 -msgid "Invalid argument type." -msgstr "" - #: src/Version.php:63 src/Version.php:82 src/VersionComponent.php:69 #: src/VersionComponent.php:124 msgid "" @@ -111,11 +149,6 @@ msgstr "" msgid " Convert value or use the \"{class}::parse\" (static) method." msgstr "" -#: src/Version.php:97 src/Version.php:113 src/VersionComponent.php:47 -#: src/VersionComponent.php:103 -msgid "Invalid argument value." -msgstr "" - #: src/Version.php:99 src/Version.php:115 src/VersionComponent.php:49 msgid "" " \"{name}\" (position {pos}) must to be a positive number; \"{actual}\" " diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index db9171f..e81c558 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -49,9 +49,20 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } if ($this->Name == '' && $versions != null) { - throw new InvalidArgumentException( - dgettext('nml', 'Can not specify $versions argument if $name argument is null.') + $args = [ + 'name' => 'versions', + 'pos' => 1, + 'name2' => 'name', + 'pos2' => 0, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) can not be specified if "{name2}" (position {pos2}) is "null".', + $args ); + + throw new InvalidArgumentException($msg); } if ($versions == null) { @@ -67,14 +78,23 @@ public function __construct($name = null, $versions = null, $cdnUri = null) $v = $version; if (!($v instanceof Version)) { try { - $v = Version::Parse($version); + $v = Version::parse($version); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException( - '$versions argument must be an array of Version objects '. - 'or any objects parseable into Version.', - 0, - $e + $args = [ + 'name' => 'versions', + 'pos' => 1, + 'expected' => typeof(new Version(1, 0))->Name, + 'actual' => typeof($version)->Name, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an array of "{expected}" elements (or any'. + ' parseable into "{expected}"); the array given has an invalid "{actual}" element.', + $args ); + + throw new InvalidArgumentException($msg, 0, $e); } } @@ -87,14 +107,23 @@ public function __construct($name = null, $versions = null, $cdnUri = null) } else { // Trata de convertir $versions en un objeto Versión try { - $v = Version::Parse($versions); + $v = Version::parse($versions); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException( - '$versions argument must be an array of Version objects (or empty), a Version object '. - 'or any object parseable into Version.', - 0, - $e + $args = [ + 'name' => 'versions', + 'pos' => 1, + 'expected' => typeof(new Version(1, 0))->Name, + 'actual' => typeof($versions)->Name, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an array of "{expected}" elements, an instance of'. + ' "{expected}" or any object parseable into "{expected}"; "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg, 0, $e); } $this->versions = array($v); @@ -124,11 +153,39 @@ public function getName() public function setName($value) { if (!is_string($value)) { - throw new InvalidArgumentException('$value argument must be string.'); + $args = [ + 'class' => $this->getType()->Name, + 'property' => 'Name', + 'pos' => 0, + 'expected' => 'string', + 'actual' => typeof($value)->Name, + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{class}::{property}" must to be an instance of "{expected}"; "{actual}" given.', + $args + ); + + throw new InvalidArgumentException($msg); } if (str_word_count($value) == 0) { - throw new InvalidArgumentException('$value argument can not be an empty or whitespace string.'); + $args = [ + 'class' => $this->getType()->Name, + 'property' => 'Name', + 'pos' => 0, + 'expected' => 'string', + 'actual' => typeof($value)->Name, + ]; + + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg( + ' "{class}::{property}" value can not be empty or whitespace.', + $args + ); + + throw new InvalidArgumentException($msg); } $this->name = trim($value); @@ -215,7 +272,7 @@ public function getDirectoryPath($version = self::NEWEST) $c = count($this->Versions); if ($c == 0) { - throw new LogicException(dgettext('nml', 'Asset has not versions.')); + throw new LogicException(nml_msg('This Asset has not versions.')); } $v = $version; @@ -233,17 +290,30 @@ public function getDirectoryPath($version = self::NEWEST) } } else { try { - $v = Version::Parse($version); + $v = Version::parse($version); } catch (InvalidArgumentException $e) { - throw new InvalidArgumentException( - '$version argument must be an Version object or any object parseable into Version.', - 0, - $e + $args = [ + 'name' => 'version', + 'pos' => 0, + 'expected' => typeof(new Version(1, 0))->Name, + 'actual' => typeof($version), + ]; + + $msg = nml_msg('Invalid argument type.'); + $msg .= nml_msg( + ' "{name}" (position {pos}) must to be an instance of "{expected}" (or compatible);'. + ' "{actual}" given.', + $args ); + + throw new InvalidArgumentException($msg); } if (array_search($v, $this->Versions) === false) { - throw new InvalidArgumentException(sprintf(dgettext('nml', 'Asset has not version %s.'), $v)); + $msg = nml_msg('Invalid argument value.'); + $msg .= nml_msg(' Asset has not the version "{version}".', ['version' => $v]); + + throw new InvalidArgumentException($msg); } } From a7dea4af5219cec24d68b8277d8bec4ab070b729 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Sun, 5 Jul 2015 10:21:55 -0430 Subject: [PATCH 53/59] add: Various files to initialize NML. --- autoload.php | 62 +++++++++++++------------------------------ composer.json | 5 +++- config/autoloader.php | 47 ++++++++++++++++++++++++++++++++ config/bootstrap.php | 21 +++++++++++++++ src/constants.php | 20 ++++++++++++++ src/functions.php | 3 --- 6 files changed, 111 insertions(+), 47 deletions(-) create mode 100644 config/autoloader.php create mode 100644 config/bootstrap.php create mode 100644 src/constants.php diff --git a/autoload.php b/autoload.php index ba10a06..7d4dbc0 100644 --- a/autoload.php +++ b/autoload.php @@ -1,52 +1,28 @@ Date: Mon, 6 Jul 2015 03:13:54 -0430 Subject: [PATCH 54/59] (m): Improved LICENSE text margin. --- LICENSE | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/LICENSE b/LICENSE index f9f3153..72ef792 100644 --- a/LICENSE +++ b/LICENSE @@ -1,22 +1,20 @@ The MIT License (MIT) -Copyright (c) 2014, 2015 Nelson Martell +Copyright (c) 2014-2015 Nelson Martell -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 49a03be7c64c7ef884bd93acd731c80743f6ca53 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Mon, 6 Jul 2015 04:53:26 -0430 Subject: [PATCH 55/59] Unify constants definition. :fire: Moved `NML_VERSION` constant definition from `src/nml.php` to `src/constants.php` and deleted sub-constants and unnecessary file. :new: Added `VERSION` file to dump `NML_VERSION` value. :memo: Documented constants. --- VERSION | 1 + autoload.php | 1 - composer.json | 1 - src/constants.php | 30 +++++++++++++++++++++++++++++- src/nml.php | 24 ------------------------ 5 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 VERSION delete mode 100644 src/nml.php diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..ef52a64 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.4.6 diff --git a/autoload.php b/autoload.php index 7d4dbc0..fc1cb3a 100644 --- a/autoload.php +++ b/autoload.php @@ -20,7 +20,6 @@ require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'constants.php'; require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'functions.php'; -require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'nml.php'; require_once __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'bootstrap.php'; require_once __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'autoloader.php'; diff --git a/composer.json b/composer.json index 6dfb970..28e5e45 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,6 @@ "files": [ "src/constants.php", "src/functions.php", - "src/nml.php", "config/bootstrap.php", ] }, diff --git a/src/constants.php b/src/constants.php index 1e5e2fb..32ffe6f 100644 --- a/src/constants.php +++ b/src/constants.php @@ -3,7 +3,7 @@ * PHP: Nelson Martell Library file * * Content: - * - Global constant definition: NML_GETTEXT_DOMAIN + * - Global constants definitions. * * Copyright © 2015 Nelson Martell (http://nelson6e65.github.io) * @@ -17,4 +17,32 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ +/** + * Gettext domain for NML messages. + * Only for internal usage. + * + * @constant string + * @since v0.4.5 + */ define('NML_GETTEXT_DOMAIN', 'nml'); + + +/** + * Corrent 'stable' version of `PHP: Nelson Martell Library`. + * Can be parsed into a `NelsonMartell\Version` object. ;) + * + * @constant string + * @since v0.4.4 + */ +define('NML_VERSION', '0.4.6'); + + +// ############################################################################# +// If `CODE_ANALYSIS` constant is defined, some NML functions/methods will throw +// notices, warnings and recommendations about its usage. This is useful in +// order to debugging your code. +// Is unactive by default. IT MUST be defined in your bootstrap app code. +// +// define('CODE_ANALYSIS', true); +// +// ############################################################################# diff --git a/src/nml.php b/src/nml.php deleted file mode 100644 index 4729b4a..0000000 --- a/src/nml.php +++ /dev/null @@ -1,24 +0,0 @@ - Date: Mon, 6 Jul 2015 06:14:02 -0430 Subject: [PATCH 56/59] fix (m): Files comment tags alignment. --- autoload.php | 8 ++++---- config/bootstrap.php | 8 ++++---- src/Collections/Collection.php | 8 ++++---- src/Collections/CollectionIterator.inc | 8 ++++---- src/Collections/ICollection.php | 8 ++++---- src/Collections/IList.php | 8 ++++---- src/Extensions/String.php | 10 +++++----- src/IComparable.php | 8 ++++---- src/IEquatable.php | 8 ++++---- src/IntString.php | 8 ++++---- src/Object.php | 8 ++++---- src/Type.php | 8 ++++---- src/Utilities/UnitTesting/Assert.php | 8 ++++---- src/Version.php | 8 ++++---- src/VersionComponent.php | 8 ++++---- src/constants.php | 8 ++++---- src/functions.php | 8 ++++---- 17 files changed, 69 insertions(+), 69 deletions(-) diff --git a/autoload.php b/autoload.php index fc1cb3a..16a6664 100644 --- a/autoload.php +++ b/autoload.php @@ -12,10 +12,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.3.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.3.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ require_once __DIR__.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'constants.php'; diff --git a/config/bootstrap.php b/config/bootstrap.php index 4c5e52d..be13d32 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.5.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.5.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ // Set the path of translations diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 2a2a1d5..13cacd5 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -12,10 +12,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.4.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.4.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Collections { diff --git a/src/Collections/CollectionIterator.inc b/src/Collections/CollectionIterator.inc index b1e613c..1195ad0 100644 --- a/src/Collections/CollectionIterator.inc +++ b/src/Collections/CollectionIterator.inc @@ -12,10 +12,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.4.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.4.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Collections; diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 1e25e5c..43d06bb 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Collections { diff --git a/src/Collections/IList.php b/src/Collections/IList.php index bd6a8d8..4172719 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Collections { diff --git a/src/Extensions/String.php b/src/Extensions/String.php index c942ea5..f324956 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.4.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.4.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Extensions; @@ -22,7 +22,7 @@ * Provides extension methods to handle strings. * * - * @copyright This class is based on Cake\Utility\String of CakePHP(tm) class. + * @copyright This class is based on Cake\Utility\String of CakePHP(tm) class. * @see Original DOC of String based on: http://book.cakephp.org/3.0/en/core-libraries/string.html * */ class String extends \Cake\Utility\Text diff --git a/src/IComparable.php b/src/IComparable.php index 5312846..d08c57b 100644 --- a/src/IComparable.php +++ b/src/IComparable.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.3.2 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.3.2 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/IEquatable.php b/src/IEquatable.php index 3f3f35d..cccce22 100644 --- a/src/IEquatable.php +++ b/src/IEquatable.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2014, 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/IntString.php b/src/IntString.php index 7201e56..839dcd2 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/Object.php b/src/Object.php index 6e42435..8c16a1c 100644 --- a/src/Object.php +++ b/src/Object.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2014, 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/Type.php b/src/Type.php index 3ca486e..97e5ea3 100644 --- a/src/Type.php +++ b/src/Type.php @@ -12,10 +12,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2013-2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2013-2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index e8743ae..c842b9c 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell\Utilities\UnitTesting { diff --git a/src/Version.php b/src/Version.php index 281a614..e532ff9 100644 --- a/src/Version.php +++ b/src/Version.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/VersionComponent.php b/src/VersionComponent.php index accf790..7f5b152 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.1.1 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.1.1 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ namespace NelsonMartell { diff --git a/src/constants.php b/src/constants.php index 32ffe6f..1ad4d4a 100644 --- a/src/constants.php +++ b/src/constants.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.5.0 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.5.0 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ /** diff --git a/src/functions.php b/src/functions.php index 2dac7c9..36d27ef 100644 --- a/src/functions.php +++ b/src/functions.php @@ -11,10 +11,10 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell - * @link http://nelson6e65.github.io/php_nml/ - * @since v0.4.5 - * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) + * @copyright Copyright © 2015 Nelson Martell + * @link http://nelson6e65.github.io/php_nml/ + * @since v0.4.5 + * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) * */ use NelsonMartell\Extensions\String; From d5f7055e0edfdb383225f6989c395787948575c9 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Mon, 6 Jul 2015 06:23:38 -0430 Subject: [PATCH 57/59] fix (m): Copyright format in files comments. --- autoload.php | 2 +- config/bootstrap.php | 2 +- src/Collections/Collection.php | 2 +- src/Collections/CollectionIterator.inc | 2 +- src/Collections/ICollection.php | 2 +- src/Collections/IList.php | 2 +- src/Extensions/String.php | 2 +- src/IComparable.php | 2 +- src/IEquatable.php | 4 ++-- src/IntString.php | 2 +- src/Object.php | 4 ++-- src/PropertiesHandler.inc | 2 +- src/Type.php | 2 +- src/Utilities/Asset.php | 4 ++-- src/Utilities/UnitTesting/Assert.php | 2 +- src/Version.php | 2 +- src/VersionComponent.php | 2 +- src/constants.php | 2 +- src/functions.php | 2 +- 19 files changed, 22 insertions(+), 22 deletions(-) diff --git a/autoload.php b/autoload.php index 16a6664..57fed51 100644 --- a/autoload.php +++ b/autoload.php @@ -12,7 +12,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.3.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/config/bootstrap.php b/config/bootstrap.php index be13d32..1b1adef 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.5.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 13cacd5..d41a817 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -12,7 +12,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.4.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Collections/CollectionIterator.inc b/src/Collections/CollectionIterator.inc index 1195ad0..920db8c 100644 --- a/src/Collections/CollectionIterator.inc +++ b/src/Collections/CollectionIterator.inc @@ -12,7 +12,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.4.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 43d06bb..76af988 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Collections/IList.php b/src/Collections/IList.php index 4172719..74ee8ce 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Extensions/String.php b/src/Extensions/String.php index f324956..06134f4 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.4.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/IComparable.php b/src/IComparable.php index d08c57b..b89fc53 100644 --- a/src/IComparable.php +++ b/src/IComparable.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.3.2 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/IEquatable.php b/src/IEquatable.php index cccce22..4338eba 100644 --- a/src/IEquatable.php +++ b/src/IEquatable.php @@ -5,13 +5,13 @@ * Content: * - Interface definition: [NelsonMartell] IEquatable * - * Copyright © 2014, 2015 Nelson Martell (http://nelson6e65.github.io) + * Copyright © 2014-2015 Nelson Martell (http://nelson6e65.github.io) * * Licensed under The MIT License (MIT) * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell + * @copyright 2014-2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/IntString.php b/src/IntString.php index 839dcd2..e4cee68 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Object.php b/src/Object.php index 8c16a1c..451ed2f 100644 --- a/src/Object.php +++ b/src/Object.php @@ -5,13 +5,13 @@ * Content: * - Class definition: [NelsonMartell] Object * - * Copyright © 2014, 2015 Nelson Martell (http://nelson6e65.github.io) + * Copyright © 2014-2015 Nelson Martell (http://nelson6e65.github.io) * * Licensed under The MIT License (MIT) * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell + * @copyright 2014-2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/PropertiesHandler.inc b/src/PropertiesHandler.inc index 1d9c065..009b613 100644 --- a/src/PropertiesHandler.inc +++ b/src/PropertiesHandler.inc @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.5.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Type.php b/src/Type.php index 97e5ea3..c6ef0d5 100644 --- a/src/Type.php +++ b/src/Type.php @@ -12,7 +12,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2013-2015 Nelson Martell + * @copyright 2013-2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index e81c558..ccffd9c 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -5,13 +5,13 @@ * Content: * - Class definition: [NelsonMartell\Utilities] Asset * - * Copyright © 2014, 2015 Nelson Martell (http://nelson6e65.github.io) + * Copyright © 2014-2015 Nelson Martell (http://nelson6e65.github.io) * * Licensed under The MIT License (MIT) * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2014, 2015 Nelson Martell + * @copyright 2014-2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Utilities/UnitTesting/Assert.php b/src/Utilities/UnitTesting/Assert.php index c842b9c..4e71673 100644 --- a/src/Utilities/UnitTesting/Assert.php +++ b/src/Utilities/UnitTesting/Assert.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/Version.php b/src/Version.php index e532ff9..b105268 100644 --- a/src/Version.php +++ b/src/Version.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/VersionComponent.php b/src/VersionComponent.php index 7f5b152..f126447 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.1.1 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/constants.php b/src/constants.php index 1ad4d4a..c9eff01 100644 --- a/src/constants.php +++ b/src/constants.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.5.0 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) diff --git a/src/functions.php b/src/functions.php index 36d27ef..70d5146 100644 --- a/src/functions.php +++ b/src/functions.php @@ -11,7 +11,7 @@ * For full copyright and license information, please see the LICENSE * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright © 2015 Nelson Martell + * @copyright 2015 Nelson Martell * @link http://nelson6e65.github.io/php_nml/ * @since v0.4.5 * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) From 4fe56800ac342421eb1d0b0aa1a8f9a255494b77 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Tue, 7 Jul 2015 01:04:56 -0430 Subject: [PATCH 58/59] fix (m): tags alignment in DocBlocks. Added some missing docs. Plus other minor fixes. --- config/autoloader.php | 23 +++--- src/Collections/Collection.php | 107 +++++++++++++----------- src/Collections/CollectionIterator.inc | 4 +- src/Collections/ICollection.php | 44 +++++----- src/Collections/IList.php | 31 ++++--- src/Extensions/String.php | 67 ++++++++------- src/IComparable.php | 30 ++++--- src/IEquatable.php | 8 +- src/IntString.php | 26 +++--- src/Object.php | 31 +++---- src/Type.php | 65 +++++++-------- src/Utilities/Asset.php | 57 ++++++++----- src/Version.php | 108 +++++++++++++++---------- src/VersionComponent.php | 15 ++-- src/constants.php | 4 +- src/functions.php | 37 +++++---- 16 files changed, 371 insertions(+), 286 deletions(-) diff --git a/config/autoloader.php b/config/autoloader.php index 19027c3..56fa3e8 100644 --- a/config/autoloader.php +++ b/config/autoloader.php @@ -1,21 +1,21 @@ + * @author Nelson Martell * */ class Collection extends Object implements ICollection { - use CollectionIterator; //Implementación de la interfaz Iterator + // Implementación de la interfaz Iterator. + use CollectionIterator; public function __construct() { @@ -54,10 +55,11 @@ final public function __invoke($index, $value = null) /** * Inserta un nuevo elemento a la colección, en el índice especificado. * - * @param integer $index Índice del elemento a insertar. - * @param mixed $newItem Nuevo elemento a insertar a la colección. - * @access protected - * @return void + * @param integer $index Índice del elemento a insertar. + * @param mixed $newItem Nuevo elemento a insertar a la colección. + * + * @return void + * @access protected * */ protected function insertItem($index, $newItem) { @@ -76,7 +78,7 @@ protected function insertItem($index, $newItem) /** * Quita todos los elementos de la colección. * - * @return void + * @return void * */ protected function clearItems() { @@ -87,9 +89,10 @@ protected function clearItems() /** * Establece un elemento en el índice especificado. * - * @param integer $index Índice del elemento a establecer. - * @param mixed $newItem Nuevo valor con el que se va a reemplazar. - * @return void + * @param integer $index Índice del elemento a establecer. + * @param mixed $newItem Nuevo valor con el que se va a reemplazar. + * + * @return void * */ protected function setItem($index, $newItem) { @@ -102,13 +105,15 @@ protected function setItem($index, $newItem) /** * Obtiene el elemento almacenado en el índice especificado. - * Este método no lanza excepción en caso de indicar un índice fuera del rango; en cambio, - * devuelve NULL. - * El elemento obtenido es de sólo lectura. Para modificar el elemento dentro de la colección, - * tendría que utilizarse el método Collection::SetItem una vez modificado. + * Este método no lanza excepción en caso de indicar un índice fuera del + * rango; en cambio, devuelve NULL. + * El elemento obtenido es de sólo lectura. Para modificar el elemento + * dentro de la colección, tendría que utilizarse el método + * Collection::setItem una vez modificado. + * + * @param integer $index Índice del elemento a obtener. * - * @param integer $index Índice del elemento a obtener. - * @return mixed + * @return mixed * */ protected function getItem($index) { @@ -120,7 +125,11 @@ protected function getItem($index) } /** - * @param integer $index + * Remove the item in specified index. + * + * @param integer $index Index. + * + * @return void */ protected function removeItem($index) { @@ -140,10 +149,13 @@ protected function removeItem($index) /** * Gets the string representation of this object collection. * - * You can format the output, by setting $format param to one of this options: - * - `R` or `r`: All items, separated by comma and space (`, `). This is the default format. + * You can format the output, by setting $format param to one of this + * options: + * - `R` or `r`: All items, separated by comma and space (`, `). + * This is the default format. * - `L` or `l`: Same as `r` option, but enclosed in braces (`{`, `}`). - * - `g`: A full string, containing class name, items count and items list (this list, like `L` option). + * - `g`: A full string, containing class name, items count and items + * list (this list, like `L` option). * - `G`: Same as `g`, but using a full class name (including namespace). * * You can also use a custom format instead, using this placeholders: @@ -156,10 +168,10 @@ protected function removeItem($index) * `Collection::ToString('My collection ({count} items): { {items} }');` * Result: 'My collection (10 items): { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }' * + * @param string $format String format (optional). By default, `r`. * - * @param string $format String format (optional). By default, `r`. - * @return string - * @see String::Format() + * @return string + * @see String::format * */ public function toString($format = 'r') { @@ -205,21 +217,20 @@ public function toString($format = 'r') } - #region {Implementación de la interfaz ICollection} /** * Obtiene el número de elementos incluidos en la colección. - * Ésta propiedad es de sólo lectura. + * Esta propiedad es de sólo lectura. * - * @var integer + * @var integer * */ public $Count; private $count = 0; /** - * Obtiene el número de elementos incluidos en la colección. + * Getter for Count property. * - * @return integer + * @return integer * */ public function getCount() { @@ -228,11 +239,12 @@ public function getCount() /** * Agrega un nuevo elemento al final de la colección. - * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien - * el método protegido 'InsertItem'. + * Nota para herederos: Para cambiar el comportamiento de este método, + * reemplazar más bien el método protegido 'InsertItem'. + * + * @param mixed $item Elemento que se va a agregar a la colección. * - * @param mixed Elemento que se va a agregar a la colección. - * @return void + * @return void * */ public function add($item) { @@ -241,21 +253,23 @@ public function add($item) /** * Quita todos los elementos de la colección. - * Nota para herederos: Para cambiar el comportamiento de este método, reemplazar más bien - * el método protegido 'ClearItems'. + * Nota para herederos: Para cambiar el comportamiento de este método, + * reemplazar más bien el método protegido `Collection::clearItems`. * - * @return void + * @return void + * @see Collection::clearItems * */ public function clear() { - $this->ClearItems(); + $this->clearItems(); } /** * Determina si la colección contiene al elemento especificado. * - * @param mixed $item Objeto que se va a buscar. - * @return boolean true si $item se encuentra; en caso contrario, false. + * @param mixed $item Objeto que se va a buscar. + * + * @return boolean `true` si $item se encuentra; en caso contrario, `false`. * */ public function contains($item) { @@ -269,11 +283,14 @@ public function contains($item) } /** - * Quita, si existe, la primera aparición de un objeto específico de la colección. + * Quita, si existe, la primera aparición de un objeto específico de la + * colección. * - * @param mixed $item Objeto que se va a quitar. - * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. - * Este método también devuelve false si no se encontró $item. + * @param mixed $item Objeto que se va a quitar. + * + * @return boolean `true` si el elemento se ha quitado correctamente; en + * caso contrario, `false`. Este método también devuelve `false` si no + * se encontró. * */ public function remove($item) { @@ -285,7 +302,5 @@ public function remove($item) return false; } - - #end region } } diff --git a/src/Collections/CollectionIterator.inc b/src/Collections/CollectionIterator.inc index 920db8c..b7bd455 100644 --- a/src/Collections/CollectionIterator.inc +++ b/src/Collections/CollectionIterator.inc @@ -23,7 +23,7 @@ namespace NelsonMartell\Collections; /** * Implementa los métodos de la interfaz Iterator para una colección de objetos. * - * @author Nelson Martell + * @author Nelson Martell * @since v0.4.0 * */ trait CollectionIterator @@ -52,7 +52,7 @@ trait CollectionIterator public function valid() { - $v = (bool) ($this->GetItem($this->iteratorPosition) != null); + $v = (bool) ($this->getItem($this->iteratorPosition) != null); return $v; } diff --git a/src/Collections/ICollection.php b/src/Collections/ICollection.php index 76af988..c60f552 100644 --- a/src/Collections/ICollection.php +++ b/src/Collections/ICollection.php @@ -24,58 +24,62 @@ /** * Define métodos para manipular colecciones de objetos. * - * - * @author Nelson Martell + * @author Nelson Martell * */ interface ICollection extends Iterator { + /** * Obtiene el número de elementos incluidos en la colección. - * Si extiende la clase NelsonMartell.Object, debe definirse la propiedad 'public $Count'. - * + * Si extiende la clase NelsonMartell.Object, puede accederse desde la + * propiedad `Count`. * - * @see NelsonMartell\Object - * @return integer + * @return integer + * @see NelsonMartell\Object * */ public function getCount(); + /** * Agrega un elemento a la colección. * + * @param mixed $item Objeto que se va a agregar. * - * @param mixed $item Objeto que se va a agregar. - * @return void + * @return void * */ public function add($item); + /** * Quita todos los elementos de la colección. + * La propiedad Count se debe establecer en 0 y deben liberarse las + * referencias a otros objetos desde los elementos de la colección. * - * - * La propiedad Count se debe establecer en 0 y deben liberarse las referencias a otros - * objetos desde los elementos de la colección. - * - * @return void + * @return void * */ public function clear(); + /** - * Determina si la colección contiene un valor específico. + * Determina si la colección contiene al elemento especificado. * + * @param mixed $item Objeto que se va a buscar. * - * @param mixed $item Objeto que se va a buscar. - * @return boolean true si $item se encuentra; en caso contrario, false. + * @return boolean `true` si $item se encuentra; en caso contrario, `false`. * */ public function contains($item); + /** - * Quita la primera aparición de un objeto específico de la colección. + * Quita, si existe, la primera aparición de un objeto específico de la + * colección. * + * @param mixed $item Objeto que se va a quitar. * - * @param $item Objeto que se va a quitar. - * @return boolean True si $item se ha quitado correctamente; en caso contrario, False. - * Este método también devuelve false si no se encontró $item. + * @return boolean `true` si el elemento se ha quitado correctamente; en + * caso contrario, `false`. Este método también devuelve `false` si no + * se encontró. * */ public function remove($item); } diff --git a/src/Collections/IList.php b/src/Collections/IList.php index 74ee8ce..1e06f73 100644 --- a/src/Collections/IList.php +++ b/src/Collections/IList.php @@ -20,40 +20,49 @@ namespace NelsonMartell\Collections { /** - * Representa una colección de objetos a los que se puede tener acceso por un índice. + * Representa una colección de objetos a los que se puede tener acceso por + * un índice. * - * - * @author Nelson Martell + * @author Nelson Martell * */ interface IList extends ICollection { + /** * Determina el índice de un elemento específico de la lista. - * Si un objeto aparece varias veces en la lista, el método IndexOf siempre devolverá la - * primera instancia encontrada. + * Si un objeto aparece varias veces en la lista, el método indexOf + * siempre devolverá la primera instancia encontrada. * + * @param mixed $item Objeto que se va a buscar. * - * @param mixed $item Objeto que se va a buscar. - * @return integer Índice de $item si se encuentra en la lista; en caso contrario, -1. + * @return integer Índice de $item si se encuentra en la lista; en caso + * contrario, -1. * */ public function indexOf($item); + /** * Inserta un elemento en la lista, en el índice especificado. * + * @param integer $index Índice de base cero en el que debe insertarse + * $item. + * @param mixed $item Objeto que se va a insertar. * - * @param integer $index Índice de base cero en el que debe insertarse $item. - * @param mixed $item Objeto que se va a insertar. - * + * @return void * */ public function insert($index, $item); + /** * Quita el elemento del índice especificado. * + * @param integer $index Índice de base cero del elemento que se va a + * quitar. * - * @param integer $index Índice de base cero del elemento que se va a quitar. + * @return boolean `true` si el elemento se ha quitado correctamente; en + * caso contrario, `false`. Este método también devuelve `false` si no + * se encontró. * */ public function removeAt($index); } diff --git a/src/Extensions/String.php b/src/Extensions/String.php index 06134f4..28b76cc 100644 --- a/src/Extensions/String.php +++ b/src/Extensions/String.php @@ -20,44 +20,49 @@ /** * Provides extension methods to handle strings. + * This class is based on \Cake\Utility\Text of CakePHP(tm) class. * - * - * @copyright This class is based on Cake\Utility\String of CakePHP(tm) class. - * @see Original DOC of String based on: http://book.cakephp.org/3.0/en/core-libraries/string.html + * @see \Cake\Utility\Text::insert + * @see http://book.cakephp.org/3.0/en/core-libraries/text.html * */ class String extends \Cake\Utility\Text { /** - * Replaces format elements in a string with the string representation of an object matching the - * list of arguments specified. You can give as many params as you need, or an array with values. + * Replaces format elements in a string with the string representation of an + * object matching the list of arguments specified. You can give as many + * params as you need, or an array with values. * * ##Usage - * Using numbers as placeholders (encloses between `{` and `}`), you can get the matching string - * representation of each object given. Use `{0}` for the fist object, `{1}` for the second, - * and so on. - * Example: `String::Format('{0} is {1} years old, and have {2} cats.', 'Bob', 65, 101);` + * Using numbers as placeholders (encloses between `{` and `}`), you can get + * the matching string representation of each object given. Use `{0}` for + * the fist object, `{1}` for the second, and so on. + * Example: + * `String::format('{0} is {1} years old, and have {2} cats.', 'Bob', 65, 101);` * Returns: 'Bob is 65 years old, and have 101 cats.' * * You can also use an array to give objects values. * Example: `String::Format('{0} is {1} years old.', ['Bob', 65, 101]);` * Returns: 'Bob is 65 years old, and have 101 cats.' * - * If give an key => value array, each key stands for a placeholder variable name to be replaced - * with value key. In this case, order of keys do not matter. + * If give an key => value array, each key stands for a placeholder variable + * name to be replaced with value key. In this case, order of keys do not + * matter. * Example: * `$arg0 = ['name' => 'Bob', 'n' => 101, 'age' => 65];` * `$format = '{name} is {age} years old, and have {n} cats.';` * `String::Format($format, $arg0);` * Returns: 'Bob is 65 years old, and have 101 cats.' * + * @param string $format A string containing variable placeholders. + * @param array|mixed $args Object(s) to be replaced into $format + * placeholders. * - * @param string $format A string containing variable placeholders. - * @param array|mixed $args Object(s) to be replaced into $format placeholders. - * @return string - * @todo Implement php.net/functions.arguments.html#functions.variable-arg-list.new for PHP 5.6+ - * @todo Implement formatting, like IFormatProvider or something like that. - * @author Nelson Martell + * @return string + * @todo Implement, for php 5.6+: + * php.net/functions.arguments.html#functions.variable-arg-list.new + * @todo Implement formatting, like IFormatProvider or something like that. + * @author Nelson Martell */ public static function format($format, $args) { @@ -74,9 +79,10 @@ public static function format($format, $args) /** * Ensures that object given is not null. If is `null`, throws and exception. * - * @param mixed $obj Object to validate + * @param mixed $obj Object to validate + * + * @return mixed Same object * @throws InvalidArgumentException if object is `null`. - * @return mixed Same object */ public static function ensureIsNotNull($obj) { @@ -91,8 +97,9 @@ public static function ensureIsNotNull($obj) /** * Ensures that object given is an string. Else, thows an exception * - * @param mixed $obj Object to validate. - * @return string Same object given, but ensured that is an string. + * @param mixed $obj Object to validate. + * + * @return string Same object given, but ensured that is an string. * @throws InvalidArgumentException if object is not an `string`. */ public static function ensureIsString($obj) @@ -108,8 +115,9 @@ public static function ensureIsString($obj) /** * Ensures that given string is not empty. * - * @param string $string String to validate. - * @return string Same string given, but ensured that is not empty. + * @param string $string String to validate. + * + * @return string Same string given, but ensured that is not empty. * @throws InvalidArgumentException if string is null or empty. */ public static function ensureIsNotEmpty($string) @@ -125,8 +133,10 @@ public static function ensureIsNotEmpty($string) /** * Ensures that given string is not empty or whitespaces. * - * @param string $string String to validate. - * @return string Same string given, but ensured that is not whitespaces. + * @param string $string String to validate. + * + * @return string Same string given, but ensured that is not whitespaces. + * @throws InvalidArgumentException if object is not an `string`. * @see trim */ public static function ensureIsNotWhiteSpaces($string) @@ -142,8 +152,11 @@ public static function ensureIsNotWhiteSpaces($string) /** * Ensures that an string follows the PHP variables naming convention. * - * @param string $string [description] - * @return [type] [description] + * @param string $string String to be ensured. + * + * @return string + * @throws InvalidArgumentException if object is not an `string` or do not + * follows the PHP variables naming convention. */ public static function ensureIsValidVarName($string) { diff --git a/src/IComparable.php b/src/IComparable.php index b89fc53..8b92108 100644 --- a/src/IComparable.php +++ b/src/IComparable.php @@ -20,30 +20,40 @@ namespace NelsonMartell { /** - * Provee un método para compara igualdad entre objetos del mismo tipo. + * Provee métodos para comparar posición relativa entre objetos del mismo + * tipo, o compatibles. * - * @author Nelson Martell + * @author Nelson Martell * */ interface IComparable { /** - * Determina la posición relativa del objeto especificado con respecto a esta instancia. + * Determina la posición relativa del objeto especificado con respecto a + * esta instancia. * + * @param mixed $other Objeto con el cuál comparar posición relativa. * - * @param mixed $other - * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. + * @return integer Si es igual, `0` (cero); si es mayor, un número + * positivo mayor a `0` (cero); y si es menor, un número negativo. + * @see compare * */ public function compareTo($other); /** - * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. - * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. + * Determina la posición relativa del objeto de la derecha con respecto + * al de la izquierda. + * Puede usarse como segundo argumento en la función de ordenamiento de + * arrays 'usort'. * + * @param mixed $left Objeto de la izquierda + * @param mixed $right Objeto de la derecha * - * @param mixed $left Objeto de la izquierda - * @param mixed $right Objeto de la derecha - * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. + * @return integer Si son iguales, `0` (cero); si el derecho es el mayor + * al izquierdo, un número positivo mayor a `0` (cero); y, en caso + * contrario, si el izquierdo es el mayor, un número negativo. + * @see usort + * @see IComparable::compareTo * */ public static function compare($left, $right); } diff --git a/src/IEquatable.php b/src/IEquatable.php index 4338eba..98c8826 100644 --- a/src/IEquatable.php +++ b/src/IEquatable.php @@ -20,9 +20,10 @@ namespace NelsonMartell { /** - * Provee un método para compara igualdad entre objetos del mismo tipo. + * Provee un método para comparar igualdad entre objetos del mismo tipo, o + * compatibles. * - * @author Nelson Martell + * @author Nelson Martell * */ interface IEquatable { @@ -30,8 +31,9 @@ interface IEquatable /** * Indica si el objeto especificado es igual a la instancia actual. * + * @param mixed $other Another object to compare equality. * - * @return boolean + * @return boolean * */ public function equals($other); } diff --git a/src/IntString.php b/src/IntString.php index e4cee68..404d813 100644 --- a/src/IntString.php +++ b/src/IntString.php @@ -20,11 +20,11 @@ namespace NelsonMartell { /** - * Representa un elemento mixto, compuesto por un entero y una cadena unidos (en ese orden). - * El método ToString obtiene esa cadena compuesta. + * Representa un elemento mixto, compuesto por un entero y una cadena unidos + * (en ese orden). + * El método IntString::toString obtiene esa cadena compuesta. * - * - * @author Nelson Martell + * @author Nelson Martell * */ class IntString extends Object implements IEquatable, IComparable { @@ -98,21 +98,21 @@ public function equals($other) } - #region IComparable - /** - * Determina la posición relativa de esta instancia con respecto al objeto especificado. - * Nota: Cualquier objeto que no sea instancia de IntString se considerará menor. + * Determina la posición relativa de esta instancia con respecto al + * objeto especificado. + * Nota: Cualquier objeto que no sea instancia de IntString se + * considerará menor. * + * @param IntString|mixed $other Objeto con el que se va a comparar. * - * @param IntString|mixed $other Objeto con el que se va a comparar. - * @return integer Cero (0), si esta instancia es igual a $other; mayor a cero (>0), - * si es mayor a $other; menor a cero (<0), si es menor. + * @return integer Cero (0), si esta instancia es igual a $other; mayor + * a cero (>0), si es mayor a $other; menor a cero (<0), si es menor. * */ public function compareTo($other) { - $r = $this->Equals($other) ? 0 : 9999; + $r = $this->equals($other) ? 0 : 9999; if ($r != 0) { if ($other instanceof IntString) { @@ -128,7 +128,5 @@ public function compareTo($other) return $r; } - - #endregion } } diff --git a/src/Object.php b/src/Object.php index 451ed2f..6fc3b34 100644 --- a/src/Object.php +++ b/src/Object.php @@ -49,7 +49,7 @@ * unset($this->Nombre); * * - * @author Nelson Martell + * @author Nelson Martell * */ class Object { @@ -61,11 +61,11 @@ public function __construct() /** * Convierte esta instancia en su representación de cadena. - * Para modificar el funcionamiento de esta función, debe reemplazarse la función - * ObjectClass::ToString() + * Para modificar el funcionamiento de esta función, debe reemplazarse + * la función ObjectClass::toString() * - * - * @return string + * @return string + * @see Object::toString * */ final public function __toString() { @@ -77,8 +77,7 @@ final public function __toString() /** * Convierte la instancia actual en su representación de cadena. * - * - * @return string + * @return string * */ public function toString() { @@ -109,8 +108,7 @@ public function toString() /** * Obtiene el tipo del objeto actual. * - * - * @return Type + * @return Type * */ final public function getType() { @@ -148,13 +146,16 @@ public function equals($other) } /** - * Determina la posición relativa del objeto de la derecha con respecto al de la izquierda. - * Puede usarse como segundo argumento en la función de ordenamiento de arrays 'usort'. + * Determina la posición relativa del objeto de la derecha con respecto + * al de la izquierda. + * Puede usarse como segundo argumento en la función de ordenamiento de + * arrays 'usort'. * + * @param mixed $left Objeto de la izquierda + * @param mixed $right Objeto de la derecha * - * @param mixed $left Objeto de la izquierda - * @param mixed $right Objeto de la derecha - * @return integer 0, si ambos son iguales; >0, si $right es mayor a $left; <0, si $left es mayor a $right. + * @return integer `0`, si ambos son iguales; `>0`, si $right es mayor a + * $left; `<0`, si $left es mayor a $right. * */ public static function compare($left, $right) { @@ -166,7 +167,7 @@ public static function compare($left, $right) if ($right instanceof IComparable) { $r = $right->CompareTo($left); } else { - //Si no son miembros de IComparable, se usa por defecto: + // Si no son miembros de IComparable, se usa por defecto: if ($left == $right) { $r = 0; } else { diff --git a/src/Type.php b/src/Type.php index c6ef0d5..f6290e1 100644 --- a/src/Type.php +++ b/src/Type.php @@ -25,10 +25,10 @@ use \ReflectionMethod; /** - * Represents a PHP object type, and provides some properties and methods to describe some info - * about itself. + * Represents a PHP object type, and provides some properties and methods to + * describe some info about itself. * - * @author Nelson Martell + * @author Nelson Martell * */ final class Type extends Object { @@ -36,7 +36,7 @@ final class Type extends Object /** * Gets the type of specified $obj and collect some info about itself. * - * @param mixed $obj Target object. + * @param mixed $obj Target object. * */ public function __construct($obj) { @@ -85,7 +85,7 @@ public function __construct($obj) * Gets the name of this Type. * This property is read-only. * - * @var string + * @var string * */ public $Name; private $name; @@ -93,7 +93,7 @@ public function __construct($obj) /** * Getter for Type::Name property. * - * @return string + * @return string * */ public function getName() { @@ -104,7 +104,7 @@ public function getName() * Gets the abbreviated name of class, in other words, without the namespace. * This property is read-only. * - * @var string + * @var string * */ public $ShortName; private $shortName = null; @@ -112,8 +112,8 @@ public function getName() /** * Getter for Type::ShortName property. * - * @return string - * @see Type::ShortName + * @return string + * @see Type::ShortName * */ public function getShortName() { @@ -125,7 +125,7 @@ public function getShortName() * If this Type is not a class, this property is set to `NULL`. * This property is read-only. * - * @var string|NULL + * @var string|NULL * */ public $Namespace; private $namespace; @@ -133,8 +133,8 @@ public function getShortName() /** * Getter for Type::Namespace property. * - * @return string|NULL - * @see Type::Namespace + * @return string|NULL + * @see Type::Namespace * */ public function getNamespace() { @@ -145,8 +145,7 @@ public function getNamespace() * Gets the public|protected properties (ReflectionProperty) of this Type. * This property is read-only. * - * - * @var array + * @var array * */ public $Vars; private $vars = null; @@ -164,8 +163,7 @@ public function getVars() * Gets the public|protected methods (ReflectionMethod) of this Type. * This property is read-only. * - * - * @var array + * @var array * */ public $Methods; private $methods = null; @@ -180,10 +178,9 @@ public function getMethods() } /** - * Determina si este Type es NULL. - * + * Determina si este Type es `null`. * - * @return boolean True if this type is null; other case, False. + * @return boolean `true` if this type is `null`; other case, `false`. * */ public function isNull() { @@ -195,10 +192,9 @@ public function isNull() } /** - * Determina si este Type NO es NULL. + * Determina si este Type NO es `null`. * - * - * @return boolean True if this type is NOT null; other case, False. + * @return boolean `true` if this type is NOT `null`; other case, `false`. * */ public function isNotNull() { @@ -209,8 +205,8 @@ public function isNotNull() /** * Determina si este Type es una clase personalizada. * - * - * @return boolean True, if this Type is a custom class; another case, False. + * @return boolean `true`, if this Type is a custom class; another case, + * `false`. * */ public function isCustom() { @@ -231,8 +227,8 @@ public function isCustom() /** * Determinate if this type is scalar. * - * @return boolean - * @see is_scalar() + * @return boolean + * @see is_scalar() * */ public function isScalar() { @@ -256,9 +252,9 @@ public function isScalar() /** * Determina si este Type es de tipo valor. * - * - * @return boolean - * @deprecated Use more precise method: Type::IsScalar, which excludes `array`. + * @return boolean + * @deprecated Use more precise method: Type::isScalar, which excludes + * `array`. * */ public function isValueType() { @@ -277,8 +273,7 @@ public function isValueType() /** * Determina si este Type es de tipo referencia. * - * - * @return boolean + * @return boolean * */ public function isReferenceType() { @@ -288,14 +283,13 @@ public function isReferenceType() /** * Convierte la instancia actual en su representación en cadena. * - * - * @return string + * @return string * */ public function toString() { $s = $this->Name; - if ($this->IsCustom()) { + if ($this->isCustom()) { $s = sprintf("object (%s)", $s); } @@ -306,8 +300,7 @@ public function toString() * Obtiene el tipo del objeto especificado. * Es un alias para el constructor de Type. * - * - * @return Type + * @return Type * @deprecated * */ public static function typeof($obj) diff --git a/src/Utilities/Asset.php b/src/Utilities/Asset.php index ccffd9c..46f4b6f 100644 --- a/src/Utilities/Asset.php +++ b/src/Utilities/Asset.php @@ -24,18 +24,23 @@ use \InvalidArgumentException; /** - * Representa un recurso estático de una página, como elementos js y css, que poseen varias - * versiones y están organizadas en subdirectorios, proponiendo una estructura predeterminada. - * Contiene métodos y propiedades para obtener las rutas de los directorios y recursos de las - * diferentes versiones del framework. + * Representa un recurso estático de una página, como elementos js y css + * organizados de una manera predeterminada en subdirectorios. + * Contiene métodos y propiedades para obtener las rutas de los directorios + * y recursos entre sus diferentes versiones. * * @author Nelson Martell * */ class Asset extends Object { /** - * Crea una nueva instancia de la clase Asset - * */ + * Crea una nueva instancia de la clase Asset. + * + * @param string|null $name Nombre humano del recurso. + * @param array|string|Version|null $versions Versión(es) del recurso. + * @param string|null $cdnUri URL del recurso en un + * servidor CDN. + */ public function __construct($name = null, $versions = null, $cdnUri = null) { parent::__construct(); @@ -134,13 +139,13 @@ public function __construct($name = null, $versions = null, $cdnUri = null) /** - * Obtiene o establece el nombre original del recurso. - * A partir de éste se determinará la ruta y el nombre real del archivo (que, por defecto, - * será éste mismo pero convertido en minúsculas y reemplazando sus espacios en blanco por - * guiones (' ' -> '-')). + * Obtiene o establece el nombre original 'humano' del recurso. + * A partir de éste se determinará la ruta y el nombre real del archivo + * (que, por defecto, será éste mismo pero convertido en minúsculas y + * reemplazando sus espacios en blanco por guiones (' ' -> '-')). * - * @see $ShortName * @var string Nombre del recurso + * @see Asset::ShortName * */ public $Name; private $name; @@ -194,7 +199,9 @@ public function setName($value) } /** - * Obtiene el nombre real del recurso, que representa al nombre real de . + * Obtiene el nombre real del recurso, que representa al nombre 'usable' + * del recurso. + * Esta propiedad es de sólo lectura. * * @var string Nombre del recurso en su forma generada * */ @@ -207,7 +214,8 @@ public function getShortName() } /** - * Obtiene la lista de versiones + * Obtiene la lista de versiones. + * Esta propiedad es de sólo lectura. * * @var List Lista de versiones del recurso * */ @@ -260,11 +268,13 @@ public function getRootDirectory() const OLDEST = 'oldest'; /** - * Obtiene la ruta del directorio de la versión especificada. Si no se especifica, - * se devuelve la versión más reciente. + * Obtiene la ruta del directorio de la versión especificada. Si no se + * especifica, se devuelve la versión más reciente. + * + * @param string|Version $version Versión a obtener. También puede + * tomar los valores 'newest' u 'oldest' para representar a la versión + * más nueva o más vieja, respectivamente. * - * @param string|Version $version Versión a obtener. También puede tomar los valores 'newest' u 'oldest' - * para representar a la versión más nueva o más vieja, respectivamente. * @return string Ruta del directorio de la versión especificada. * */ public function getDirectoryPath($version = self::NEWEST) @@ -322,12 +332,15 @@ public function getDirectoryPath($version = self::NEWEST) /** - * Obtiene la ruta del recurso de la versión especificada. Si no se especifica, se devuelve la - * versión más reciente. + * Obtiene la ruta del recurso de la versión especificada. Si no se + * especifica, se devuelve la versión más reciente. + * + * @param string|Version $version Versión a obtener. También puede + * tomar los valores 'newest' u 'oldest' para representar a la versión + * más nueva o más vieja, respectivamente. + * @param string $append Texto que se le anezará a la cadena + * de salida. * - * @param string|Version $version Versión a obtener. También puede tomar los valores 'newest' u 'oldest' para - * representar a la versión más nueva o más vieja, respectivamente. - * @param string $append Texto que se le anezará a la cadena de salida * @return string Ruta del recurso * */ public function getResourcePath($version = self::NEWEST, $append = '') diff --git a/src/Version.php b/src/Version.php index b105268..edf9d29 100644 --- a/src/Version.php +++ b/src/Version.php @@ -26,23 +26,22 @@ * siendo obligatorios el primer y segundo componente. * No se puede heredar esta clase. * - * - * @author Nelson Martell + * @author Nelson Martell * */ final class Version extends Object implements IEquatable, IComparable { /** - * Crea una nueva instancia con los números principal, secundario, de compilación (opcional) - * y revisión (opcional). - * Para comprobar si la versión es válida, usar el método IsValid. + * Crea una nueva instancia con los números principal, secundario, de + * compilación (opcional) y revisión (opcional). + * Para comprobar si la versión es válida, usar el método isValid. * + * @param int $major Componente principal + * @param int $minor Componente secundario + * @param int|string|VersionComponent|null $build Componente de compilación + * @param int|string|VersionComponent|null $revision Componente de revisión * - * @param int $major Componente principal - * @param int $minor Componente secundario - * @param int|string|VersionComponent|NULL $build Componente de compilación - * @param int|string|VersionComponent|NULL $revision Componente de revisión - * @throw InvalidArgumentException + * @throws InvalidArgumentException * */ public function __construct($major, $minor, $build = null, $revision = null) { @@ -128,9 +127,9 @@ public function __construct($major, $minor, $build = null, $revision = null) /** * Convierte una cadena a su representación del tipo Version. * + * @param Version|string|int|float|array $value Objeto a convertir. * - * @param Version|string|int|float|array Objeto a convertir. - * @return Version Objeto convertido desde $value. + * @return Version Objeto convertido desde $value. * */ public static function parse($value) { @@ -189,15 +188,21 @@ public static function parse($value) } /** - * Obtiene el valor del componente principal del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * + * Obtiene el valor del componente principal del número de versión del + * objeto actual. + * Esta propiedad es de sólo lectura. * - * @var int Componente principal del número de versión + * @var int Componente principal del número de versión. * */ public $Major; private $major; + /** + * Getter for Major property. + * + * @return integer + * @see Version::Major. + */ public function getMajor() { return $this->major; @@ -205,45 +210,63 @@ public function getMajor() /** - * Obtiene el valor del componente secundario del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. + * Obtiene el valor del componente secundario del número de versión del + * objeto actual. + * Esta propiedad es de sólo lectura. * - * - * @var int Componente secundario del número de versión + * @var int Componente secundario del número de versión. * */ public $Minor; private $minor; + /** + * Getter for minor property. + * + * @return integer + * @see Version::Minor. + */ public function getMinor() { return $this->minor; } /** - * Obtiene el valor del componente de compilación del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. + * Obtiene el valor del componente de compilación del número de versión + * del objeto actual. + * Esta propiedad es de sólo lectura. * - * - * @var VersionComponent Componente de compilación del número de versión + * @var VersionComponent Componente de compilación del número de versión. * */ public $Build; private $build; + /** + * Getter for Build property. + * + * @return VersionComponent + * @see Version::Build + */ public function getBuild() { return $this->build; } /** - * Obtiene el valor del componente de revisión del número de versión del objeto actual. - * Ésta propiedad es de sólo lectura. - * + * Obtiene el valor del componente de revisión del número de versión del + * objeto actual. + * Esta propiedad es de sólo lectura. * - * @var VersionComponent Componente de revisión del número de versión + * @var VersionComponent Componente de revisión del número de versión. * */ public $Revision; private $revision; + /** + * Getter for Revision property. + * + * @return VersionComponent + * @see Version::Revision + */ public function getRevision() { return $this->revision; @@ -252,14 +275,15 @@ public function getRevision() /** * Convierte la instancia actual en su representación en cadena. - * Por defecto, si no están definidos los componentes de compilación y revisión, no se - * incluyen en la salida. - * Use el método IsValid si quiere determinar si la versión es válida antes de devolver esta cadena. - * + * Por defecto, si no están definidos los componentes de compilación y + * revisión, no se incluyen en la salida. + * Use el método isValid si quiere determinar si la versión es válida + * antes de devolver esta cadena. * - * @return string Representación de la versión en forma de cadena: 'major.minor[.build[.revision]]' - * @see VersionComponent::IsNull - * @see Version::IsValid + * @return string Representación de la versión en forma de cadena: + * 'major.minor[.build[.revision]]' + * @see VersionComponent::isNull + * @see Version::isValid * */ public function toString() { @@ -291,7 +315,7 @@ public function toString() * 6. Build está definido y tiene la cadena, pero Revision no está definido. * 7. Revision posee cadena, pero Build no. * - * @return boolean Un valor que indica si la instancia actual es válida. + * @return boolean Un valor que indica si la instancia actual es válida. * */ public function isValid() { @@ -334,9 +358,10 @@ public function isValid() /** * Determina si el objeto $other especificado es igual a la instancia actual. * + * @param Version $other El otro objeto a comparar. * - * @param Version $other - * @return bool True si $other es igual esta instancia + * @return bool `true` si $other es igual esta instancia; caso contrario, + * `false`. * */ public function equals($other) { @@ -357,11 +382,12 @@ public function equals($other) #region IComparable /** - * Determina la posición relativa del objeto especificado con respecto a esta instancia. + * Determina la posición relativa del objeto especificado con respecto a + * esta instancia. * + * @param Version $other El otro objeto Version a comparar. * - * @param Version $other - * @return integer 0, si es igual; >0, si es mayor; <0, si es menor. + * @return integer `0`, si es igual; >0, si es mayor; <0, si es menor. * */ public function compareTo($other) { diff --git a/src/VersionComponent.php b/src/VersionComponent.php index f126447..406b812 100644 --- a/src/VersionComponent.php +++ b/src/VersionComponent.php @@ -25,8 +25,7 @@ * Representa un componente de un número de Version. * Extiende la clase IntString, pero restringe los valores que puede tomar. * - * - * @author Nelson Martell + * @author Nelson Martell * */ class VersionComponent extends IntString implements IEquatable { @@ -150,8 +149,7 @@ public static function parse($value = null) /** * Determina si este componente tiene los valores predeterminados (0). * - * - * @return boolean + * @return boolean * */ public function isDefault() { @@ -168,7 +166,7 @@ public function isDefault() /** * Getter method for VersionComponent::IntValue property. * - * @return integer|NULL + * @return integer|NULL * */ public function getIntValue() { @@ -179,8 +177,7 @@ public function getIntValue() /** * Determina si este componente NO tiene los valores predeterminados. * - * - * @return boolean + * @return boolean * */ public function isNotDefault() { @@ -190,7 +187,7 @@ public function isNotDefault() /** * Determina si esta instancia es nula. * - * @return boolean + * @return boolean * */ public function isNull() { @@ -204,7 +201,7 @@ public function isNull() /** * Determina si esta instancia NO es nula. * - * @return boolean + * @return boolean * */ public function isNotNull() { diff --git a/src/constants.php b/src/constants.php index c9eff01..2aaac9b 100644 --- a/src/constants.php +++ b/src/constants.php @@ -22,7 +22,7 @@ * Only for internal usage. * * @constant string - * @since v0.4.5 + * @since v0.4.5 */ define('NML_GETTEXT_DOMAIN', 'nml'); @@ -32,7 +32,7 @@ * Can be parsed into a `NelsonMartell\Version` object. ;) * * @constant string - * @since v0.4.4 + * @since v0.4.4 */ define('NML_VERSION', '0.4.6'); diff --git a/src/functions.php b/src/functions.php index 70d5146..9bd1830 100644 --- a/src/functions.php +++ b/src/functions.php @@ -24,13 +24,13 @@ * Busca un mensaje único traducido en el dominio 'nml'. * El mensaje puede contener cadenas de formato. * + * @param string $message Mensaje con formato que se va a buscar. + * @param array|mixed $args Un objeto, una lista de objetos o múltiples + * argumentos que se van a incluir en las cadenas de formato del mensaje. * - * @param string $message Mensaje con formato que se va a buscar. - * @param array|mixed $args Un objeto, una lista de objetos o múltiples argumentos que se van a - * incluir en las cadenas de formato del mensaje. - * @return string - * @see dgettext - * @see String::format + * @return string + * @see dgettext + * @see String::format * */ function nml_msg($message, $args = null) { @@ -48,14 +48,17 @@ function nml_msg($message, $args = null) * Busca un mensaje único, en singular y plural, traducido en el dominio 'nml'. * El mensaje puede contener cadenas de formato. * - * @param string $singular Mensaje con formato que se va a buscar cuando $n es uno (1). - * @param string $plural Mensaje con formato que se va a buscar cuando $n es distinto a (1). - * @param integer $n Cantidad - * @param array|mixed $args Un objeto, una lista de objetos o múltiples argumentos que se van a - * incluir en las cadenas de formato del mensaje. - * @return string - * @see dngettext - * @see String::format + * @param string $singular Mensaje con formato que se va a buscar cuando $n + * es uno (1). + * @param string $plural Mensaje con formato que se va a buscar cuando $n + * es distinto a (1). + * @param integer $n Cantidad + * @param array|mixed $args Un objeto, una lista de objetos o múltiples + * argumentos que se van a incluir en las cadenas de formato del mensaje. + * + * @return string + * @see dngettext + * @see String::format * */ function nml_nmsg($singular, $plural, $n, $args = null) { @@ -73,10 +76,10 @@ function nml_nmsg($singular, $plural, $n, $args = null) * Obtiene el tipo del objeto especificado. * Es un alias para el constructor de la clase Type. * + * @param mixed $obj Objeto al cual se le extraerá su tipo. * - * @param mixed $obj Objeto al cual se le extraerá su tipo. - * @return Type - * @see Type::__construct + * @return Type + * @see Type::__construct * */ function typeof($obj) { From 591304cf96a0f1b4aea7dc00c02e22e3d01ff824 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Tue, 7 Jul 2015 20:43:57 -0430 Subject: [PATCH 59/59] Update composer.json fix: extra comma. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 28e5e45..c2d0411 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "files": [ "src/constants.php", "src/functions.php", - "config/bootstrap.php", + "config/bootstrap.php" ] }, "autoload-dev": {