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

DeleteAbandonedJobMessageService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 26
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 5 1
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