Passed
Push — main ( 1a73d8...6d7b5d )
by Thierry
14:19
created

CallableChargeClass::checkChargeEdit()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 4
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 9
rs 9.6111
1
<?php
2
3
namespace App\Ajax;
4
5
use Siak\Tontine\Exception\MessageException;
6
use Siak\Tontine\Model\Charge as ChargeModel;
7
use Siak\Tontine\Service\Meeting\Charge\BillService;
8
use Siak\Tontine\Service\Meeting\Charge\SettlementService;
9
use Siak\Tontine\Service\Tontine\ChargeService;
10
11
/**
12
 * @before getCharge
13
 */
14
class CallableChargeClass extends CallableSessionClass
15
{
16
    /**
17
     * @var ChargeModel|null
18
     */
19
    protected ?ChargeModel $charge;
20
21
    /**
22
     * @di
23
     * @var ChargeService
24
     */
25
    protected ChargeService $chargeService;
26
27
    /**
28
     * @di
29
     * @var SettlementService
30
     */
31
    protected SettlementService $settlementService;
32
33
    /**
34
     * @di
35
     * @var BillService
36
     */
37
    protected BillService $billService;
38
39
    /**
40
     * @return void
41
     */
42
43
     protected function getCharge()
44
     {
45
         $chargeId = $this->target()->method() === 'home' ?
46
             $this->target()->args()[0] : $this->bag('meeting')->get('charge.id');
47
         $this->charge = $this->chargeService->getCharge($chargeId);
0 ignored issues
show
Bug introduced by
It seems like $chargeId can also be of type null; however, parameter $chargeId of Siak\Tontine\Service\Ton...rgeService::getCharge() does only seem to accept integer, 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->charge = $this->chargeService->getCharge(/** @scrutinizer ignore-type */ $chargeId);
Loading history...
48
     }
49
  
50
    /**
51
     * @return void
52
     */
53
    protected function checkChargeEdit()
54
    {
55
        if(!$this->session || $this->session->closed)
56
        {
57
            throw new MessageException(trans('meeting.warnings.session.closed'), false);
58
        }
59
        if(!$this->charge || !$this->charge->active)
60
        {
61
            throw new MessageException(trans('meeting.warnings.charge.disabled'), false);
62
        }
63
    }
64
}
65