HashMapAsserter::containsKey()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Collections\Tests\Asserters;
12
13
use Cubiche\Core\Collections\HashMapInterface;
14
use mageekguy\atoum\exceptions\logic as LogicException;
15
16
/**
17
 * HashMapAsserter class.
18
 *
19
 * @author Ivannis Suárez Jerez <[email protected]>
20
 */
21
class HashMapAsserter extends CollectionAsserter
22
{
23
    /**
24
     * @var bool
25
     */
26
    protected $assertAll;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setWith($value, $checkType = true)
32
    {
33
        parent::setWith($value, $checkType);
34
35
        if ($checkType === true) {
36
            if ($this->value instanceof HashMapInterface) {
37
                $this->pass();
38
            } else {
39
                $this->fail($this->getLocale()->_('%s is not a list', $this));
40
            }
41
        }
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param mixed $key
48
     *
49
     * @return $this
50
     */
51 View Code Duplication
    public function containsKey($key)
0 ignored issues
show
Duplication introduced by
This method 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...
52
    {
53
        $collection = $this->valueAsCollection();
54
        if ($collection->containsKey($key) === true) {
55
            $this->pass();
56
        } else {
57
            $this->fail($this->getLocale()->_('The hashmap not contain the key %s', $key));
58
        }
59
60
        return $this;
61
    }
62
63
    /**
64
     * @param array|\Traversable $keys
65
     *
66
     * @return $this
67
     */
68
    public function containsKeys($keys)
69
    {
70
        foreach ($keys as $key) {
71
            $this->containsKey($key);
72
        }
73
74
        return $this;
75
    }
76
77
    /**
78
     * @param mixed $key
79
     *
80
     * @return $this
81
     */
82 View Code Duplication
    public function notContainsKey($key)
0 ignored issues
show
Duplication introduced by
This method 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...
83
    {
84
        $collection = $this->valueAsCollection();
85
        if ($collection->containsKey($key) === true) {
86
            $this->fail($this->getLocale()->_('The hashmap contain this key %s', $key));
87
        } else {
88
            $this->pass();
89
        }
90
91
        return $this;
92
    }
93
94
    /**
95
     * @throws LogicException
96
     *
97
     * @return \Cubiche\Core\Collections\HashMapInterface
98
     */
99
    protected function valueAsCollection()
100
    {
101
        $value = $this->valueIsSet()->getValue();
102
        if ($value instanceof HashMapInterface) {
103
            return $value;
104
        }
105
106
        throw new LogicException('Hashmap is undefined');
107
    }
108
}
109