Completed
Push — master ( e6850e...e5139b )
by Pol
02:35 queued 21s
created

Touch::exec()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpvfs\Command;
6
7
use drupol\phpvfs\Filesystem\FilesystemInterface;
8
use drupol\phpvfs\Node\File;
9
10
class Touch
11
{
12
    /**
13
     * @param \drupol\phpvfs\Filesystem\FilesystemInterface $vfs
14
     * @param string $id
15
     * @param string $content
16
     * @param array $attributes
17
     *
18
     * @throws \Exception
19
     *
20
     * @return \drupol\phpvfs\Node\File
21
     */
22 1
    public static function exec(FilesystemInterface $vfs, string $id, string $content = '', array $attributes = [])
23
    {
24 1
        if (Exist::exec($vfs, $id)) {
25 1
            throw new \Exception('File already exist.');
26
        }
27
28 1
        $file = File::create($id, $content, $attributes);
29
30 1
        $vfs->getCwd()->add($file);
31
32 1
        return $file;
33
    }
34
}
35