RulesFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
c 1
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createRule() 0 18 2
1
<?php
2
3
/**
4
 * @author: Abdul Qureshi. <[email protected]>
5
 * 
6
 * This file has been modified from the original source.
7
 * See original here:
8
 *
9
 * @link: https://github.com/progsmile/request-validator
10
 */
11
namespace TheSupportGroup\Common\Validator\Helpers;
12
13
use TheSupportGroup\Common\ValidationInterop\ValidationProviderInterface;
14
use TheSupportGroup\Common\Validator\Contracts\Helpers\RulesFactoryInterface;
15
16
class RulesFactory implements RulesFactoryInterface
17
{
18
    /**
19
     * @param $ruleName
20
     * @param $config
21
     * @param $params
22
     *
23
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
24
     */
25
    public function createRule(
26
        $ruleName,
27
        $config,
28
        $params,
29
        ValidationProviderInterface $validationProvider
30
    ) {
31
        $ruleName = ucfirst($ruleName);
32
33
        if (!file_exists(__DIR__.'/../Rules/'.$ruleName.'.php')) {
34
            trigger_error('Such rule doesn\'t exists: '.$ruleName, E_USER_ERROR);
35
        }
36
37
        $class = 'TheSupportGroup\\Common\\Validator\\Rules\\'.$ruleName;
38
        $ruleInstance = new $class($config, $validationProvider);
39
        $ruleInstance->setParams($params);
40
41
        return $ruleInstance;
42
    }
43
}
44