MailController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 20
cts 28
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 10 1
A actionView() 0 10 2
A actionViewHtml() 0 11 2
A actionDownload() 0 8 2
1
<?php
2
3
namespace bedezign\yii2\audit\controllers;
4
5
use bedezign\yii2\audit\components\Helper;
6
use bedezign\yii2\audit\components\web\Controller;
7
use bedezign\yii2\audit\models\AuditMail;
8
use bedezign\yii2\audit\models\AuditMailSearch;
9
use Yii;
10
use yii\web\NotFoundHttpException;
11
12
/**
13
 * MailController
14
 * @package bedezign\yii2\audit\controllers
15
 */
16
class MailController extends Controller
17
{
18
    /**
19
     * Lists all AuditMail models.
20
     * @return mixed
21
     */
22 6
    public function actionIndex()
23
    {
24 6
        $searchModel = new AuditMailSearch;
25 6
        $dataProvider = $searchModel->search(Yii::$app->request->get());
26
27 6
        return $this->render('index', [
28 6
            'dataProvider' => $dataProvider,
29 6
            'searchModel' => $searchModel,
30 6
        ]);
31
    }
32
33
    /**
34
     * Displays a single AuditMail model.
35
     * @param integer $id
36
     * @return mixed
37
     * @throws NotFoundHttpException
38
     */
39 3
    public function actionView($id)
40
    {
41 3
        $model = AuditMail::findOne($id);
42 3
        if (!$model) {
43 3
            throw new NotFoundHttpException('The requested mail does not exist.');
44
        }
45 3
        return $this->render('view', [
46 3
            'model' => $model,
47 3
        ]);
48
    }
49
50
    /**
51
     * Displays a single AuditMail model's HTML.
52
     * @param integer $id
53
     * @return mixed
54
     * @throws NotFoundHttpException
55
     */
56
    public function actionViewHtml($id)
57
    {
58
        $model = AuditMail::findOne($id);
59
        if (!$model) {
60
            throw new NotFoundHttpException('The requested mail does not exist.');
61
        }
62
        $this->layout = false;
63
        return $this->render('view-html', [
64
            'model' => $model,
65
        ]);
66
    }
67
68
    /**
69
     * Download an AuditMail file as eml.
70
     * @param $id
71
     * @throws NotFoundHttpException
72
     */
73 3
    public function actionDownload($id)
74
    {
75 3
        $model = AuditMail::findOne($id);
76 3
        if (!$model) {
77 3
            throw new NotFoundHttpException('The requested mail does not exist.');
78
        }
79 3
        Yii::$app->response->sendContentAsFile(Helper::uncompress($model->data), $model->id . '.eml');
80 3
    }
81
}
82