Completed
Pull Request — master (#140)
by Vitaly
04:25
created

Ftp::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
namespace phpbu\App\Backup\Collector;
3
4
use phpbu\App\Backup\Collector;
5
use phpbu\App\Backup\Target;
6
7
class Ftp extends Collector
8
{
9
    /**
10
     * FTP connection stream
11
     *
12
     * @var resource
13
     */
14
    private $ftpConnection;
15
16
    /**
17
     * Ftp constructor.
18
     *
19
     * @param \phpbu\App\Backup\Target     $target
20
     * @param resource                     $ftpConnection
21
     */
22
    public function __construct(Target $target, $ftpConnection)
23
    {
24
        $this->ftpConnection = $ftpConnection;
25
        $this->setUp($target);
26
    }
27
28
    /**
29
     * Get all created backups.
30
     *
31
     * @return \phpbu\App\Backup\File[]
32
     */
33
    public function getBackupFiles(): array
34
    {
35
        $files = ftp_nlist($this->ftpConnection, '.');
36
        foreach ($files as $filename) {
37
            if ($filename == $this->target->getFilename()) {
38
                continue;
39
            }
40
            if ($this->isFilenameMatch($filename)) {
41
                $this->files[] = new \phpbu\App\Backup\File\Ftp($this->ftpConnection, $filename);
42
            }
43
        }
44
        return $this->files;
45
    }
46
}
47