Test Failed
Push — master ( a8880a...8a4f74 )
by Jean-Christophe
08:35
created

ValidatorsManagerInitTrait::initClassValidators()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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 1
	 * to use in dev only
18 1
	 *
19 1
	 * @param array $config
20 1
	 */
21 1
	public static function initModelsValidators(&$config) {
22 1
		$models = CacheManager::getModels ( $config, true );
23 1
		foreach ( $models as $model ) {
24 1
			self::initClassValidators ( $config, $model );
25
		}
26
	}
27 1
28
	/**
29
	 *
30
	 * Parses a class and save validators in cache
31
	 * to use in dev only
32
	 *
33
	 * @param array $config
34
	 * @param string $class
35
	 */
36
	public static function initClassValidators(&$config, $class) {
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

36
	public static function initClassValidators(/** @scrutinizer ignore-unused */ &$config, $class) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
		$parser = new ValidationModelParser ();
38
		$parser->parse ( $class );
39
		$validators = $parser->getValidators ();
40
		if (sizeof ( $validators ) > 0) {
41
			self::store ( $class, $parser->__toString () );
42
		}
43
	}
44
45
	/**
46
	 * Parses a class and save validators in cache
47
	 *
48
	 * @param string $class
49
	 */
50
	public static function addClassValidators($class) {
51
		$config = Startup::getConfig ();
52
		CacheManager::start ( $config );
53
		self::initClassValidators ( $config, $class );
54
	}
55
56
	/**
57
	 * Registers a validator type for using with @validator annotation
58
	 *
59
	 * @param string $type
60
	 * @param string $validatorClass
61
	 */
62
	public static function registerType($type, $validatorClass) {
63
		self::$validatorTypes [$type] = $validatorClass;
64
	}
65
}
66
67