Completed
Push — master ( 8a7993...1a063d )
by Nikola
05:00
created

BaseDestination::push()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.439
cc 5
eloc 12
nc 12
nop 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\Destination;
14
15
use RunOpenCode\Backup\Contract\BackupInterface;
16
use RunOpenCode\Backup\Contract\DestinationInterface;
17
/**
18
 * Class BaseDestination
19
 *
20
 * BaseDestination provides prototype for concrete destination implementation.
21
 *
22
 * @package RunOpenCode\Backup\Destination
23
 */
24
abstract class BaseDestination implements DestinationInterface
25
{
26
    /**
27
     * @var BackupInterface[]
28
     */
29
    protected $backups;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getIterator()
35
    {
36
        if (is_null($this->backups)) {
37
            $this->load();
38
        }
39
40
        return new \ArrayIterator($this->backups);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 14
    public function get($name)
47
    {
48 14
        if (is_null($this->backups)) {
49
            $this->load();
50
        }
51
52 14
        return $this->backups[$name];
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 14
    public function has($name)
59
    {
60 14
        if (is_null($this->backups)) {
61 14
            $this->load();
62 7
        }
63
64 14
        return array_key_exists($name, $this->backups);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function all()
71
    {
72
        if (is_null($this->backups)) {
73
            $this->load();
74
        }
75
76
        return $this->backups;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 4
    public function count()
83
    {
84 4
        if (is_null($this->backups)) {
85
            $this->load();
86
        }
87
88 4
        return count($this->backups);
89
    }
90
91
    /**
92
     * Load backups from destination.
93
     *
94
     * @return BackupInterface[]
95
     */
96
    abstract protected function load();
97
}
98