Issues (23)

Security Analysis    no vulnerabilities found

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/Handlers/Duty/DutyGroups.php (5 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
namespace SET\Handlers\Duty;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Support\Facades\Gate;
8
use SET\Duty;
9
use SET\DutySwap;
10
11
class DutyGroups extends DutyHelper
12
{
13
    public function __construct(Duty $duty)
14
    {
15
        parent::__construct($duty);
16
    }
17
18
    public function htmlOutput()
19
    {
20
        $newCollection = new Collection();
21
22
        foreach ($this->list as $entry) {
23
            $row = $this->buildHTMLUserRow($entry);
24
25
            $newCollection->push([
26
                'row'  => $row,
27
                'id'   => $entry['id'],
28
                'date' => $entry['date'],
29
            ]);
30
        }
31
32
        return $newCollection;
33
    }
34
35
    public function emailOutput()
36
    {
37
        $collection = $this->list->map(function ($value) {
38
            return [
39
                'users' => $value['group'],
40
                'date'  => $value['date'],
41
            ];
42
        });
43
44
        return $collection;
45
    }
46
47
    /**
48
     * Get function for the list. List is stored on the helper class.
49
     *
50
     * @return Collection
51
     */
52
    public function getList()
53
    {
54
        return $this->list;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->list; of type array<*,array>|Illuminat...ase\Eloquent\Collection adds the type array<*,array> to the return on line 54 which is incompatible with the return type documented by SET\Handlers\Duty\DutyGroups::getList of type Illuminate\Database\Eloquent\Collection.
Loading history...
55
    }
56
57 View Code Duplication
    public function recordNextEntry()
58
    {
59
        if ($this->list->count() < 2) {
60
            return;
61
        }
62
63
        $nextGroupID = $this->list->toArray()[1]['id'];
64
        $this->duty->groups()->updateExistingPivot($nextGroupID, ['last_worked' => Carbon::today()]);
65
    }
66
67
    public function getLastWorked()
68
    {
69
        $this->lastWorkedUser = $this->duty->groups()->orderBy('duty_group.last_worked', 'DESC')->first();
70
71
        return $this;
72
    }
73
74
    public function queryList()
75
    {
76
        $this->list = $this->duty->groups()->orderBy('name')->get();
77
78
        return $this;
79
    }
80
81
    /**
82
     * Take our list of groups and merge them with dates so that each group is assigned a duty date.
83
     *
84
     * @return DutyGroups
85
     */
86
    public function combineListWithDates()
87
    {
88
        $dates = (new DutyDates($this->duty))->getDates();
89
        $newDatesList = array_values(array_diff($dates, $this->swapDates->toArray()));
90
        $count = $this->list->count();
91
        $dateCounter = 0;
92
93
        for ($i = 0; $i < $count; $i++) {
94
            // Does list[i] already have date assigned? Is yes, skip assignment
95
            if (!empty($this->list[$i]['date'])) {
96
                continue;
97 View Code Duplication
            } else {
0 ignored issues
show
This code seems to be duplicated across 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
                $this->list[$i] = [
99
                    'group' => $this->list[$i]['group'],
100
                    'id'    => $this->list[$i]['id'],
101
                    'date'  => $newDatesList[$dateCounter++],
102
                ];
103
            }
104
        }
105
        $this->list = $this->list->sortBy('date');
106
107
        return $this;
108
    }
109
110
    /**
111
     * Query a list of groups who we swapped around and insert them into our current duty list of groups.
112
     */
113
    public function insertFromDutySwap()
114
    {
115
        $dutySwaps = DutySwap::where('duty_id', $this->duty->id)
116
            ->where('imageable_type', 'SET\Group')
117
            ->where('date', '>=', Carbon::now()->subDays(6)) //Omit really old records.
118
            ->orderBy('date', 'ASC')
119
            ->get();
120
121
        $this->convertListToCollection();
122
        $this->swapDates = new Collection();
123
124
        foreach ($dutySwaps as $swap) {
125
            $key = key($this->list->where('id', $swap->imageable_id)->toArray());
0 ignored issues
show
The method where cannot be called on $this->list (of type array<integer|string,arr...,"id":"?","date":"?"}>>).

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...
126
            if (!is_null($key)) {
127
                $this->swapDates->push($swap->date);
128
                $this->list[$key] = [
129
                    'group' => $swap->imageable()->first()->users()->active()->get(),
130
                    'id'    => $swap->imageable()->first()->id,
131
                    'date'  => $swap->date,
132
                ];
133
            }
134
        }
135
136
        return $this;
137
    }
138
139
    /**
140
     * Convert the list of groups into a collection of group users, group id and date.
141
     */
142
    private function convertListToCollection()
143
    {
144
        $count = $this->list->count();
0 ignored issues
show
The method count cannot be called on $this->list (of type array<integer|string,arr...,"id":"?","date":"?"}>>).

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...
145
        $newList = new Collection();
146
        for ($i = 0; $i < $count; $i++) {
147
            $newList->push([
148
                'group' => $this->list[$i]->users()->active()->get(),
0 ignored issues
show
The method users cannot be called on $this->list[$i] (of type array<string,?,{"group":"?","id":"?","date":"?"}>).

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...
149
                'id'    => $this->list[$i]->id,
150
                'date'  => '',
151
            ]);
152
        }
153
        $this->list = $newList;
154
    }
155
156
    /**
157
     * @param $entry
158
     *
159
     * @return string
160
     */
161
    private function buildHTMLUserRow($entry)
162
    {
163
        $row = '';
164
        foreach ($entry['group'] as $user) {
165
            if (Gate::allows('view')) {
166
                $row .= "<a href='".url('user', $user->id)."'>".$user->userFullName.'</a> & ';
167
            } else {
168
                $row .= $user->userFullName.' & ';
169
            }
170
        }
171
        $row = rtrim($row, '& ');
172
173
        return $row;
174
    }
175
}
176