PaymentEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
nc 1
nop 1
dl 0
loc 4
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace Orkhanahmadov\LaravelGoldenpay\Actions;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Orkhanahmadov\LaravelGoldenpay\Models\Payment;
7
8
class PaymentEvent
9
{
10
    /**
11
     * @var Repository
12
     */
13
    private $config;
14
    /**
15
     * @var bool
16
     */
17
    private $enabled = true;
18
19
    /**
20
     * Event constructor.
21
     *
22
     * @param Repository $config
23
     */
24
    public function __construct(Repository $config)
25
    {
26
        $this->config = $config;
27
        $this->enabled = $config->get('goldenpay.payment_events.enabled', true);
28
    }
29
30
    /**
31
     * Fires event with given Payment instance.
32
     *
33
     * @param string $name
34
     * @param Payment $payment
35
     */
36
    public function execute(string $name, Payment $payment): void
37
    {
38
        $event = $this->config->get($name);
39
40
        if ($event && $this->enabled) {
41
            $event::dispatch($payment);
42
        }
43
    }
44
}
45