Test Setup Failed
Push — master ( 6c9e70...259561 )
by Phan
03:40
created

app/Http/Controllers/API/ProfileController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Http\Controllers\API;
4
5
use App\Http\Requests\API\ProfileUpdateRequest;
6
use App\Models\User;
7
use Hash;
8
9
class ProfileController extends Controller
10
{
11
    /**
12
     * Update the current user's profile.
13
     *
14
     * @param ProfileUpdateRequest $request
15
     *
16
     * @throws \RuntimeException
17
     *
18
     * @return \Illuminate\Http\JsonResponse
19
     */
20 View Code Duplication
    public function update(ProfileUpdateRequest $request)
21
    {
22
        $data = $request->only('name', 'email');
23
24
        if ($request->password) {
0 ignored issues
show
The property password does not exist on object<App\Http\Requests...I\ProfileUpdateRequest>. 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...
25
            $data['password'] = Hash::make($request->password);
0 ignored issues
show
The property password does not exist on object<App\Http\Requests...I\ProfileUpdateRequest>. 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...
26
        }
27
28
        return response()->json($request->user()->update($data));
29
    }
30
}
31