UserNotificationModel   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 197
Duplicated Lines 11.17 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 22
loc 197
rs 10
c 0
b 0
f 0
wmc 21
lcom 1
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A sendNotifications() 0 10 3
A sendUserNotification() 0 18 3
A getUsersWithNotificationEnabled() 0 18 4
A enableNotification() 0 4 1
A disableNotification() 0 4 1
B saveSettings() 0 17 5
A readSettings() 0 8 1
A getProjectUserMembersWithNotificationEnabled() 12 12 1
A getProjectGroupMembersWithNotificationEnabled() 0 13 1
A getEverybodyWithNotificationEnabled() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Model;
13
14
use Jitamin\Foundation\Database\Model;
15
use Jitamin\Foundation\Translator;
16
17
/**
18
 * User Notification.
19
 */
20
class UserNotificationModel extends Model
21
{
22
    /**
23
     * Send notifications to people.
24
     *
25
     * @param string $event_name
26
     * @param array  $event_data
27
     */
28
    public function sendNotifications($event_name, array $event_data)
29
    {
30
        $users = $this->getUsersWithNotificationEnabled($event_data['task']['project_id'], $this->userSession->getId());
0 ignored issues
show
Documentation introduced by
The property userSession does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
31
32
        foreach ($users as $user) {
33
            if ($this->userNotificationFilterModel->shouldReceiveNotification($user, $event_data)) {
0 ignored issues
show
Documentation introduced by
The property userNotificationFilterModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
34
                $this->sendUserNotification($user, $event_name, $event_data);
35
            }
36
        }
37
    }
38
39
    /**
40
     * Send notification to someone.
41
     *
42
     * @param array  $user       User
43
     * @param string $event_name
44
     * @param array  $event_data
45
     */
46
    public function sendUserNotification(array $user, $event_name, array $event_data)
47
    {
48
        Translator::unload();
49
50
        // Use the user language otherwise use the application language (do not use the session language)
51
        if (!empty($user['language'])) {
52
            Translator::load($user['language']);
53
        } else {
54
            Translator::load($this->settingModel->get('application_language', 'en_US'));
0 ignored issues
show
Documentation introduced by
The property settingModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
55
        }
56
57
        foreach ($this->userNotificationTypeModel->getSelectedTypes($user['id']) as $type) {
0 ignored issues
show
Documentation introduced by
The property userNotificationTypeModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
58
            $this->userNotificationTypeModel->getType($type)->notifyUser($user, $event_name, $event_data);
0 ignored issues
show
Documentation introduced by
The property userNotificationTypeModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
59
        }
60
61
        // Restore locales
62
        $this->languageModel->loadCurrentLanguage();
0 ignored issues
show
Documentation introduced by
The property languageModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
63
    }
64
65
    /**
66
     * Get a list of people with notifications enabled.
67
     *
68
     * @param int $project_id      Project id
69
     * @param int $exclude_user_id User id to exclude
70
     *
71
     * @return array
72
     */
73
    public function getUsersWithNotificationEnabled($project_id, $exclude_user_id = 0)
74
    {
75
        if ($this->projectPermissionModel->isEverybodyAllowed($project_id)) {
0 ignored issues
show
Documentation introduced by
The property projectPermissionModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
76
            return $this->getEverybodyWithNotificationEnabled($exclude_user_id);
77
        }
78
79
        $users = [];
80
        $members = $this->getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id);
81
        $groups = $this->getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id);
82
83
        foreach (array_merge($members, $groups) as $user) {
84
            if (!isset($users[$user['id']])) {
85
                $users[$user['id']] = $user;
86
            }
87
        }
88
89
        return array_values($users);
90
    }
91
92
    /**
93
     * Enable notification for someone.
94
     *
95
     * @param int $user_id
96
     *
97
     * @return bool
98
     */
99
    public function enableNotification($user_id)
100
    {
101
        return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(['notifications_enabled' => 1]);
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
102
    }
103
104
    /**
105
     * Disable notification for someone.
106
     *
107
     * @param int $user_id
108
     *
109
     * @return bool
110
     */
111
    public function disableNotification($user_id)
112
    {
113
        return $this->db->table(UserModel::TABLE)->eq('id', $user_id)->update(['notifications_enabled' => 0]);
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
114
    }
115
116
    /**
117
     * Save settings for the given user.
118
     *
119
     * @param int   $user_id User id
120
     * @param array $values  Form values
121
     */
122
    public function saveSettings($user_id, array $values)
123
    {
124
        $types = empty($values['notification_types']) ? [] : array_keys($values['notification_types']);
125
126
        if (!empty($types)) {
127
            $this->enableNotification($user_id);
128
        } else {
129
            $this->disableNotification($user_id);
130
        }
131
132
        $filter = empty($values['notifications_filter']) ? UserNotificationFilterModel::FILTER_BOTH : $values['notifications_filter'];
133
        $project_ids = empty($values['notification_projects']) ? [] : array_keys($values['notification_projects']);
134
135
        $this->userNotificationFilterModel->saveFilter($user_id, $filter);
0 ignored issues
show
Documentation introduced by
The property userNotificationFilterModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
136
        $this->userNotificationFilterModel->saveSelectedProjects($user_id, $project_ids);
0 ignored issues
show
Documentation introduced by
The property userNotificationFilterModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
137
        $this->userNotificationTypeModel->saveSelectedTypes($user_id, $types);
0 ignored issues
show
Documentation introduced by
The property userNotificationTypeModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
138
    }
139
140
    /**
141
     * Read user settings to display the form.
142
     *
143
     * @param int $user_id User id
144
     *
145
     * @return array
146
     */
147
    public function readSettings($user_id)
148
    {
149
        $values = $this->db->table(UserModel::TABLE)->eq('id', $user_id)->columns('notifications_enabled', 'notifications_filter')->findOne();
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
150
        $values['notification_types'] = $this->userNotificationTypeModel->getSelectedTypes($user_id);
0 ignored issues
show
Documentation introduced by
The property userNotificationTypeModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
151
        $values['notification_projects'] = $this->userNotificationFilterModel->getSelectedProjects($user_id);
0 ignored issues
show
Documentation introduced by
The property userNotificationFilterModel does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
152
153
        return $values;
154
    }
155
156
    /**
157
     * Get a list of project members with notification enabled.
158
     *
159
     * @param int $project_id      Project id
160
     * @param int $exclude_user_id User id to exclude
161
     *
162
     * @return array
163
     */
164 View Code Duplication
    private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165
    {
166
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
167
            ->table(ProjectUserRoleModel::TABLE)
168
            ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter')
169
            ->join(UserModel::TABLE, 'id', 'user_id')
170
            ->eq(ProjectUserRoleModel::TABLE.'.project_id', $project_id)
171
            ->eq(UserModel::TABLE.'.notifications_enabled', '1')
172
            ->eq(UserModel::TABLE.'.is_active', 1)
173
            ->neq(UserModel::TABLE.'.id', $exclude_user_id)
174
            ->findAll();
175
    }
176
177
    /**
178
     * Get a list of group members with notification enabled.
179
     *
180
     * @param int $project_id      Project id
181
     * @param int $exclude_user_id User id to exclude
182
     *
183
     * @return array
184
     */
185
    private function getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id)
186
    {
187
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
188
            ->table(ProjectGroupRoleModel::TABLE)
189
            ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter')
190
            ->join(GroupMemberModel::TABLE, 'group_id', 'group_id', ProjectGroupRoleModel::TABLE)
191
            ->join(UserModel::TABLE, 'id', 'user_id', GroupMemberModel::TABLE)
192
            ->eq(ProjectGroupRoleModel::TABLE.'.project_id', $project_id)
193
            ->eq(UserModel::TABLE.'.notifications_enabled', '1')
194
            ->neq(UserModel::TABLE.'.id', $exclude_user_id)
195
            ->eq(UserModel::TABLE.'.is_active', 1)
196
            ->findAll();
197
    }
198
199
    /**
200
     * Get a list of project members with notification enabled.
201
     *
202
     * @param int $exclude_user_id User id to exclude
203
     *
204
     * @return array
205
     */
206 View Code Duplication
    private function getEverybodyWithNotificationEnabled($exclude_user_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
    {
208
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\UserNotificationModel>. 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...
209
            ->table(UserModel::TABLE)
210
            ->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', UserModel::TABLE.'.email', UserModel::TABLE.'.language', UserModel::TABLE.'.notifications_filter')
211
            ->eq('notifications_enabled', '1')
212
            ->neq(UserModel::TABLE.'.id', $exclude_user_id)
213
            ->eq(UserModel::TABLE.'.is_active', 1)
214
            ->findAll();
215
    }
216
}
217