Completed
Pull Request — master (#18)
by
unknown
04:15
created

User   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 54
rs 10
c 2
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B init() 0 45 1
1
<?php
2
namespace Anax\Users;
3
4
/**
5
 * Model for Users.
6
 *
7
 */
8
class User extends \Anax\MVC\CDatabaseModel
9
{
10
11
    /**
12
     * Initialize model.
13
     *
14
     * @return array
15
     */
16
    public function init()
17
    {
18
        // $this->db->setVerbose();
19
        $this->db->dropTableIfExists('user')->execute();
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Anax\Users\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...
20
21
        $this->db->createTable(
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Anax\Users\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...
22
            'user',
23
            [
24
               'id' => ['integer', 'primary key', 'not null', 'auto_increment'],
25
               'acronym' => ['varchar(20)', 'unique', 'not null'],
26
               'email' => ['varchar(80)'],
27
               'name' => ['varchar(80)'],
28
               'password' => ['varchar(255)'],
29
               'created' => ['datetime'],
30
               'updated' => ['datetime'],
31
               'deleted' => ['datetime'],
32
               'active' => ['datetime'],
33
            ]
34
        )->execute();
35
        $this->db->insert(
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Anax\Users\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...
36
            'user',
37
            ['acronym', 'email', 'name', 'password', 'created', 'active']
38
        );
39
40
        $now = gmdate('Y-m-d H:i:s');
41
42
        $this->db->execute([
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Anax\Users\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...
43
            'admin',
44
            '[email protected]',
45
            'Administrator',
46
            password_hash('admin', PASSWORD_DEFAULT),
47
            $now,
48
            $now
49
        ]);
50
51
        $this->db->execute([
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Anax\Users\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...
52
            'doe',
53
            '[email protected]',
54
            'John/Jane Doe',
55
            password_hash('doe', PASSWORD_DEFAULT),
56
            $now,
57
            $now
58
        ]);
59
60
    }
61
}
62