Mkdir::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 3
crap 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