Passed
Push — master ( 2ea67c...f4db78 )
by Chris
39:33
created

QueriedModelUpdater::updateModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace WebTheory\Saveyour\Processor;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use WebTheory\Saveyour\Abstracts\QueriesRepositoryTrait;
7
use WebTheory\Saveyour\Contracts\Processor\FormDataProcessorInterface;
8
use WebTheory\Saveyour\Contracts\Report\FormProcessReportInterface;
9
use WebTheory\Saveyour\Enum\ServerRequestLocation;
10
use WebTheory\Saveyour\Processor\Abstracts\AbstractFormDataProcessor;
11
12
class QueriedModelUpdater extends AbstractFormDataProcessor implements FormDataProcessorInterface
13
{
14
    use QueriesRepositoryTrait;
15
16
    public function __construct(
17
        string $name,
18
        ?array $fields,
19
        object $repository,
20
        string $queryMethod,
21
        string $updateMethod,
22
        string $lookup,
23
        ?ServerRequestLocation $location = null,
24
        ?string $commitMethod = null
25
    ) {
26
        parent::__construct($name, $fields);
27
28
        $this->repository = $repository;
29
        $this->queryMethod = $queryMethod;
30
        $this->updateMethod = $updateMethod;
31
        $this->lookup = $lookup;
32
        $this->commitMethod = $commitMethod;
33
        $this->location = $location ?? ServerRequestLocation::Attribute();
34
    }
35
36
    public function process(ServerRequestInterface $request, array $results): ?FormProcessReportInterface
37
    {
38
        if ($this->hasReasonToProcess($results)) {
39
            $this->updateModel($request);
40
        }
41
42
        return null;
43
    }
44
45
    protected function updateModel(ServerRequestInterface $request): void
46
    {
47
        $this->updateRepository($this->getModelFromRepository($request));
0 ignored issues
show
Bug introduced by
It seems like $this->getModelFromRepository($request) can also be of type null; however, parameter $model of WebTheory\Saveyour\Proce...ter::updateRepository() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        $this->updateRepository(/** @scrutinizer ignore-type */ $this->getModelFromRepository($request));
Loading history...
48
        $this->maybeCommitRepositoryChanges();
49
    }
50
}
51