Completed
Push — master ( f8aac3...6e7b55 )
by Sebastian
07:15
created

Remote::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use phpbu\App\Util;
5
use phpbu\App\Backup\Path;
6
use phpbu\App\Backup\Target;
7
8
/**
9
 * Abstraction class.
10
 *
11
 * @package    phpbu
12
 * @subpackage Backup
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @author     Vitaly Baev <[email protected]>
15
 * @copyright  Sebastian Feldmann <[email protected]>
16
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
17
 * @link       http://phpbu.de/
18
 * @since      Class available since Release 5.1.0
19
 */
20
abstract class Remote extends Abstraction
21
{
22
    /**
23
     * Path class.
24
     *
25
     * @var \phpbu\App\Backup\Path
26
     */
27
    protected $path;
28
29
    /**
30
     * Setting up Target and fileRegex.
31
     *
32
     * @param \phpbu\App\Backup\Target $target
33
     * @param \phpbu\App\Backup\Path   $path
34
     */
35
    protected function setUp(Target $target, Path $path)
36
    {
37
        $this->target    = $target;
38
        $this->path      = $path;
39
        $this->fileRegex = Util\Path::datePlaceholdersToRegex($target->getFilenameRaw());
40
    }
41
42
    /**
43
     * Return true if target full path matches file and path regex.
44
     *
45
     * @param  string $targetPath Full path to the remote file to check
46
     * @return bool
47
     */
48
    protected function isFileMatch(string $targetPath) : bool
49
    {
50
        $rawPath    = Util\Path::withoutLeadingSlash($this->path->getPathRaw());
51
        $rawPath    = !empty($rawPath) ? Util\Path::withTrailingSlash($rawPath) : $rawPath;
52
        $pathRegex  = Util\Path::datePlaceholdersToRegex($rawPath);
53
        $fileRegex  = Util\Path::datePlaceholdersToRegex($this->target->getFilenameRaw());
54
        $targetPath = Util\Path::withoutLeadingSlash($targetPath);
55
        return preg_match('#' . $pathRegex . $fileRegex . '$#i', $targetPath);
56
    }
57
}
58