Completed
Push — master ( 12d056...9bd6a3 )
by Patrick
17s
created

PendingUser   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 1 Features 2
Metric Value
c 6
b 1
f 2
dl 0
loc 103
rs 10
wmc 13
lcom 1
cbo 3

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getHash() 0 4 1
A getRegistrationTime() 0 4 1
A isInGroupNamed() 0 4 1
A __get() 0 8 2
A __set() 0 4 1
A __isset() 0 4 1
A getPassword() 0 4 1
A jsonSerialize() 0 14 2
A sendEmail() 0 20 2
A delete() 0 3 1
1
<?php
2
/**
3
 * PendingUser class
4
 *
5
 * This file describes the PendingUser classes
6
 *
7
 * PHP version 5 and 7
8
 *
9
 * @author Patrick Boyd / [email protected]
10
 * @copyright Copyright (c) 2015, Austin Artistic Reconstruction
11
 * @license http://www.apache.org/licenses/ Apache 2.0 License
12
 */
13
14
namespace Auth;
15
16
/**
17
 * A class to abstract access to PendingUsers (users that have not completed registration) regardless of the Authentication type used.
18
 *
19
 * This class is the primary method to access pending user information.
20
 */
21
class PendingUser extends User
22
{
23
    protected $intData = array();
24
25
    public function getHash()
26
    {
27
        return false;
28
    }
29
30
    public function getRegistrationTime()
31
    {
32
        return false;
33
    }
34
35
    /**
36
     * Is this user in the Group or a child of that group?
37
     *
38
     * @param string $name The name of the group to check if the user is in
39
     *
40
     * @return boolean True if the user is in the group, false otherwise
41
     */
42
    public function isInGroupNamed($name)
43
    {
44
        return false;
45
    }
46
47
    public function __get($propName)
48
    {
49
        if(isset($this->intData[$propName]))
50
        {
51
            return $this->intData[$propName];
52
        }
53
        return parent::__get($propName);
54
    }
55
56
    public function __set($propName, $value)
57
    {
58
        $this->intData[$propName] = $value;
59
    }
60
61
    public function __isset($propName)
62
    {
63
        return isset($this->intData[$propName]);
64
    }
65
66
    /**
67
     * Get the user's password as specified during registration
68
     *
69
     * We need the ability to obtain the user's unhashed plain text password to allow for it to be sent 
70
     * to the correct backend which will hash it
71
     *
72
     * @return boolean|string The current password
73
     */
74
    public function getPassword()
75
    {
76
        return false;
77
    }
78
79
    /**
80
     * Serialize the user data into a format usable by the json_encode method
81
     *
82
     * @return array A simple keyed array representing the user
83
     */
84
    public function jsonSerialize()
85
    {
86
        $user = array();
87
        $user['hash'] = $this->getHash();
88
        $user['mail'] = $this->mail;
0 ignored issues
show
Documentation introduced by
The property mail does not exist on object<Auth\PendingUser>. 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...
89
        $user['uid'] = $this->uid;
0 ignored issues
show
Documentation introduced by
The property uid does not exist on object<Auth\PendingUser>. 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...
90
        $time = $this->getRegistrationTime();
91
        if($time !== false)
92
        {
93
            $user['time'] = $time->format(\DateTime::RFC822);
0 ignored issues
show
Bug introduced by
The method format cannot be called on $time (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
94
        }
95
        $user['class'] = get_class($this);
96
        return $user; 
97
    }
98
99
    public function sendEmail()
100
    {
101
        $email_msg = new \Email\Email();
102
        $email_msg->addToAddress($this->mail);
0 ignored issues
show
Documentation introduced by
The property mail does not exist on object<Auth\PendingUser>. 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...
103
        $email_msg->setTextBody('Thank you for signing up with Burning Flipside. Your registration is not complete until you goto the address below.
104
                https://profiles.burningflipside.com/finish.php?hash='.$this->getHash().'
105
                Thank you,
106
                Burning Flipside Technology Team');
107
        $email_msg->setHTMLBody('Thank you for signing up with Burning Flipside. Your registration is not complete until you follow the link below.<br/>
108
                <a href="https://profiles.burningflipside.com/finish.php?hash='.$this->getHash().'">Complete Registration</a><br/>
109
                Thank you,<br/>
110
                Burning Flipside Technology Team');
111
        $email_msg->setSubject('Burning Flipside Registration');
112
        $email_provider = \EmailProvider::getInstance();
113
        if($email_provider->sendEmail($email_msg) === false)
114
        {
115
            throw new \Exception('Unable to send email!');
116
        }
117
        return true;
118
    }
119
120
    public function delete()
121
    {
122
    }
123
}
124
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
125