Completed
Pull Request — master (#274)
by
unknown
63:55 queued 33:13
created

StoreManager::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 21
ccs 9
cts 10
cp 0.9
rs 9.9666
cc 3
nc 4
nop 2
crap 3.009
1
<?php
2
3
namespace Thinktomorrow\Chief\Management\Application;
4
5
use Illuminate\Http\Request;
6
use Thinktomorrow\Chief\Management\Manager;
7
8
class StoreManager
9
{
10 44
    public function handle(Manager $manager, Request $request): Manager
11
    {
12 44
        $manager->guard('store');
13
14 44
        $request = $manager->storeRequest($request);
15
16 44
        $manager->fieldsWithAssistantFields()->validate($request->all());
17
18 41
        if (method_exists($manager, 'beforeStore')) {
19
            $manager->beforeStore($request);
20
        }
21
22 41
        $manager->saveFields($request);
23
24 41
        if (method_exists($manager, 'afterStore')) {
25 15
            $manager->afterStore($request);
26
        }
27
28
        // Since the model doesn't exist yet, it is now created via the save method
29
        // For the store we return the new manager which is now connected to the created model instance
30 41
        return $manager;
31
    }
32
}
33