Passed
Push — master ( d2aa98...9cef35 )
by Hirofumi
02:21
created

DeleteAbandonedJobMessageService::__construct()   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 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Shippinno\Job\Application\Messaging;
4
5
use Shippinno\Job\Domain\Model\AbandonedJobMessageStore;
6
7
class DeleteAbandonedJobMessageService
8
{
9
    /**
10
     * @var AbandonedJobMessageStore
11
     */
12
    private $abandonedJobMessageStore;
13
14
    /**
15
     * DeleteAbandonedJobMessageService constructor.
16
     * @param AbandonedJobMessageStore $abandonedJobMessageStore
17
     */
18
    public function __construct(AbandonedJobMessageStore $abandonedJobMessageStore)
19
    {
20
        $this->abandonedJobMessageStore = $abandonedJobMessageStore;
21
    }
22
23
    /**
24
     * @param string $id
25
     * @throws \Shippinno\Job\Domain\Model\AbandonedJobMessageNotFoundException
26
     */
27
    public function execute(string $id): void
28
    {
29
        $abandonedJobMessage = $this->abandonedJobMessageStore->abandonedJobMessageOfId($id);
30
        $this->abandonedJobMessageStore->remove($abandonedJobMessage);
0 ignored issues
show
Bug introduced by
It seems like $abandonedJobMessage defined by $this->abandonedJobMessa...onedJobMessageOfId($id) on line 29 can be null; however, Shippinno\Job\Domain\Mod...bMessageStore::remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
31
    }
32
}
33