Issues (1752)

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/Fwlib/Html/ListView/Fitter.php (2 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
namespace Fwlib\Html\ListView;
3
4
use Fwlib\Html\ListView\Exception\InvalidFitModeException;
5
6
/**
7
 * @copyright   Copyright 2015 Fwolf
8
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
9
 */
10
class Fitter implements FitterInterface
11
{
12
    /**
13
     * Empty filler
14
     *
15
     * In body fit process, newly created key will use this as value. This
16
     * will not affect head, which will use key as filler.
17
     *
18
     * Default value also set in ListView configs with key 'fitEmptyFiller'.
19
     *
20
     * @see ListView::getDefaultConfigs()
21
     *
22
     * @var string
23
     */
24
    protected $emptyFiller = '&nbsp;';
25
26
    /**
27
     * Fit mode
28
     *
29
     * Default value also set in ListView configs with key 'fitMode'.
30
     *
31
     * @see ListView::getDefaultConfigs()
32
     * @see FitMode
33
     *
34
     * @var int
35
     */
36
    protected $mode = FitMode::TO_TITLE;
37
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * Skip if their key are same, or either is empty.
43
     *
44
     * @throws  InvalidFitModeException
45
     */
46
    public function fit(ListDto $listDto)
47
    {
48
        $listBody = $listDto->getBody();
49
        $listHead = $listDto->getHead();
50
51
        if (empty($listBody) || empty($listHead)) {
52
            return $listDto;
53
        }
54
55
        $bodyKeys = array_keys(current($listBody));
56
        $headKeys = array_keys($listHead);
57
58
        if ($bodyKeys == $headKeys) {
59
            return $listDto;
60
        }
61
62 View Code Duplication
        switch ($this->mode) {
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...
63
            case FitMode::TO_TITLE:
64
                $fittedKeys = $headKeys;
65
                break;
66
67
            case FitMode::TO_DATA:
68
                $fittedKeys = $bodyKeys;
69
                break;
70
71
            case FitMode::INTERSECTION:
72
                $fittedKeys = array_intersect($headKeys, $bodyKeys);
73
                break;
74
75
            case FitMode::UNION:
76
                $fittedKeys =
77
                    array_unique(array_merge($headKeys, $bodyKeys));
78
                break;
79
80
            default:
81
                throw new InvalidFitModeException;
82
        }
83
84
        $this->fitHead($listDto, $fittedKeys);
85
        $this->fitBody($listDto, $fittedKeys);
86
87
        return $listDto;
88
    }
89
90
91
    /**
92
     * Fit each row in body with given keys
93
     *
94
     * If row index is not in given keys, it will be dropped. If given keys is
95
     * not in row index, it will be created with filling value.
96
     *
97
     * @param   ListDto $listDto
98
     * @param   array   $keys
99
     */
100
    protected function fitBody(ListDto $listDto, array $keys)
101
    {
102
        $listBody = $listDto->getBody();
103
104
        // Use first row in body as sample, need not scan all rows
105
        $sampleRow = current($listBody);
106
107
        $keysToDel = array_diff(array_keys($sampleRow), $keys);
108
109
        $keysToAdd = array_diff($keys, array_keys($sampleRow));
110
111
        if (empty($keysToAdd) && empty($keysToDel)) {
112
            return;
113
        }
114
115
        $deleteDummy = array_fill_keys($keys, null);
116
        $addDummy = array_fill_keys($keysToAdd, $this->emptyFiller);
117
        foreach ($listBody as &$row) {
118
            $row = array_intersect_key($row, $deleteDummy);
119
            $row = array_merge($row, $addDummy);
120
        }
121
        unset($row);
122
123
        $listDto->setBody($listBody);
0 ignored issues
show
$listBody is of type array<integer,array>, but the function expects a array<integer,object<array>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
    }
125
126
127
    /**
128
     * Fit head with given keys
129
     *
130
     * Drop head key not in given keys, and create new if given keys is not
131
     * exists in head array.
132
     *
133
     * @param   ListDto $listDto
134
     * @param   array   $keys
135
     */
136
    protected function fitHead(ListDto $listDto, array $keys)
137
    {
138
        $listHead = $listDto->getHead();
139
140
        // Head index not in keys list
141
        $listHead = array_intersect_key(
142
            $listHead,
143
            array_fill_keys($keys, null)
144
        );
145
146
        // Add keys not exist in head
147
        foreach ($keys as $key) {
148
            if (!array_key_exists($key, $listHead)) {
149
                $listHead[$key] = ucfirst($key);
150
            }
151
        }
152
153
        $listDto->setHead($listHead);
154
    }
155
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function setEmptyFiller($emptyFiller)
161
    {
162
        $this->emptyFiller = $emptyFiller;
163
164
        return $this;
165
    }
166
167
168
    /**
169
     * {@inheritdoc}
170
     */
171
    public function setMode($mode)
172
    {
173
        $this->mode = $mode;
174
175
        return $this;
176
    }
177
}
178