Completed
Pull Request — master (#23)
by Erin
03:28
created

CollectionAssertTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A lengthOf() 0 5 1
A isIncluded() 0 5 1
A notInclude() 0 5 1
1
<?php
2
namespace Peridot\Leo\Interfaces\Assert;
3
4
use Countable;
5
6
/**
7
 * CollectionAssertTrait contains assertions that primarily
8
 * deal with collections and countable values.
9
 *
10
 * @package Peridot\Leo\Interfaces\Assert
11
 */
12
trait CollectionAssertTrait
13
{
14
    /**
15
     * Perform a length assertion.
16
     *
17
     * @param string|array|Countable $countable
18
     * @param $length
19
     * @param string $message
20
     */
21
    public function lengthOf($countable, $length, $message = "")
22
    {
23
        $this->assertion->setActual($countable);
0 ignored issues
show
Bug introduced by
The property assertion does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
        return $this->assertion->to->have->length($length, $message);
25
    }
26
27
    /**
28
     * Perform an inclusion assertion.
29
     *
30
     * @param array|string $haystack
31
     * @param mixed $needle
32
     * @param string $message
33
     */
34
    public function isIncluded($haystack, $needle, $message = "")
35
    {
36
        $this->assertion->setActual($haystack);
37
        return $this->assertion->to->include($needle, $message);
38
    }
39
40
    /**
41
     * Perform a negated inclusion assertion.
42
     *
43
     * @param array|string $haystack
44
     * @param mixed $needle
45
     * @param string $message
46
     */
47
    public function notInclude($haystack, $needle, $message = "")
48
    {
49
        $this->assertion->setActual($haystack);
50
        return $this->assertion->to->not->include($needle, $message);
51
    }
52
}
53