Completed
Pull Request — master (#144)
by Mantas
63:58
created

AndRelation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isRelated() 0 10 4
A addRelation() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\FilterManagerBundle\Relation\LogicalJoin;
13
14
use ONGR\FilterManagerBundle\Relation\RelationInterface;
15
16
/**
17
 * This class joins several relations using "and" logical operator.
18
 */
19
class AndRelation implements RelationInterface
20
{
21
    /**
22
     * @var RelationInterface[]
23
     */
24
    private $relations;
25
26
    /**
27
     * @param RelationInterface[] $relations
28
     */
29
    public function __construct($relations = [])
30
    {
31
        $this->relations = $relations;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function isRelated($name)
38
    {
39
        foreach ($this->relations as $relation) {
40
            if (isset($relation) && $relation->isRelated($name) === false) {
41
                return false;
42
            }
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * @param RelationInterface $relation
50
     */
51
    public function addRelation(RelationInterface $relation = null)
52
    {
53
        $this->relations[] = $relation;
54
    }
55
}
56