Passed
Push — master ( 6b49ff...b93f48 )
by Paweł
05:24
created

FindOrCreate::findOrCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 12.06.2018
6
 */
7
8
namespace app\components\traits;
9
10
11
use yii\db\ActiveRecord;
12
13
trait FindOrCreate
14
{
15
    public function findOrCreate(array $conditions, string $class): ActiveRecord
16
    {
17
        $model = $class::findOne($conditions);
18
        if ($model === null) {
19
            $model = new $class($conditions);
20
        }
21
22
        return $model;
23
    }
24
}