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

Sftp::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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