KeyAlreadyExists   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getKey() 0 4 1
A getValue() 0 4 1
1
<?php namespace nyx\core\collections\exceptions;
2
3
// Internal dependencies
4
use nyx\core\collections;
5
6
/**
7
 * Key Already Exists In Collection Exception
8
 *
9
 * @version     0.1.0
10
 * @author      Michal Chojnacki <[email protected]>
11
 * @copyright   2012-2017 Nyx Dev Team
12
 * @link        https://github.com/unyx/nyx
13
 */
14
class KeyAlreadyExists extends collections\Exception
15
{
16
    /**
17
     * @var mixed   The key the value was attempted to be set as.
18
     */
19
    private $key;
20
21
    /**
22
     * @var mixed   The value that was attempted to be set with the given key.
23
     */
24
    private $value;
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @param   mixed   $key    The key the value was attempted to be set as.
30
     * @param   mixed   $value  The value that was attempted to be set with the given key.
31
     */
32
    public function __construct(collections\interfaces\Collection $collection, $key, $value, string $message = null, $code = 0, $previous = null)
33
    {
34
        $this->key   = $key;
35
        $this->value = $value;
36
37
        parent::__construct($collection, $message ?? "An item with this key [$key] has already been set.", $code, $previous);
38
    }
39
40
    /**
41
     * Returns the key the value was attempted to be set as.
42
     *
43
     * @return  mixed
44
     */
45
    public function getKey()
46
    {
47
        return $this->key;
48
    }
49
50
    /**
51
     * Returns the value that was attempted to be set with the given key.
52
     *
53
     * @return  mixed
54
     */
55
    public function getValue()
56
    {
57
        return $this->value;
58
    }
59
}
60