Action   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findModel() 0 7 2
1
<?php
2
3
namespace yiicod\base\actions\base;
4
5
use yii\base\Action as BaseAction;
6
use yii\base\Model;
7
use yii\db\ActiveRecordInterface;
8
use yii\web\HttpException;
9
10
/**
11
 * Class BaseAction
12
 * Base action for extensions
13
 *
14
 * @author Virchenko Maksim <[email protected]>
15
 *
16
 * @deprecated This class was deprecated. Use \yiicod\base\traits\FindRecordTrait instead.
17
 *
18
 * @package yiicod\base\helpers
19
 */
20
class Action extends BaseAction
21
{
22
    /**
23
     * Returns the data model based on the primary key given in the param.
24
     * If the data model is not found, an HTTP exception will be raised.
25
     *
26
     * @param int $id the ID of the model to be loaded
27
     * @param string $class
28
     *
29
     * @return ActiveRecordInterface the loaded model
30
     *
31
     * @throws HttpException
32
     */
33
    public function findModel($id, $class)
34
    {
35
        if ($model = $class::findOne($id)) {
36
            return $model;
37
        }
38
        throw new HttpException(404, 'The requested page does not exist.');
39
    }
40
}
41