Completed
Push — master ( 9c804c...c3c62a )
by Nikola
02:23
created

Backup::getModifiedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
14
namespace RunOpenCode\Backup\Backup;
15
16
use RunOpenCode\Backup\Contract\FileInterface;
17
use RunOpenCode\Backup\Contract\BackupInterface;
18
19
/**
20
 * Class Backup.
21
 *
22
 * Backup is abstraction of collection of files for backup.
23
 */
24
final class Backup implements BackupInterface
25
{
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var FileInterface[]
33
     */
34
    private $files;
35
36
    /**
37
     * @var int
38
     */
39
    private $size;
40
41
    /**
42
     * @var \DateTimeInterface
43
     */
44
    private $createdAt;
45
46
    /**
47
     * @var \DateTimeInterface
48
     */
49
    private $modifiedAt;
50
51 14
    public function __construct($name, array $files = array(), $size = 0, $createdAt = null, $modifiedAt = null)
52
    {
53 14
        $this->name = $name;
54 14
        $this->size = $size;
55 14
        $this->createdAt = is_null($createdAt) ? new \DateTime('now') : $createdAt;
56 14
        $this->modifiedAt = is_null($modifiedAt) ? new \DateTime('now') : $modifiedAt;
57
58 14
        if (count($files)) {
59 4
            $this->setFiles($files);
60 4
        }
61 14
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 14
    public function getName()
67
    {
68 14
        return $this->name;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function setName($name)
75
    {
76
        $this->name = $name;
77
78
        return $this;
79
    }
80
81
    public function addFiles(array $files)
82
    {
83
        foreach ($files as $file) {
84
            $this->addFile($file);
85
        }
86
87
        return $this;
88
    }
89
90 4
    public function addFile(FileInterface $file)
91
    {
92 4
        $this->files[] = $file;
93 4
        $this->size += $file->getSize();
94
95 4
        return $this;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 4
    public function getFiles()
102
    {
103 4
        return $this->files;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 4
    public function setFiles(array $files)
110
    {
111 4
        $this->files = $files;
112 4
        $this->size = 0;
113 4
        foreach ($this->files as $file) {
114 4
            $this->size += $file->getSize();
115 4
        }
116
117 4
        return $this;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 8
    public function getSize()
124
    {
125 8
        return $this->size;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function setSize($size)
132
    {
133
        $this->size = $size;
134
135
        return $this;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141 10
    public function getCreatedAt()
142
    {
143 10
        return $this->createdAt;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function setCreatedAt($createdAt)
150
    {
151
        $this->createdAt = \DateTimeImmutable::createFromMutable((is_integer($createdAt) ? date_timestamp_set(new \DateTime(), $createdAt) : $createdAt));
152
153
        return $this;
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159
    public function getModifiedAt()
160
    {
161
        return $this->modifiedAt;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function setModifiedAt($modifiedAt)
168
    {
169
        $this->modifiedAt = \DateTimeImmutable::createFromMutable((is_integer($modifiedAt) ? date_timestamp_set(new \DateTime(), $modifiedAt) : $modifiedAt));
170
171
        return $this;
172
    }
173
}
174