UserController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A showUser() 0 5 1
A postUser() 0 16 2
A regenerateApiKey() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers\Dashboard;
13
14
use AltThree\Validator\ValidationException;
15
use Gitamin\Models\User;
16
use Illuminate\Routing\Controller;
17
use Illuminate\Support\Facades\Auth;
18
use Illuminate\Support\Facades\Redirect;
19
use Illuminate\Support\Facades\Request;
20
use Illuminate\Support\Facades\View;
21
22
class UserController extends Controller
23
{
24
    /**
25
     * Shows the user view.
26
     *
27
     * @return \Illuminate\View\View
28
     */
29
    public function showUser()
30
    {
31
        return View::make('dashboard.user.index')
32
            ->withPageTitle(trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'));
33
    }
34
35
    /**
36
     * Updates the current user.
37
     *
38
     * @return \Illuminate\View\View
39
     */
40
    public function postUser()
41
    {
42
        $userData = array_filter(Request::only(['username', 'email', 'password']));
43
44
        try {
45
            Auth::user()->update($userData);
46
        } catch (ValidationException $e) {
47
            return Redirect::route('dashboard.user')
48
                ->withInput($userData)
49
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
50
                ->withErrors($e->getMessageBag());
51
        }
52
53
        return Redirect::route('dashboard.user')
54
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
55
    }
56
57
    /**
58
     * Regenerates the users API key.
59
     *
60
     * @return \Illuminate\View\View
61
     */
62
    public function regenerateApiKey(User $user)
63
    {
64
        $user->api_key = User::generateApiKey();
0 ignored issues
show
Documentation introduced by
The property api_key does not exist on object<Gitamin\Models\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
        $user->save();
66
67
        return Redirect::route('dashboard.user');
68
    }
69
}
70