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

CollectionAssertTrait::lengthOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
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