AbstractCollection::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
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