Completed
Pull Request — master (#140)
by
unknown
11:59 queued 08:36
created

Ftp::getBackupFiles()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 0
crap 30
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use League\Flysystem\Filesystem;
5
use phpbu\App\Backup\Collector;
6
use phpbu\App\Backup\Target;
7
8
class Ftp extends Collector
9
{
10
    /**
11
     * @var Filesystem
12
     */
13
    private $flySystem;
14
15
    /**
16
     * @var string
17
     */
18
    private $path;
19
20
    /**
21
     * Ftp constructor.
22
     *
23
     * @param \phpbu\App\Backup\Target     $target
24
     * @param \League\Flysystem\Filesystem $flySystem
25
     */
26
    public function __construct(Target $target, Filesystem $flySystem)
27
    {
28
        $this->flySystem = $flySystem;
29
        $this->setUp($target);
30
    }
31
32
    /**
33
     * Get all created backups.
34
     *
35
     * @return \phpbu\App\Backup\File[]
36
     */
37
    public function getBackupFiles(): array
38
    {
39
        $files = $this->flySystem->listContents();
40
        foreach ($files as $file) {
41
            if ($file['type'] != 'file') {
42
                continue;
43
            }
44
            // skip currently created backup
45
            if ($file['basename'] == $this->target->getFilename()) {
46
                continue;
47
            }
48
            if ($this->isFilenameMatch($file['basename'])) {
49
                $this->files[] = new \phpbu\App\Backup\File\Ftp($this->flySystem, $file);
50
            }
51
        }
52
        return $this->files;
53
    }
54
}
55