UserController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 7
Bugs 4 Features 2
Metric Value
wmc 3
c 7
b 4
f 2
lcom 0
cbo 1
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createUser() 0 22 3
1
<?php
2
/**
3
 * @author   Temitope Olotin <[email protected]>
4
 * @license  <https://opensource.org/license/MIT> MIT
5
 */
6
namespace Laztopaz\EmojiRestfulAPI;
7
8
class UserController
9
{
10
    /**
11
     * This method creates a user account.
12
     *
13
     * @param $data
14
     *
15
     * @return bool true
16
     */
17
    public function createUser(array $data)
18
    {
19
        if (is_array($data)) {
20
            $passwordHashed = password_hash($data['password'], PASSWORD_BCRYPT);
21
22
            $user = User::create([
23
                'firstname'  => $data['firstname'],
24
                'lastname'   => $data['lastname'],
25
                'username'   => $data['username'],
26
                'password'   => $passwordHashed,
27
                'email'      => $data['email'],
28
                'created_at' => date('Y-m-d h:i:s'),
29
                'updated_at' => date('Y-m-d h:i:s'),
30
            ]);
31
32
            if ($user->id) {
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Laztopaz\EmojiRestfulAPI\User>. 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...
33
                return true;
34
            }
35
36
            return false;
37
        }
38
    }
39
}
40