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

MoveFileHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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