Passed
Push — master ( ee4606...24a9ec )
by Jean-Christophe
06:42
created

ValidatorsManagerInitTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 50
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initModelsValidators() 0 4 2
A addClassValidators() 0 4 1
A registerType() 0 2 1
A initClassValidators() 0 6 2
1
<?php
2
3
namespace Ubiquity\contents\validation;
4
5
use Ubiquity\cache\CacheManager;
6
use Ubiquity\controllers\Startup;
7
8
/**
9
 *
10
 * @author jcheron <[email protected]>
11
 * @property array $validatorTypes
12
 */
13
trait ValidatorsManagerInitTrait {
14
15
	/**
16
	 * Parses models and save validators in cache
17
	 * to use in dev only
18
	 *
19
	 * @param array $config
20
	 */
21 1
	public static function initModelsValidators(&$config) {
22 1
		$models = CacheManager::getModels ( $config, true );
23 1
		foreach ( $models as $model ) {
24 1
			self::initClassValidators ( $model );
25
		}
26 1
	}
27
28
	/**
29
	 *
30
	 * Parses a class and save validators in cache
31
	 * to use in dev only
32
	 *
33
	 * @param string $class
34
	 */
35 2
	public static function initClassValidators($class) {
36 2
		$parser = new ValidationModelParser ();
37 2
		$parser->parse ( $class );
38 2
		$validators = $parser->getValidators ();
39 2
		if (sizeof ( $validators ) > 0) {
40 2
			self::store ( $class, $parser->__toString () );
41
		}
42 2
	}
43
44
	/**
45
	 * Parses a class and save validators in cache
46
	 *
47
	 * @param string $class
48
	 */
49 1
	public static function addClassValidators($class) {
50 1
		$config = Startup::getConfig ();
51 1
		CacheManager::start ( $config );
52 1
		self::initClassValidators ( $class );
53 1
	}
54
55
	/**
56
	 * Registers a validator type for using with @validator annotation
57
	 *
58
	 * @param string $type
59
	 * @param string $validatorClass
60
	 */
61
	public static function registerType($type, $validatorClass) {
62
		self::$validatorTypes [$type] = $validatorClass;
63
	}
64
}
65
66