Completed
Push — experimental/3.1 ( 742b88...c83f5d )
by Yangsin
98:33 queued 98:18
created

SoldOutEventListener::execute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
rs 9.2
1
<?php
2
3
4
namespace Acme\Entity;
5
6
7
use Doctrine\ORM\Event\LifecycleEventArgs;
8
use Doctrine\ORM\Event\PreUpdateEventArgs;
9
use Eccube\Entity\Event\Annotations\PreUpdate;
10
use Eccube\Entity\Event\EntityEventListener;
11
use Eccube\Entity\ProductStock;
12
13
/**
14
 * @PreUpdate("Eccube\Entity\ProductStock")
15
 */
16
class SoldOutEventListener implements EntityEventListener
17
{
18
    public function execute(LifecycleEventArgs $eventArgs)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
19
    {
20
        /** @var PreUpdateEventArgs $eventArgs */
21
        if ($eventArgs->hasChangedField('stock')) {
22
            /** @var ProductStock $ProductStock */
23
            $ProductStock = $eventArgs->getEntity();
24
25
            // 変更前の在庫数
26
            $prevStock = $eventArgs->getOldValue('stock');
27
            // 変更後の在庫数
28
            $currentStock = $ProductStock->getStock();
29
30
            // 在庫数が0になった場合は売り切れ
31
            if ($currentStock == 0 && $prevStock != 0) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
32
                // TODO 管理者にメール送信
33
            }
34
        }
35
    }
36
}