Completed
Push — master ( 94ddbb...e5219e )
by Jean-Christophe
04:25
created

ValidationModelParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 14
dl 0
loc 28
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 11 5
A __toString() 0 2 1
A getValidators() 0 2 1
1
<?php
2
3
namespace Ubiquity\contents\validation;
4
5
use Ubiquity\orm\parser\Reflexion;
6
use Ubiquity\utils\base\UArray;
7
use Ubiquity\annotations\ValidatorAnnotation;
8
9
/**
10
 * @author jc
11
 *
12
 */
13
class ValidationModelParser {
14
	
15
	protected $validators=[];
16
	
17 1
	public function parse($modelClass) {
18 1
		$instance=new $modelClass();
19 1
		$properties=Reflexion::getProperties($instance);
20 1
		foreach ( $properties as $property ) {
21 1
			$propName=$property->getName();
22 1
			$annots=Reflexion::getAnnotationsMember($modelClass, $propName, "@validator");
23 1
			if(sizeof($annots)>0){
24 1
				$this->validators[$propName]=[];
25 1
				foreach ($annots as $annotation){
26 1
					if($annotation instanceof ValidatorAnnotation){
27 1
						$this->validators[$propName][]=$annotation->getPropertiesAndValues();
28
					}
29
				}
30
			}
31
		}
32
33 1
	}
34
	
35 1
	public function getValidators(){
36 1
		return $this->validators;
37
	}
38
	
39 1
	public function __toString() {
40 1
		return "return " . UArray::asPhpArray($this->validators, "array") . ";";
41
	}
42
}
43
44