Passed
Push — develop ( eaa894...ad515c )
by Baptiste
01:56
created

MoveFileHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 10 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Files\Handler;
5
6
use PersonalGalaxy\Files\{
7
    Command\MoveFile,
8
    Repository\FileRepository,
9
    Repository\FolderRepository,
10
    Exception\FolderNotFound,
11
};
12
13
final class MoveFileHandler
14
{
15
    private $files;
16
    private $folder;
0 ignored issues
show
introduced by
The private property $folder is not used, and could be removed.
Loading history...
17
18 2
    public function __construct(
19
        FileRepository $files,
20
        FolderRepository $folders
21
    ) {
22 2
        $this->files = $files;
23 2
        $this->folders = $folders;
0 ignored issues
show
Bug Best Practice introduced by
The property folders does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24 2
    }
25
26 2
    public function __invoke(MoveFile $wished): void
27
    {
28 2
        if (!$this->folders->has($wished->folder())) {
29 1
            throw new FolderNotFound($wished->folder());
30
        }
31
32
        $this
33 1
            ->files
34 1
            ->get($wished->identity())
35 1
            ->moveTo($wished->folder());
36 1
    }
37
}
38