Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

Ruleset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A call() 0 14 4
A __unset() 0 3 1
1
<?php
2
3
namespace Vanderlee\Comprehend\builder;
4
5
use Vanderlee\Comprehend\Parser\Parser;
6
7
/**
8
 * Description of Ruleset
9
 *
10
 * @method void define(array | string $name, Definition | Parser | callable $definition = [])
11
 * @method bool defined(string[] | string $name)
12
 * @method void undefine(string[] | string $name)
13
 * //method static void define(array|string $name, Definition|Parser|callable $definition = [])
14
 * //method static bool defined(string[]|string $name)
15
 * //method static void undefine(string[]|string $name)
16
 *
17
 * @author Martijn
18
 */
19
class Ruleset extends AbstractRuleset
20
{
21
    protected static function call(&$rules, $key, $arguments = [])
22
    {
23
        switch ($key) {
24
            case 'define':
25
                return self::defineRule($rules, ...$arguments);
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::defineRule($rules, $arguments) targeting Vanderlee\Comprehend\bui...ctRuleset::defineRule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
$arguments is expanded, but the parameter $names of Vanderlee\Comprehend\bui...ctRuleset::defineRule() does not expect variable arguments. ( Ignorable by Annotation )

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

25
                return self::defineRule($rules, /** @scrutinizer ignore-type */ ...$arguments);
Loading history...
26
27
            case 'defined':
28
                return self::isRuleDefined($rules, ...$arguments);
0 ignored issues
show
Bug introduced by
$arguments is expanded, but the parameter $names of Vanderlee\Comprehend\bui...uleset::isRuleDefined() does not expect variable arguments. ( Ignorable by Annotation )

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

28
                return self::isRuleDefined($rules, /** @scrutinizer ignore-type */ ...$arguments);
Loading history...
29
30
            case 'undefine':
31
                return self::undefineRule($rules, ...$arguments);
0 ignored issues
show
Bug introduced by
$arguments is expanded, but the parameter $names of Vanderlee\Comprehend\bui...Ruleset::undefineRule() does not expect variable arguments. ( Ignorable by Annotation )

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

31
                return self::undefineRule($rules, /** @scrutinizer ignore-type */ ...$arguments);
Loading history...
Bug introduced by
Are you sure the usage of self::undefineRule($rules, $arguments) targeting Vanderlee\Comprehend\bui...Ruleset::undefineRule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
        }
33
34
        return parent::call($rules, $key, $arguments);
35
    }
36
37
    /**
38
     * Define an instance rule
39
     * @param string $name
40
     * @param Mixed $definition
41
     * @throws \Exception
42
     */
43
    public function __set($name, $definition)
44
    {
45
        self::setRule($this->instanceRules, $name, $definition);
46
    }
47
48
    /**
49
     * Undefine an instance rule
50
     * @param string $name
51
     */
52
    public function __unset($name)
53
    {
54
        unset($this->instanceRules[$name]);
55
    }
56
57
}
58