Issues (3948)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

app/Console/TaskOverdueNotificationCommand.php (12 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
/*
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\Console;
13
14
use Jitamin\Foundation\Security\Role;
15
use Jitamin\Model\TaskModel;
16
use Symfony\Component\Console\Helper\Table;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Task overdue notification command class.
23
 */
24
class TaskOverdueNotificationCommand extends BaseCommand
25
{
26
    /**
27
     * Configure the console command.
28
     *
29
     * @return void
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->setName('notification:overdue-tasks')
35
            ->setDescription('Send notifications for overdue tasks')
36
            ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks')
37
            ->addOption('group', null, InputOption::VALUE_NONE, 'Group all overdue tasks for one user (from all projects) in one email')
38
            ->addOption('manager', null, InputOption::VALUE_NONE, 'Send all overdue tasks to project manager(s) in one email');
39
    }
40
41
    /**
42
     * Execute the console command.
43
     *
44
     * @param InputInterface  $output
45
     * @param OutputInterface $output
46
     *
47
     * @return void
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output)
50
    {
51
        if ($input->getOption('group')) {
52
            $tasks = $this->sendGroupOverdueTaskNotifications();
53
        } elseif ($input->getOption('manager')) {
54
            $tasks = $this->sendOverdueTaskNotificationsToManagers();
55
        } else {
56
            $tasks = $this->sendOverdueTaskNotifications();
57
        }
58
59
        if ($input->getOption('show')) {
60
            $this->showTable($output, $tasks);
61
        }
62
    }
63
64
    /**
65
     * Show table.
66
     *
67
     * @param OutputInterface $output
68
     * @param array           $tasks
69
     *
70
     * @return void
71
     */
72
    public function showTable(OutputInterface $output, array $tasks)
73
    {
74
        $rows = [];
75
76
        foreach ($tasks as $task) {
77
            $rows[] = [
78
                $task['id'],
79
                $task['title'],
80
                date('Y-m-d', $task['date_due']),
81
                $task['project_id'],
82
                $task['project_name'],
83
                $task['assignee_name'] ?: $task['assignee_username'],
84
            ];
85
        }
86
87
        $table = new Table($output);
88
        $table
89
            ->setHeaders(['Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee'])
90
            ->setRows($rows)
91
            ->render();
92
    }
93
94
    /**
95
     * Send all overdue tasks for one user in one email.
96
     */
97 View Code Duplication
    public function sendGroupOverdueTaskNotifications()
0 ignored issues
show
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...
98
    {
99
        $tasks = $this->taskFinderModel->getOverdueTasks();
0 ignored issues
show
The property taskFinderModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
100
101
        foreach ($this->groupByColumn($tasks, 'owner_id') as $user_tasks) {
102
            $users = $this->userNotificationModel->getUsersWithNotificationEnabled($user_tasks[0]['project_id']);
0 ignored issues
show
The property userNotificationModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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
104
            foreach ($users as $user) {
105
                $this->sendUserOverdueTaskNotifications($user, $user_tasks);
106
            }
107
        }
108
109
        return $tasks;
110
    }
111
112
    /**
113
     * Send all overdue tasks in one email to project manager(s).
114
     */
115
    public function sendOverdueTaskNotificationsToManagers()
116
    {
117
        $tasks = $this->taskFinderModel->getOverdueTasks();
0 ignored issues
show
The property taskFinderModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
118
119
        foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
120
            $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id);
0 ignored issues
show
The property userNotificationModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
121
            $managers = [];
122
123
            foreach ($users as $user) {
124
                $role = $this->projectUserRoleModel->getUserRole($project_id, $user['id']);
0 ignored issues
show
The property projectUserRoleModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
125
                if ($role == Role::PROJECT_MANAGER) {
126
                    $managers[] = $user;
127
                }
128
            }
129
130
            foreach ($managers as $manager) {
131
                $this->sendUserOverdueTaskNotificationsToManagers($manager, $project_tasks);
132
            }
133
        }
134
135
        return $tasks;
136
    }
137
138
    /**
139
     * Send overdue tasks.
140
     */
141 View Code Duplication
    public function sendOverdueTaskNotifications()
0 ignored issues
show
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...
142
    {
143
        $tasks = $this->taskFinderModel->getOverdueTasks();
0 ignored issues
show
The property taskFinderModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
144
145
        foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
146
            $users = $this->userNotificationModel->getUsersWithNotificationEnabled($project_id);
0 ignored issues
show
The property userNotificationModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
147
148
            foreach ($users as $user) {
149
                $this->sendUserOverdueTaskNotifications($user, $project_tasks);
150
            }
151
        }
152
153
        return $tasks;
154
    }
155
156
    /**
157
     * Send overdue tasks for a given user.
158
     *
159
     * @param array $user
160
     * @param array $tasks
161
     */
162
    public function sendUserOverdueTaskNotifications(array $user, array $tasks)
163
    {
164
        $user_tasks = [];
165
        $project_names = [];
166
167
        foreach ($tasks as $task) {
168
            if ($this->userNotificationFilterModel->shouldReceiveNotification($user, ['task' => $task])) {
0 ignored issues
show
The property userNotificationFilterModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
169
                $user_tasks[] = $task;
170
                $project_names[$task['project_id']] = $task['project_name'];
171
            }
172
        }
173
174
        if (!empty($user_tasks)) {
175
            $this->userNotificationModel->sendUserNotification(
0 ignored issues
show
The property userNotificationModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
176
                $user,
177
                TaskModel::EVENT_OVERDUE,
178
                ['tasks' => $user_tasks, 'project_name' => implode(', ', $project_names)]
179
            );
180
        }
181
    }
182
183
    /**
184
     * Send overdue tasks for a project manager(s).
185
     *
186
     * @param array $manager
187
     * @param array $tasks
188
     */
189
    public function sendUserOverdueTaskNotificationsToManagers(array $manager, array $tasks)
190
    {
191
        $this->userNotificationModel->sendUserNotification(
0 ignored issues
show
The property userNotificationModel does not exist on object<Jitamin\Console\T...dueNotificationCommand>. 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...
192
            $manager,
193
            TaskModel::EVENT_OVERDUE,
194
            ['tasks' => $tasks, 'project_name' => $tasks[0]['project_name']]
195
        );
196
    }
197
198
    /**
199
     * Group a collection of records by a column.
200
     *
201
     * @param array  $collection
202
     * @param string $column
203
     *
204
     * @return array
205
     */
206
    public function groupByColumn(array $collection, $column)
207
    {
208
        $result = [];
209
210
        foreach ($collection as $item) {
211
            $result[$item[$column]][] = $item;
212
        }
213
214
        return $result;
215
    }
216
}
217