Skip to content

Commit

Permalink
🔨 new ValidateHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Mar 1, 2020
1 parent ef8ac74 commit 30cd0f6
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 19 deletions.
6 changes: 2 additions & 4 deletions base/classes/helpers/ArrayHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public static function convertArrayFormDin2Pdo($dataArray,$upperCase = false)
}
//--------------------------------------------------------------------------------
/**
* @deprecated chante to ValidateHelper::isArray
* Validade is array and not empty
* @param integer $id
* @param string $method
Expand All @@ -190,10 +191,7 @@ public static function convertArrayFormDin2Pdo($dataArray,$upperCase = false)
*/
public static function validateIsArray($array,$method,$line)
{
FormDinHelper::validateMethodLine($method, $line, __METHOD__);
if( empty($array) || !is_array($array) ){
throw new InvalidArgumentException(TMessage::ERROR_TYPE_NOT_ARRAY.'See the method: '.$method.' in the line: '.$line);
}
ValidateHelper::isArray($array, $method, $line);
}
//--------------------------------------------------------------------------------
/***
Expand Down
27 changes: 12 additions & 15 deletions base/classes/helpers/FormDinHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,20 @@ public static function convertVo2ArrayFormDin($vo)
return $arrayFormDin;
}

/**
* @deprecated chante to ValidateHelper::methodLine
* @param string $method
* @param string $line
* @param string $nameMethodValidate
* @throws InvalidArgumentException
*/
public static function validateMethodLine($method,$line,$nameMethodValidate)
{
if( empty($method) ){
throw new InvalidArgumentException(TMessage::ERROR_EMPTY_INPUT.' variable method is null. '.$nameMethodValidate);
}
if( empty($line) ){
throw new InvalidArgumentException(TMessage::ERROR_EMPTY_INPUT.' variable line is null. '.$nameMethodValidate);
}
ValidateHelper::methodLine($method, $line, $nameMethodValidate);
}
//--------------------------------------------------------------------------------
/**
* @deprecated chante to ValidateHelper::objTypeTPDOConnectionObj
* Validate Object Type is Instance Of TPDOConnectionObj
*
* @param object $tpdo instanceof TPDOConnectionObj
Expand All @@ -132,14 +135,11 @@ public static function validateMethodLine($method,$line,$nameMethodValidate)
*/
public static function validateObjTypeTPDOConnectionObj($tpdo,$method,$line)
{
self::validateMethodLine($method, $line, __METHOD__);
$typeObjWrong = !($tpdo instanceof TPDOConnectionObj);
if( !is_null($tpdo) && $typeObjWrong ){
throw new InvalidArgumentException('Informed class is not an instance of TPDOConnectionObj. See the method: '.$method.' in the line: '.$line);
}
ValidateHelper::objTypeTPDOConnectionObj($tpdo, $method, $line);
}
//--------------------------------------------------------------------------------
/**
* @deprecated chante to ValidateHelper::isNumeric
* Validade ID is numeric and not empty
* @param integer $id
* @param string $method
Expand All @@ -149,10 +149,7 @@ public static function validateObjTypeTPDOConnectionObj($tpdo,$method,$line)
*/
public static function validateIdIsNumeric($id,$method,$line)
{
self::validateMethodLine($method, $line, __METHOD__);
if( empty($id) || !is_numeric($id) ){
throw new InvalidArgumentException(TMessage::ERROR_TYPE_NOT_INT.'See the method: '.$method.' in the line: '.$line);
}
ValidateHelper::isNumeric($id, $method, $line);
}
/***
*
Expand Down
98 changes: 98 additions & 0 deletions base/classes/helpers/ValidateHelper.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/*
* Formdin Framework
* Copyright (C) 2012 Ministério do Planejamento
* Criado por Luís Eugênio Barbosa
* Essa versão é um Fork https://github.com/bjverde/formDin
*
* ----------------------------------------------------------------------------
* This file is part of Formdin Framework.
*
* Formdin Framework is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License version 3
* along with this program; if not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301, USA.
* ----------------------------------------------------------------------------
* Este arquivo é parte do Framework Formdin.
*
* O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
* modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
* do Software Livre (FSF).
*
* Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
* GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
* APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
* para maiores detalhes.
*
* Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
* "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
* ou escreva para a Fundação do Software Livre (FSF) Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
*/
class ValidateHelper
{


public static function methodLine($method,$line,$nameMethodValidate)
{
if( empty($method) ){
throw new InvalidArgumentException(TMessage::ERROR_EMPTY_INPUT.' variable method is null. '.$nameMethodValidate);
}
if( empty($line) ){
throw new InvalidArgumentException(TMessage::ERROR_EMPTY_INPUT.' variable line is null. '.$nameMethodValidate);
}
}

public static function isNumeric($id,$method,$line)
{
self::methodLine($method, $line, __METHOD__);
if( empty($id) || !is_numeric($id) ){
throw new InvalidArgumentException(TMessage::ERROR_TYPE_NOT_INT.'See the method: '.$method.' in the line: '.$line);
}
}

/**
* Validade is array and not empty
* @param array $array
* @param string $method
* @param string $line
* @throws InvalidArgumentException
* @return void
*/
public static function isArray($array,$method,$line)
{
self::methodLine($method, $line, __METHOD__);
if( empty($array) || !is_array($array) ){
throw new InvalidArgumentException(TMessage::ERROR_TYPE_NOT_ARRAY.'See the method: '.$method.' in the line: '.$line);
}
}

//--------------------------------------------------------------------------------
/**
* Validate Object Type is Instance Of TPDOConnectionObj
*
* @param object $tpdo instanceof TPDOConnectionObj
* @param string $method __METHOD__
* @param string $line __LINE__
* @throws InvalidArgumentException
* @return void
*/
public static function objTypeTPDOConnectionObj($tpdo,$method,$line)
{
self::validateMethodLine($method, $line, __METHOD__);
$typeObjWrong = !($tpdo instanceof TPDOConnectionObj);
if( !is_null($tpdo) && $typeObjWrong ){
throw new InvalidArgumentException('Informed class is not an instance of TPDOConnectionObj. See the method: '.$method.' in the line: '.$line);
}
}
}
?>

0 comments on commit 30cd0f6

Please sign in to comment.