forked from deblan/csv-validator
PSR2 compliance
This commit is contained in:
parent
d5b0c29c23
commit
7de3c8a9e8
|
@ -10,7 +10,8 @@ use Symfony\Component\Validator\ConstraintViolation;
|
|||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* Class Validator
|
||||
* Class Validator.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class Validator
|
||||
|
@ -36,7 +37,7 @@ class Validator
|
|||
protected $dataConstraints = [];
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $hasValidate = false;
|
||||
|
||||
|
@ -51,7 +52,7 @@ class Validator
|
|||
protected $expectedLegend = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param RecursiveValidator $validator
|
||||
*/
|
||||
|
@ -65,10 +66,11 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Append a constraint to a specific column
|
||||
* Append a constraint to a specific column.
|
||||
*
|
||||
* @param integer $key The column number
|
||||
* @param int $key The column number
|
||||
* @param Constraint $constraint The constraint
|
||||
*
|
||||
* @return Validator
|
||||
*/
|
||||
public function addFieldConstraint($key, Constraint $constraint)
|
||||
|
@ -83,9 +85,10 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Append a constraint to a specific line
|
||||
* Append a constraint to a specific line.
|
||||
*
|
||||
* @param Constraint $constraint The constraint
|
||||
*
|
||||
* @return Validator
|
||||
*/
|
||||
public function addDataConstraint(Constraint $constraint)
|
||||
|
@ -96,9 +99,10 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the expected legend
|
||||
* Set the expected legend.
|
||||
*
|
||||
* @param array $legend Expected legend
|
||||
*
|
||||
* @return Validator
|
||||
*/
|
||||
public function setExpectedLegend(array $legend)
|
||||
|
@ -109,7 +113,8 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Run the validation
|
||||
* Run the validation.
|
||||
*
|
||||
* @param CsvParser $parser
|
||||
*/
|
||||
public function validate(CsvParser $parser)
|
||||
|
@ -118,8 +123,7 @@ class Validator
|
|||
$this->parser = $parser;
|
||||
$this->parser->parse();
|
||||
$this->errors = [];
|
||||
}
|
||||
elseif ($this->hasValidate) {
|
||||
} elseif ($this->hasValidate) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -127,12 +131,11 @@ class Validator
|
|||
$this->validateDatas();
|
||||
$this->validateFields();
|
||||
|
||||
|
||||
$this->hasValidate = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the legend
|
||||
* Validates the legend.
|
||||
*/
|
||||
protected function validateLegend()
|
||||
{
|
||||
|
@ -150,7 +153,7 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Validates datas
|
||||
* Validates datas.
|
||||
*/
|
||||
protected function validateDatas()
|
||||
{
|
||||
|
@ -168,7 +171,7 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Validates fields
|
||||
* Validates fields.
|
||||
*/
|
||||
protected function validateFields()
|
||||
{
|
||||
|
@ -201,11 +204,11 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Add violations
|
||||
* Add violations.
|
||||
*
|
||||
* @param ConstraintViolationList $violations
|
||||
* @param integer $line The line of the violations
|
||||
* @param integer|null $key The column of the violations
|
||||
* @param int $line The line of the violations
|
||||
* @param int|null $key The column of the violations
|
||||
*/
|
||||
protected function mergeViolationsMessages(ConstraintViolationList $violations, $line, $key = null)
|
||||
{
|
||||
|
@ -219,11 +222,11 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Create and append a violation from a string error
|
||||
* Create and append a violation from a string error.
|
||||
*
|
||||
* @param string $message The error message
|
||||
* @param integer $line The line of the violations
|
||||
* @param integer|null $key The column of the violations
|
||||
* @param int $line The line of the violations
|
||||
* @param int|null $key The column of the violations
|
||||
*/
|
||||
protected function mergeErrorMessage($message, $line, $key = null)
|
||||
{
|
||||
|
@ -232,9 +235,9 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the validation status
|
||||
* Returns the validation status.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @throw RuntimeException No validation yet
|
||||
*/
|
||||
public function isValid()
|
||||
|
@ -247,7 +250,7 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the errors
|
||||
* Returns the errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -257,9 +260,10 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate a ConstraintViolation
|
||||
* Generate a ConstraintViolation.
|
||||
*
|
||||
* @param string $message The error message
|
||||
*
|
||||
* @return ConstraintViolation
|
||||
*/
|
||||
protected function generateConstraintViolation($message)
|
||||
|
@ -268,11 +272,12 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate a Violation
|
||||
* Generate a Violation.
|
||||
*
|
||||
* @param string $message The error message
|
||||
* @param integer $line The line of the violations
|
||||
* @param integer|null $key The column of the violations
|
||||
* @param int $line The line of the violations
|
||||
* @param int|null $key The column of the violations
|
||||
*
|
||||
* @return Violation
|
||||
*/
|
||||
protected function generateViolation($line, $key, ConstraintViolation $violation)
|
||||
|
@ -281,25 +286,27 @@ class Validator
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the true line number of an error
|
||||
* Get the true line number of an error.
|
||||
*
|
||||
* @param integer $line
|
||||
* @return integer
|
||||
* @param int $line
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getTrueLine($line)
|
||||
{
|
||||
if ($this->parser->getHasLegend()) {
|
||||
$line++;
|
||||
++$line;
|
||||
}
|
||||
|
||||
return ++$line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true culumn number of an error
|
||||
* Get the true culumn number of an error.
|
||||
*
|
||||
* @param integer $key
|
||||
* @return integer
|
||||
* @param int $key
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getTrueColunm($key)
|
||||
{
|
||||
|
|
|
@ -5,18 +5,19 @@ namespace Deblan\CsvValidator;
|
|||
use Symfony\Component\Validator\ConstraintViolation;
|
||||
|
||||
/**
|
||||
* Class Violation
|
||||
* Class Violation.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class Violation
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $line;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $column;
|
||||
|
||||
|
@ -26,10 +27,10 @@ class Violation
|
|||
protected $violation;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param integer $line The line of the violation
|
||||
* @param integer $column The column of the violation
|
||||
* @param int $line The line of the violation
|
||||
* @param int $column The column of the violation
|
||||
* @param ConstraintViolation $violation The violation
|
||||
*/
|
||||
public function __construct($line, $column, ConstraintViolation $violation)
|
||||
|
@ -41,6 +42,7 @@ class Violation
|
|||
|
||||
/**
|
||||
* @param int $line
|
||||
*
|
||||
* @return Violation
|
||||
*/
|
||||
public function setLine($line)
|
||||
|
@ -60,6 +62,7 @@ class Violation
|
|||
|
||||
/**
|
||||
* @param int $column
|
||||
*
|
||||
* @return Violation
|
||||
*/
|
||||
public function setColumn($column)
|
||||
|
@ -83,6 +86,7 @@ class Violation
|
|||
|
||||
/**
|
||||
* @param ConstraintViolation $violation
|
||||
*
|
||||
* @return Violation
|
||||
*/
|
||||
public function setViolation(ConstraintViolation $violation)
|
||||
|
|
Loading…
Reference in a new issue