AddFileHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A __invoke() 0 18 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Files\Handler;
5
6
use PersonalGalaxy\Files\{
7
    Command\AddFile,
8
    Entity\File,
9
    Entity\File\Name,
10
    Repository\FileRepository,
11
    Repository\FolderRepository,
12
    Exception\FolderNotFound,
13
};
14
use Innmind\Filesystem\{
15
    Adapter,
16
    File\File as RawFile,
17
};
18
19
final class AddFileHandler
20
{
21
    private $files;
22
    private $folders;
23
    private $filesystem;
24
25 2
    public function __construct(
26
        FileRepository $files,
27
        FolderRepository $folders,
28
        Adapter $filesystem
29
    ) {
30 2
        $this->files = $files;
31 2
        $this->folders = $folders;
32 2
        $this->filesystem = $filesystem;
33 2
    }
34
35 2
    public function __invoke(AddFile $wished): void
36
    {
37 2
        if (!$this->folders->has($wished->folder())) {
38 1
            throw new FolderNotFound($wished->folder());
39
        }
40
41 1
        $file = File::add(
42 1
            $wished->identity(),
43 1
            new Name((string) $wished->file()->name()),
44 1
            $wished->folder(),
45 1
            $wished->file()->mediaType()
46
        );
47 1
        $this->filesystem->add(new RawFile(
48 1
            (string) $wished->identity(),
49 1
            $wished->file()->content(),
50 1
            $wished->file()->mediaType()
51
        ));
52 1
        $this->files->add($file);
53 1
    }
54
}
55