Completed
Push — develop ( 856b14...45ab37 )
by Nate
17:44
created

BeforeInsertProviderInstance::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\events\handlers;
10
11
use flipbox\patron\Patron;
12
use flipbox\patron\records\ProviderInstance;
13
use yii\base\ModelEvent;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class BeforeInsertProviderInstance
20
{
21
    /**
22
     * @param ModelEvent $event
23
     */
24
    public static function handle(ModelEvent $event)
25
    {
26
        $defaultEnvironments = Patron::getInstance()->getSettings()->getDefaultEnvironments();
27
28
        /** @var ProviderInstance $provider */
29
        $provider = $event->sender;
30
31
        // Ignore if already set
32
        if ($provider->isRelationPopulated('environments') === true) {
33
            return;
34
        }
35
36
        $provider->setEnvironments($defaultEnvironments);
37
        $provider->autoSaveEnvironments = true;
38
    }
39
}
40