AbstractCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A get() 0 4 2
A set() 0 6 1
A exists() 0 4 1
1
<?php
2
3
/**
4
 * @file
5
 * Base implementation of state collections.
6
 */
7
8
namespace Itafroma\Zork\State;
9
10
abstract class AbstractCollection implements CollectionInterface
11
{
12
    protected $atoms = [];
13
14
    /**
15
     * Creates a new atom within the collection.
16
     *
17
     * @param string $name The name of the atom to create.
18
     * @return mixed The atom created.
19
     */
20 1
    public function create($name)
21
    {
22 1
        $this->atoms[$name] = null;
23
24 1
        return $this->atoms[$name];
25
    }
26
27
    /**
28
     * Retrieves an atom by name.
29
     *
30
     * @param string $name The name of the atom to retrieve.
31
     * @return mixed The atom retrieved if it exists, false otherwise.
32
     */
33 2
    public function get($name)
34
    {
35 2
        return isset($this->atoms[$name]) ? $this->atoms[$name] : false;
36
    }
37
38
    /**
39
     * Adds a value to the collection.
40
     *
41
     * @param string $name The name of the atom to add to the collection.
42
     * @param string $value The value to add to the collection.
43
     * @return mixed The value added to the collection.
44
     */
45 1
    public function set($name, $value)
46
    {
47 1
        $this->atoms[$name] = $value;
48
49 1
        return $value;
50
    }
51
52
    /**
53
     * Checks to see if an atom already exists within the collection.
54
     *
55
     * @param string $name The name of the atom.
56
     * @return boolean True if the atom exists, false otherwise.
57
     */
58 2
    public function exists($name)
59
    {
60 2
        return isset($this->atoms[$name]);
61
    }
62
}
63