Rmdir   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 4 1
A handle() 0 23 4
1
<?php
2
3
namespace Twistor\Flysystem\Plugin;
4
5
use League\Flysystem\RootViolationException;
6
use League\Flysystem\Util;
7
use Twistor\Flysystem\Exception\DirectoryNotEmptyException;
8
9
class Rmdir extends AbstractPlugin
10
{
11
    /**
12
     * @inheritdoc
13
     */
14 210
    public function getMethod()
15
    {
16 210
        return 'rmdir';
17
    }
18
19
    /**
20
     * Delete a directory.
21
     *
22
     * @param string $dirname path to directory
23
     * @param int $options
24
     *
25
     * @return bool
26
     *
27
     * @throws \Twistor\Flysystem\Exception\DirectoryNotEmptyException
28
     */
29 21
    public function handle($dirname, $options)
30
    {
31 21
        $dirname = Util::normalizePath($dirname);
32
33 21
        if ($dirname === '') {
34 6
            throw new RootViolationException('Root directories can not be deleted.');
35
        }
36
37 15
        $adapter = $this->filesystem->getAdapter();
38
39 15
        if ($options & STREAM_MKDIR_RECURSIVE) {
40
            // I don't know how this gets triggered.
41 3
            return (bool) $adapter->deleteDir($dirname);
42
        }
43
44 12
        $contents = $this->filesystem->listContents($dirname);
45
46 12
        if ( ! empty($contents)) {
47 12
            throw new DirectoryNotEmptyException();
48
        }
49
50 6
        return (bool) $adapter->deleteDir($dirname);
51
    }
52
}
53