StorageStack::getScopes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Storage;
11
12
use Transfer\Storage\Exception\ObjectNotFoundException;
13
14
/**
15
 * Storage stack.
16
 */
17
class StorageStack
18
{
19
    /**
20
     * @var StorageInterface Scope collection
21
     */
22
    protected $scopes;
23
24
    /**
25
     * @param array $scopes Initial scopes
26
     */
27 20
    public function __construct($scopes = array())
28
    {
29 20
        $this->scopes = new InMemoryStorage();
30
31 20
        foreach ($scopes as $scope => $storage) {
32 19
            $this->scopes->add($storage, $scope);
33 20
        }
34 20
    }
35
36
    /**
37
     * Sets scope.
38
     *
39
     * @param string           $scope   Scope name
40
     * @param StorageInterface $storage Scoped storage
41
     */
42 8
    public function setScope($scope, StorageInterface $storage)
43
    {
44 8
        $this->scopes->add($storage, $scope);
45 8
    }
46
47
    /**
48
     * Gets scope.
49
     *
50
     * @param string $scope Scope name
51
     *
52
     * @throws ObjectNotFoundException
53
     *
54
     * @return StorageInterface Object
55
     */
56 8
    public function getScope($scope)
57
    {
58 8
        return $this->scopes->findById($scope);
59
    }
60
61
    /**
62
     * Removes scope.
63
     *
64
     * @param string $scope Scope name
65
     */
66 1
    public function removeScope($scope)
67
    {
68 1
        $this->scopes->removeById($scope);
69 1
    }
70
71
    /**
72
     * Returns all scopes.
73
     *
74
     * @return array|\Iterator|\Traversable Scope collection
75
     */
76 3
    public function getScopes()
77
    {
78 3
        return $this->scopes->all();
79
    }
80
}
81