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

BeforeInsertToken::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 11
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\records\Token;
12
use yii\base\ModelEvent;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.0.0
17
 */
18
class BeforeInsertToken
19
{
20
    /**
21
     * Assign default environments to a provider
22
     * @param ModelEvent $event
23
     */
24
    public static function handle(ModelEvent $event)
25
    {
26
        /** @var Token $token */
27
        $token = $event->sender;
28
29
        // Ignore if already set
30
        if ($token->isRelationPopulated('environments') === true) {
31
            return;
32
        }
33
34
        $token->setEnvironments(
35
            $token->getProvider()->getEnvironments()->select('environment')->column()
36
        );
37
        $token->autoSaveEnvironments = true;
38
    }
39
}
40