Completed
Push — master ( f1c80d...df54dd )
by Nikola
02:23
created

Manager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 9
c 7
b 2
f 1
lcom 1
cbo 2
dl 0
loc 73
ccs 21
cts 24
cp 0.875
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A add() 0 5 1
A has() 0 4 1
A get() 0 4 1
A execute() 0 11 2
A getIterator() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup;
14
15
use RunOpenCode\Backup\Contract\ManagerInterface;
16
use RunOpenCode\Backup\Contract\ProfileInterface;
17
use RunOpenCode\Backup\Contract\WorkflowInterface;
18
19
/**
20
 * Class Manager
21
 *
22
 * Backup manager.
23
 *
24
 * @package RunOpenCode\Backup
25
 */
26
final class Manager implements ManagerInterface
27
{
28
    /**
29
     * @var ProfileInterface[]
30
     */
31
    private $profiles;
32
33
    /**
34
     * @var WorkflowInterface
35
     */
36
    private $workflow;
37
38 2
    public function __construct(WorkflowInterface $workflow, $profiles = array())
39
    {
40 2
        $this->profiles = array();
41 2
        $this->workflow = $workflow;
42
43 2
        if (!empty($profiles)) {
44
45 2
            foreach ($profiles as $profile) {
46 2
                $this->add($profile);
47 2
            }
48 2
        }
49 2
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 2
    public function add(ProfileInterface $profile)
55
    {
56 2
        $this->profiles[$profile->getName()] = $profile;
57 2
        return $this;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 2
    public function has($name)
64
    {
65 2
        return (isset($this->profiles[$name]));
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 2
    public function get($name)
72
    {
73 2
        return $this->profiles[$name];
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 2
    public function execute($name)
80
    {
81 2
        if (!$this->has($name)) {
82
            throw new \RuntimeException(sprintf('Unknown profile: "%s".', $name));
83
        }
84
85 2
        $profile = $this->get($name);
86 2
        $this->workflow->execute($profile);
87
88 2
        return $this;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getIterator()
95
    {
96
        return new \ArrayIterator($this->profiles);
97
    }
98
}
99