Test Failed
Push — master ( 74488a...9d98fe )
by Jean-Christophe
26:36
created

ValidatorsManagerInitTrait::initClassValidators()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Ubiquity\contents\validation\traits;
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
	 * @param array $databaseOffset
21
	 */
22
	public static function initModelsValidators(&$config, $databaseOffset = 'default') {
23
		$models = CacheManager::getModels ( $config, true, $databaseOffset );
24
		foreach ( $models as $model ) {
25
			self::initClassValidators ( $model );
26
		}
27
	}
28
29
	/**
30
	 *
31
	 * Parses a class and save validators in cache
32
	 * to use in dev only
33
	 *
34
	 * @param string $class
35
	 */
36
	public static function initClassValidators($class) {
37
		$parser = new ValidationModelParser ();
0 ignored issues
show
Bug introduced by
The type Ubiquity\contents\valida...s\ValidationModelParser 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...
38
		$parser->parse ( $class );
39
		$validators = $parser->getValidators ();
40
		if (\count ( $validators ) > 0) {
41
			self::store ( $class, $validators );
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 ( $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