Issues (26)

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/StructuredData/NumericCellRenderer.php (1 issue)

Severity

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 Consolidation\OutputFormatters\StructuredData;
3
4
use Consolidation\OutputFormatters\Options\FormatterOptions;
5
6
use Consolidation\OutputFormatters\Formatters\FormatterAwareInterface;
7
use Consolidation\OutputFormatters\Formatters\FormatterAwareTrait;
8
9
/**
10
 * Create a formatter to add commas to numeric data.
11
 *
12
 * Example:
13
 *
14
 *    -------
15
 *     Value
16
 *    -------
17
 *      2,384
18
 *    143,894
19
 *         23
20
 *     98,538
21
 *
22
 * This formatter may also be re-used for other purposes where right-justified
23
 * data is desired by simply making a subclass. See method comments below.
24
 *
25
 * Usage:
26
 *
27
 *     return (new RowsOfFields($data))->addRenderer(
28
 *          new NumericCellRenderer($data, ['value'])
29
 *     );
30
 *
31
 */
32
class NumericCellRenderer implements RenderCellInterface, FormatterAwareInterface
33
{
34
    use FormatterAwareTrait;
35
36
    protected $data;
37
    protected $renderedColumns;
38
    protected $widths = [];
39
40
    /**
41
     * NumericCellRenderer constructor
42
     */
43
    public function __construct($data, $renderedColumns)
44
    {
45
        $this->data = $data;
46
        $this->renderedColumns = $renderedColumns;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function renderCell($key, $cellData, FormatterOptions $options, $rowData)
53
    {
54
        if (!$this->isRenderedFormat($options) || !$this->isRenderedColumn($key)) {
55
            return $cellData;
56
        }
57
        if ($this->isRenderedData($cellData)) {
58
            $cellData = $this->formatCellData($cellData);
59
        }
60
        return $this->justifyCellData($key, $cellData);
61
    }
62
63
    /**
64
     * Right-justify the cell data.
65
     */
66
    protected function justifyCellData($key, $cellData)
67
    {
68
        return str_pad($cellData, $this->columnWidth($key), " ", STR_PAD_LEFT);
69
    }
70
71
    /**
72
     * Determine if this format is to be formatted.
73
     */
74
    protected function isRenderedFormat(FormatterOptions $options)
0 ignored issues
show
The parameter $options 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...
75
    {
76
        return $this->isHumanReadable();
77
    }
78
79
    /**
80
     * Determine if this is a column that should be formatted.
81
     */
82
    protected function isRenderedColumn($key)
83
    {
84
        return array_key_exists($key, $this->renderedColumns);
85
    }
86
87
    /**
88
     * Ignore cell data that should not be formatted.
89
     */
90
    protected function isRenderedData($cellData)
91
    {
92
        return is_numeric($cellData);
93
    }
94
95
    /**
96
     * Format the cell data.
97
     */
98
    protected function formatCellData($cellData)
99
    {
100
        return number_format($this->convertCellDataToString($cellData));
101
    }
102
103
    /**
104
     * This formatter only works with columns whose columns are strings.
105
     * To use this formatter for another purpose, override this method
106
     * to ensure that the cell data is a string before it is formatted.
107
     */
108
    protected function convertCellDataToString($cellData)
109
    {
110
        return $cellData;
111
    }
112
113
    /**
114
     * Get the cached column width for the provided key.
115
     */
116
    protected function columnWidth($key)
117
    {
118
        if (!isset($this->widths[$key])) {
119
            $this->widths[$key] = $this->calculateColumnWidth($key);
120
        }
121
        return $this->widths[$key];
122
    }
123
124
    /**
125
     * Using the cached table data, calculate the largest width
126
     * for the data in the table for use when right-justifying.
127
     */
128
    protected function calculateColumnWidth($key)
129
    {
130
        $width = isset($this->renderedColumns[$key]) ? $this->renderedColumns[$key] : 0;
131
        foreach ($this->data as $row) {
132
            $data = $this->formatCellData($row[$key]);
133
            $width = max(strlen($data), $width);
134
        }
135
        return $width;
136
    }
137
}
138