Completed
Pull Request — master (#140)
by
unknown
05:20
created

Collector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace phpbu\App\Backup;
3
4
use phpbu\App\Util\Str;
5
6
abstract class Collector
7
{
8
    /**
9
     * Backup target
10
     *
11
     * @var \phpbu\App\Backup\Target
12
     */
13
    protected $target;
14
15
    /**
16
     * Target filename regex
17
     *
18
     * @var string
19
     */
20
    protected $fileRegex;
21
22
    /**
23
     * Collection cache
24
     *
25
     * @var \phpbu\App\Backup\File[]
26
     */
27
    protected $files;
28
29
    /**
30
     * Setting up
31
     *
32
     * @param \phpbu\App\Backup\Target $target
33
     */
34 4
    public function setUp(Target $target)
35
    {
36 4
        $this->target = $target;
37 4
        $this->fileRegex = Str::datePlaceholdersToRegex($target->getFilenameRaw());
38 4
        $this->files     = [];
39 4
    }
40
41
    /**
42
     * Returns true if filename matches the target regex
43
     *
44
     * @param string $filename
45
     * @return bool
46
     */
47 13
    protected function isFilenameMatch(string $filename): bool
48
    {
49 13
        return preg_match('#'.$this->fileRegex . '#i', $filename);
50
    }
51
52
    /**
53
     * Get all created backups.
54
     *
55
     * @return \phpbu\App\Backup\File[]
56
     */
57
    abstract public function getBackupFiles() : array;
58
}