Failed Conditions
Pull Request — master (#90)
by Jonathan
02:14
created

InflectorService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addRules() 0 20 4
A reset() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector;
6
7
use function array_merge;
8
use function is_array;
9
10
abstract class InflectorService
11
{
12
    /** @var mixed[] */
13
    protected $rules = [];
14
15
    /**
16
     * Method cache array.
17
     *
18
     * @var string[][]
19
     */
20
    protected $cache = [];
21
22
    public function __construct()
23
    {
24
        $this->rules = $this->getRules();
25
    }
26
27
    abstract public function inflect(string $word) : string;
28
29
    /**
30
     * @return string[][]
31
     */
32
    abstract public function getRules() : array;
33
34
    public function reset() : void
35
    {
36
        $this->cache = [];
37
        $this->rules = $this->getRules();
38
    }
39
40
    /**
41
     * @param mixed[] $rules
42
     */
43
    public function addRules(array $rules, bool $reset = false) : void
0 ignored issues
show
Unused Code introduced by
The parameter $reset 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

43
    public function addRules(array $rules, /** @scrutinizer ignore-unused */ bool $reset = false) : void

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...
44
    {
45
        //if ($reset) {
46
            $this->reset();
47
        //}
48
49
        foreach ($rules as $rule => $pattern) {
50
            if (! is_array($pattern)) {
51
                continue;
52
            }
53
54
            $this->rules[$rule] = ($rule === 'uninflected')
55
                ? array_merge($pattern, $this->rules[$rule])
56
                : $pattern + $this->rules[$rule];
57
58
            unset($rules[$rule]);
59
        }
60
61
        $this->rules['rules'] = $rules + $this->rules['rules'];
62
        $this->cache          = [];
63
    }
64
}
65