Completed
Push — master ( 6aac25...fc5b3c )
by Sebastian
04:08 queued 01:04
created

Collector::isFilenameMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace phpbu\App\Backup;
3
4
use phpbu\App\Util\Str;
5
6
/**
7
 * Collector class.
8
 *
9
 * @package    phpbu
10
 * @subpackage Backup
11
 * @author     Sebastian Feldmann <[email protected]>
12
 * @author     Vitaly Baev <[email protected]>
13
 * @copyright  Sebastian Feldmann <[email protected]>
14
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
15
 * @link       http://phpbu.de/
16
 * @since      Class available since Release 5.1.0
17
 */
18
abstract class Collector
19
{
20
    /**
21
     * Backup target
22
     *
23
     * @var \phpbu\App\Backup\Target
24
     */
25
    protected $target;
26
27
    /**
28
     * Target filename regex
29
     *
30
     * @var string
31
     */
32
    protected $fileRegex;
33
34
    /**
35
     * Collection cache
36
     *
37
     * @var \phpbu\App\Backup\File[]
38
     */
39
    protected $files;
40
41
    /**
42
     * Setting up
43
     *
44
     * @param \phpbu\App\Backup\Target $target
45
     */
46 4
    public function setUp(Target $target)
47
    {
48 4
        $this->target = $target;
49 4
        $this->fileRegex = Str::datePlaceholdersToRegex($target->getFilenameRaw());
50 4
        $this->files     = [];
51 4
    }
52
53
    /**
54
     * Returns true if filename matches the target regex
55
     *
56
     * @param string $filename
57
     * @return bool
58
     */
59 13
    protected function isFilenameMatch(string $filename): bool
60
    {
61 13
        return preg_match('#'.$this->fileRegex . '#i', $filename);
62
    }
63
64
    /**
65
     * Get all created backups.
66
     *
67
     * @return \phpbu\App\Backup\File[]
68
     */
69
    abstract public function getBackupFiles() : array;
70
}
71