Completed
Push — master ( 97a535...5d395b )
by Carlos C
14:54 queued 02:21
created

CollectionMethods   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 9
c 3
b 1
f 0
lcom 0
cbo 0
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addAll() 0 8 3
A containsAll() 0 9 3
A containsAny() 0 9 3
1
<?php namespace GenericCollections\Traits;
2
3
/**
4
 * This methods apply to BaseCollectionInterface and
5
 * its shared between all the different AbstractCollections like
6
 * AbstractCollection and AbstractMap
7
 *
8
 * This methods are declared to avoid warnings
9
 *
10
 * @package GenericCollections\Traits
11
 */
12
trait CollectionMethods
13
{
14 336
    public function addAll(array $elements)
15
    {
16 336
        $added = false;
17 336
        foreach ($elements as $element) {
18 174
            $added = $this->add($element) || $added;
0 ignored issues
show
Bug introduced by
It seems like add() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19 336
        }
20 336
        return $added;
21
    }
22
23 3
    public function containsAll(array $elements)
24
    {
25 3
        foreach ($elements as $element) {
26 3
            if (! $this->contains($element)) {
0 ignored issues
show
Bug introduced by
The method contains() does not exist on GenericCollections\Traits\CollectionMethods. Did you maybe mean containsAll()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
27 3
                return false;
28
            }
29 3
        }
30 3
        return true;
31
    }
32
33 3
    public function containsAny(array $elements)
34
    {
35 3
        foreach ($elements as $element) {
36 3
            if ($this->contains($element)) {
0 ignored issues
show
Bug introduced by
The method contains() does not exist on GenericCollections\Traits\CollectionMethods. Did you maybe mean containsAll()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37 3
                return true;
38
            }
39 3
        }
40 3
        return false;
41
    }
42
}
43