Mkdir   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 39
ccs 10
cts 10
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 17 4
1
<?php
2
3
namespace Twistor\Flysystem\Plugin;
4
5
use League\Flysystem\FileNotFoundException;
6
use League\Flysystem\Util;
7
8
class Mkdir extends AbstractPlugin
9
{
10
    /**
11
     * @inheritdoc
12
     */
13 210
    public function getMethod()
14
    {
15 210
        return 'mkdir';
16
    }
17
18
    /**
19
     * Creates a directory.
20
     *
21
     * @param string $dirname
22
     * @param int $mode
23
     * @param int $options
24
     *
25
     * @return bool True on success, false on failure.
26
     *
27
     * @throws \League\Flysystem\FileNotFoundException
28
     */
29 60
    public function handle($dirname, $mode, $options)
30
    {
31 60
        $dirname = Util::normalizePath($dirname);
32
33 60
        $adapter = $this->filesystem->getAdapter();
34
35
        // If recursive, or a single level directory, just create it.
36 60
        if (($options & STREAM_MKDIR_RECURSIVE) || strpos($dirname, '/') === false) {
37 54
            return (bool) $adapter->createDir($dirname, $this->defaultConfig());
38
        }
39
40 18
        if ( ! $adapter->has(dirname($dirname))) {
41 12
            throw new FileNotFoundException($dirname);
42
        }
43
44 12
        return (bool) $adapter->createDir($dirname, $this->defaultConfig());
45
    }
46
}
47