ProfileController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 63
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A behaviors() 0 20 1
A actionIndex() 0 4 1
A actionShow() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Controller;
13
14
use Da\User\Query\ProfileQuery;
15
use Yii;
16
use yii\base\Module;
17
use yii\filters\AccessControl;
18
use yii\web\Controller;
19
use yii\web\NotFoundHttpException;
20
21
class ProfileController extends Controller
22
{
23
    protected $profileQuery;
24
25
    /**
26
     * ProfileController constructor.
27
     *
28
     * @param string       $id
29
     * @param Module       $module
30
     * @param ProfileQuery $profileQuery
31
     * @param array        $config
32
     */
33
    public function __construct($id, Module $module, ProfileQuery $profileQuery, array $config = [])
34
    {
35
        $this->profileQuery = $profileQuery;
36
        parent::__construct($id, $module, $config);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function behaviors()
43
    {
44
        return [
45
            'access' => [
46
                'class' => AccessControl::class,
47
                'rules' => [
48
                    [
49
                        'allow' => true,
50
                        'actions' => ['index'],
51
                        'roles' => ['@'],
52
                    ],
53
                    [
54
                        'allow' => true,
55
                        'actions' => ['show'],
56
                        'roles' => ['?', '@'],
57
                    ],
58
                ],
59
            ],
60
        ];
61
    }
62
63
    public function actionIndex()
64
    {
65
        return $this->redirect(['show', 'id' => Yii::$app->user->getId()]);
66
    }
67
68
    public function actionShow($id)
69
    {
70
        $profile = $this->profileQuery->whereUserId($id)->one();
71
72
        if ($profile === null) {
73
            throw new NotFoundHttpException();
74
        }
75
76
        return $this->render(
77
            'show',
78
            [
79
                'profile' => $profile,
80
            ]
81
        );
82
    }
83
}
84