Completed
Push — master ( b12741...03b4a1 )
by Kirill
01:38
created

Conjunction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 46
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addMatcher() 10 10 2
A match() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of Properties package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Serafim\Properties\Attribute;
11
12
/**
13
 * Class Conjunction
14
 */
15 View Code Duplication
class Conjunction implements Matchable
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * @var array|Matchable[]
19
     */
20
    private $matchable = [];
21
22
    /**
23
     * OrTypeHint constructor.
24
     * @param Matchable $matcher
25
     */
26
    public function __construct(Matchable $matcher)
27
    {
28
        $this->addMatcher($matcher);
29
    }
30
31
    /**
32
     * @param Matchable $matcher
33
     * @return Disjunction
34
     */
35
    public function addMatcher(Matchable $matcher): Matchable
36
    {
37
        if ($matcher instanceof self) {
38
            $this->matchable = \array_merge($this->matchable, $matcher->matchable);
39
        } else {
40
            $this->matchable[] = $matcher;
41
        }
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param mixed $value
48
     * @return bool
49
     */
50
    public function match($value): bool
51
    {
52
        foreach ($this->matchable as $matcher) {
53
            if (! $matcher->match($value)) {
54
                return false;
55
            }
56
        }
57
58
        return true;
59
    }
60
}
61