|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Administrador |
|
5
|
|
|
* Date: 08/08/2017 |
|
6
|
|
|
* Time: 11:22 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Greenter\Xml\Validator; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
|
12
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait RetentionValidator |
|
16
|
|
|
* @package Greenter\Xml\Validator |
|
17
|
|
|
*/ |
|
18
|
|
View Code Duplication |
trait RetentionValidator |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
|
21
|
|
|
{ |
|
22
|
|
|
$metadata->addPropertyConstraints('serie', [ |
|
23
|
|
|
new Assert\NotBlank(), |
|
24
|
|
|
new Assert\Length(['max' => 4]), |
|
25
|
|
|
]); |
|
26
|
|
|
$metadata->addPropertyConstraints('correlativo', [ |
|
27
|
|
|
new Assert\NotBlank(), |
|
28
|
|
|
new Assert\Length(['max' => 8]), |
|
29
|
|
|
]); |
|
30
|
|
|
$metadata->addPropertyConstraints('fechaEmision', [ |
|
31
|
|
|
new Assert\NotBlank(), |
|
32
|
|
|
new Assert\Date(), |
|
33
|
|
|
]); |
|
34
|
|
|
$metadata->addPropertyConstraints('proveedor', [ |
|
35
|
|
|
new Assert\NotBlank(), |
|
36
|
|
|
new Assert\Valid(), |
|
37
|
|
|
]); |
|
38
|
|
|
$metadata->addPropertyConstraints('regimen', [ |
|
39
|
|
|
new Assert\NotBlank(), |
|
40
|
|
|
new Assert\Length(['min' => 2, 'max' => 2]), |
|
41
|
|
|
]); |
|
42
|
|
|
$metadata->addPropertyConstraint('tasa', new Assert\NotBlank()); |
|
43
|
|
|
$metadata->addPropertyConstraint('impPercibido', new Assert\NotBlank()); |
|
44
|
|
|
$metadata->addPropertyConstraint('impCobrado', new Assert\NotBlank()); |
|
45
|
|
|
$metadata->addPropertyConstraints('moneda', [ |
|
46
|
|
|
new Assert\NotBlank(), |
|
47
|
|
|
new Assert\Length(['min' => 3, 'max' => 3]), |
|
48
|
|
|
]); |
|
49
|
|
|
$metadata->addPropertyConstraint('observacion', new Assert\Length(['max' => 250])); |
|
50
|
|
|
$metadata->addPropertyConstraints('details', [ |
|
51
|
|
|
new Assert\NotBlank(), |
|
52
|
|
|
new Assert\Valid(), |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.