Passed
Push — master ( b68a78...d29a76 )
by Jean-Christophe
16:10 queued 03:52
created

ValidationModelParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
c 0
b 0
f 0
dl 0
loc 26
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 10 4
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;
0 ignored issues
show
Bug introduced by
The type Ubiquity\annotations\ValidatorAnnotation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * @author jc
11
 *
12
 */
13
class ValidationModelParser {
14
15
	protected $validators=[];
16
17 38
	public function parse($modelClass) {
18 38
		$instance=new $modelClass();
19 38
		$properties=Reflexion::getProperties($instance);
20 38
		foreach ( $properties as $property ) {
21 38
			$propName=$property->getName();
22 38
			$annots=Reflexion::getAnnotationsMember($modelClass, $propName, 'validator');
23 38
			if(\count($annots)>0){
24 38
				$this->validators[$propName]=[];
25 38
				foreach ($annots as $annotation){
26 38
					$this->validators[$propName][]=$annotation->getPropertiesAndValues();
27
				}
28
			}
29
		}
30
31 38
	}
32
33 38
	public function getValidators(){
34 38
		return $this->validators;
35
	}
36
37
	public function __toString() {
38
		return "return " . UArray::asPhpArray($this->validators, "array") . ";";
39
	}
40
}
41
42