Issues (68)

Security Analysis    no request data  

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.

src/Html/Options/HasColumns.php (4 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 Yajra\DataTables\Html\Options;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Str;
7
use Yajra\DataTables\Html\Column;
8
use Illuminate\Contracts\Support\Arrayable;
9
10
/**
11
 * DataTables - Columns option builder.
12
 *
13
 * @see https://datatables.net/reference/option/
14
 */
15
trait HasColumns
16
{
17
    /**
18
     * Set columnDefs option value.
19
     *
20
     * @param mixed $value
21
     * @return $this
22
     * @see https://datatables.net/reference/option/columnDefs
23
     */
24 View Code Duplication
    public function columnDefs($value)
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...
25
    {
26
        if (is_callable($value)) {
27
            $value = app()->call($value);
28
        }
29
30
        if ($value instanceof Arrayable) {
31
            $value = $value->toArray();
32
        }
33
34
        $this->attributes['columnDefs'] = $value;
0 ignored issues
show
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
36
        return $this;
37
    }
38
39
    /**
40
     * Add a columnDef option.
41
     *
42
     * @param mixed $value
43
     * @return $this
44
     * @see https://datatables.net/reference/option/columnDefs
45
     */
46 View Code Duplication
    public function addColumnDef($value)
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...
47
    {
48
        if (is_callable($value)) {
49
            $value = app()->call($value);
50
        }
51
52
        if ($value instanceof Arrayable) {
53
            $value = $value->toArray();
54
        }
55
56
        $this->attributes['columnDefs'][] = $value;
57
58
        return $this;
59
    }
60
61
    /**
62
     * Set columns option value.
63
     *
64
     * @param array $columns
65
     * @return $this
66
     * @see https://datatables.net/reference/option/columns
67
     */
68
    public function columns(array $columns)
69
    {
70
        $this->collection = new Collection;
0 ignored issues
show
The property collection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
71
72
        foreach ($columns as $key => $value) {
73
            if (! is_a($value, Column::class)) {
74
                if (is_array($value)) {
75
                    $attributes = array_merge(
76
                        [
77
                            'name' => $value['name'] ?? $value['data'] ?? $key,
78
                            'data' => $value['data'] ?? $key,
79
                        ],
80
                        $this->setTitle($key, $value)
81
                    );
82
                } else {
83
                    $attributes = [
84
                        'name' => $value,
85
                        'data' => $value,
86
                        'title' => $this->getQualifiedTitle($value),
87
                    ];
88
                }
89
90
                $this->collection->push(new Column($attributes));
91
            } else {
92
                $this->collection->push($value);
93
            }
94
        }
95
96
        return $this;
97
    }
98
99
    /**
100
     * Set title attribute of an array if not set.
101
     *
102
     * @param string $title
103
     * @param array $attributes
104
     * @return array
105
     */
106
    public function setTitle($title, array $attributes)
107
    {
108
        if (! isset($attributes['title'])) {
109
            $attributes['title'] = $this->getQualifiedTitle($title);
110
        }
111
112
        return $attributes;
113
    }
114
115
    /**
116
     * Convert string into a readable title.
117
     *
118
     * @param string $title
119
     * @return string
120
     */
121
    public function getQualifiedTitle($title)
122
    {
123
        return Str::title(str_replace(['.', '_'], ' ', Str::snake($title)));
124
    }
125
126
    /**
127
     * Add a column in collection usingsl attributes.
128
     *
129
     * @param  array $attributes
130
     * @return $this
131
     */
132
    public function addColumn(array $attributes)
133
    {
134
        $this->collection->push(new Column($attributes));
135
136
        return $this;
137
    }
138
139
    /**
140
     * Add a Column object at the beginning of collection.
141
     *
142
     * @param \Yajra\DataTables\Html\Column $column
143
     * @return $this
144
     */
145
    public function addBefore(Column $column)
146
    {
147
        $this->collection->prepend($column);
148
149
        return $this;
150
    }
151
152
    /**
153
     * Add a column at the beginning of collection using attributes.
154
     *
155
     * @param  array $attributes
156
     * @return $this
157
     */
158
    public function addColumnBefore(array $attributes)
159
    {
160
        $this->collection->prepend(new Column($attributes));
161
162
        return $this;
163
    }
164
165
    /**
166
     * Add a Column object in collection.
167
     *
168
     * @param \Yajra\DataTables\Html\Column $column
169
     * @return $this
170
     */
171
    public function add(Column $column)
172
    {
173
        $this->collection->push($column);
174
175
        return $this;
176
    }
177
178
    /**
179
     * Get collection of columns.
180
     *
181
     * @return \Illuminate\Support\Collection
182
     */
183
    public function getColumns()
184
    {
185
        return $this->collection;
186
    }
187
188
    /**
189
     * Remove column by name.
190
     *
191
     * @param array $names
192
     * @return $this
193
     */
194
    public function removeColumn(...$names)
195
    {
196
        foreach ($names as $name) {
197
            $this->collection = $this->collection->filter(function (Column $column) use ($name) {
198
                return $column->name !== $name;
199
            })->flatten();
200
        }
201
202
        return $this;
203
    }
204
}
205