Completed
Push — master ( 7e790a...ff6d92 )
by Frank
02:46
created

Ftpd::getMetadata()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6.2163

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 9
cts 11
cp 0.8182
rs 8.9617
c 0
b 0
f 0
cc 6
nc 5
nop 1
crap 6.2163
1
<?php
2
3
namespace League\Flysystem\Adapter;
4
5
class Ftpd extends Ftp
6
{
7
    /**
8
     * @inheritdoc
9
     */
10 15
    public function getMetadata($path)
11
    {
12 15
        if ($path === '') {
13 3
            return ['type' => 'dir', 'path' => ''];
14
        }
15 12
        if (@ftp_chdir($this->getConnection(), $path) === true) {
16 9
            $this->setConnectionRoot();
17
18 9
            return ['type' => 'dir', 'path' => $path];
19
        }
20
21 6
        if ( ! ($object = ftp_raw($this->getConnection(), 'STAT ' . $path)) || count($object) < 3) {
22
            return false;
23
        }
24
25 6
        if (substr($object[1], 0, 5) === "ftpd:") {
26 6
            return false;
27
        }
28
29
        return $this->normalizeObject($object[1], '');
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 6
    protected function listDirectoryContents($directory, $recursive = true)
36
    {
37 6
        $listing = ftp_rawlist($this->getConnection(), $directory, $recursive);
38
39 6
        if ($listing === false || ( ! empty($listing) && substr($listing[0], 0, 5) === "ftpd:")) {
40 3
            return [];
41
        }
42
43 3
        return $this->normalizeListing($listing, $directory);
44
    }
45
}
46