Issues (3)

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.

src/mappers/ColumnValueMapper.php (1 issue)

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 the 2amigos/yii2-exportable-widget project.
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace dosamigos\exportable\mappers;
11
12
use yii\base\Model;
13
use yii\db\ActiveRecordInterface;
14
use yii\grid\ActionColumn;
15
use yii\grid\CheckboxColumn;
16
use yii\grid\Column;
17
use yii\grid\DataColumn;
18
use yii\helpers\ArrayHelper;
19
20
class ColumnValueMapper
21
{
22
    /**
23
     * @var array column definitions from GridView
24
     */
25
    protected $columns = [];
26
    /**
27
     * @var array the exportable column names
28
     */
29
    protected $exportableColumns = [];
30
    /**
31
     * @var bool whether we render HTML or not
32
     */
33
    protected $isHtml;
34
35
    /**
36
     * ColumnValueMapper constructor.
37
     *
38
     * @param array $columns
39
     * @param array $exportableColumns
40
     * @param bool $isHtml whether we need to render HTML or not
41
     */
42
    public function __construct(array $columns, array $exportableColumns = [], $isHtml = false)
43
    {
44
        $this->columns = $columns;
45
        $this->exportableColumns = $exportableColumns;
46
        $this->isHtml = $isHtml;
47
    }
48
49
    /**
50
     * Fetch data from the data provider and create the rows array
51
     *
52
     * @param mixed $model
53
     * @param $index
54
     *
55
     * @return array
56
     */
57
    public function map($model, $index)
58
    {
59
        $row = [];
60
        foreach ($this->columns as $column) {
61
            if ($this->isColumnExportable($column)) {
62
                /** @var DataColumn $column */
63
                $key = $model instanceof ActiveRecordInterface
64
                    ? $model->getPrimaryKey()
65
                    : $model[$column->attribute];
66
67
                $value = $this->getColumnValue($column, $model, $key, $index);
68
69
                $header = $this->getColumnHeader($column);
70
                $row[$header] = $value;
71
            }
72
        }
73
74
        return $row;
75
    }
76
77
    protected function getColumnValue($column, $model, $key, $index)
78
    {
79
        $value = $column->renderDataCell($model, $key, $index);
80
        if (!$this->isHtml) {
81
            $value = strip_tags($value);
82
        }
83
84
        return $value;
85
    }
86
87
    /**
88
     * Returns column headers
89
     *
90
     * @param $model
91
     *
92
     * @return array
93
     */
94
    public function getHeaders($model)
0 ignored issues
show
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        $headers = [];
97
        /** @var Column $column */
98
        foreach ($this->columns as $column) {
99
            if ($this->isColumnExportable($column)) {
100
                $headers[] = $this->getColumnHeader($column);
101
            }
102
        }
103
104
        return $headers;
105
    }
106
107
    /**
108
     * Checks whether the column is exportable or not
109
     *
110
     * @param Column $column
111
     *
112
     * @return bool
113
     */
114
    protected function isColumnExportable($column)
115
    {
116
        if ($column instanceof ActionColumn || $column instanceof CheckboxColumn) {
117
            return false;
118
        }
119
120
        if (empty($this->exportableColumns)) {
121
            return true;
122
        }
123
124
        return in_array($column->attribute, $this->exportableColumns);
125
    }
126
127
    /**
128
     * Gets columns header
129
     *
130
     * @param $column
131
     * @param $model
132
     *
133
     * @return string
134
     */
135
    protected function getColumnHeader($column)
136
    {
137
        $header = $column->renderHeaderCell();
138
        if (!$this->isHtml) {
139
            $header = strip_tags($header);
140
        }
141
142
        return $header;
143
    }
144
}
145