APIUsersController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Acacha\Events\Http\Controllers;
4
5
use Acacha\Events\Http\Requests\DestroyUser;
6
use Acacha\Events\Http\Requests\UpdateUser;
7
use Acacha\Events\Http\Requests\ListUsers;
8
use Acacha\Events\Http\Requests\ShowUser;
9
use Acacha\Events\Http\Requests\StoreUser;
10
use App\User;
11
12
/**
13
 * Class APIUsersController.
14
 *
15
 * @package App\Http\Controllers
16
 */
17
class APIUsersController extends Controller
18
{
19
    /**
20
     * Show list of users.
21
     *
22
     * @param ListUsers $request
23
     * @return \Illuminate\Database\Eloquent\Collection|static[]
24
     */
25
    public function index(ListUsers $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        return User::all();
28
    }
29
30
    /**
31
     * Show and user
32
     *
33
     * @param ShowUser $request
34
     * @param User $user
35
     * @return User
36
     */
37
    public function show(ShowUser $request, User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        return $user;
40
    }
41
42
    /**
43
     * Store and user.
44
     *
45
     * @param StoreUser $request
46
     * @return mixed
47
     */
48
    public function store(StoreUser $request)
49
    {
50
        return User::create([
51
            'name' => $request->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Acacha\Events\Http\Requests\StoreUser>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
52
            'email' => $request->email,
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<Acacha\Events\Http\Requests\StoreUser>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
53
            'password' => bcrypt($request->password)
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<Acacha\Events\Http\Requests\StoreUser>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
54
        ]);
55
    }
56
57
    /**
58
     * Edit and user.
59
     *
60
     * @param UpdateUser $request
61
     * @param $user
62
     * @return mixed
63
     */
64
    public function update(UpdateUser $request, User $user)
65
    {
66
        $user->update($request->only('name',''));
67
        $user->save();
68
        return $user;
69
    }
70
71
    /**
72
     * Delete user.
73
     *
74
     * @param DestroyUser $request
75
     * @param $user
76
     * @return mixed
77
     */
78
    public function destroy(DestroyUser $request, User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        $user->delete();
81
        return $user;
82
    }
83
84
}
85