Issues (283)

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/UI/Component/BorderUtil.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
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Console\UI\Component;
13
14
use Webmozart\Console\Api\Formatter\Style;
15
use Webmozart\Console\Api\IO\IO;
16
use Webmozart\Console\UI\Style\Alignment;
17
use Webmozart\Console\UI\Style\BorderStyle;
18
use Webmozart\Console\Util\StringUtil;
19
20
/**
21
 * Contains utility methods to draw borders and bordered cells.
22
 *
23
 * @since  1.0
24
 *
25
 * @author Bernhard Schussek <[email protected]>
26
 */
27
class BorderUtil
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
28
{
29
    /**
30
     * Draws a top border.
31
     *
32
     * Crossings are drawn between each pair of columns if more than one column
33
     * length is passed.
34
     *
35
     * @param IO          $io            The I/O.
36
     * @param BorderStyle $style         The border style.
37
     * @param int[]       $columnLengths An array of column lengths.
38
     * @param int         $indentation   The number of spaces to indent.
39
     */
40 21
    public static function drawTopBorder(IO $io, BorderStyle $style, array $columnLengths, $indentation = 0)
41
    {
42 21
        self::drawBorder(
43
            $io,
44
            $columnLengths,
45
            $indentation,
46 21
            $style->getLineHTChar(),
47 21
            $style->getCornerTLChar(),
48 21
            $style->getCrossingTChar(),
49 21
            $style->getCornerTRChar(),
50 21
            $style->getStyle()
51
        );
52 21
    }
53
54
    /**
55
     * Draws a middle border.
56
     *
57
     * Crossings are drawn between each pair of columns if more than one column
58
     * length is passed.
59
     *
60
     * @param IO          $io            The I/O.
61
     * @param BorderStyle $style         The border style.
62
     * @param int[]       $columnLengths An array of column lengths.
63
     * @param int         $indentation   The number of spaces to indent.
64
     */
65 20
    public static function drawMiddleBorder(IO $io, BorderStyle $style, array $columnLengths, $indentation = 0)
66
    {
67 20
        self::drawBorder(
68
            $io,
69
            $columnLengths,
70
            $indentation,
71 20
            $style->getLineHCChar(),
72 20
            $style->getCrossingLChar(),
73 20
            $style->getCrossingCChar(),
74 20
            $style->getCrossingRChar(),
75 20
            $style->getStyle()
76
        );
77 20
    }
78
79
    /**
80
     * Draws a bottom border.
81
     *
82
     * Crossings are drawn between each pair of columns if more than one column
83
     * length is passed.
84
     *
85
     * @param IO          $io            The I/O.
86
     * @param BorderStyle $style         The border style.
87
     * @param int[]       $columnLengths An array of column lengths.
88
     * @param int         $indentation   The number of spaces to indent.
89
     */
90 21
    public static function drawBottomBorder(IO $io, BorderStyle $style, array $columnLengths, $indentation = 0)
91
    {
92 21
        self::drawBorder(
93
            $io,
94
            $columnLengths,
95
            $indentation,
96 21
            $style->getLineHBChar(),
97 21
            $style->getCornerBLChar(),
98 21
            $style->getCrossingBChar(),
99 21
            $style->getCornerBRChar(),
100 21
            $style->getStyle()
101
        );
102 21
    }
103
104
    /**
105
     * Draws a bordered row of cells.
106
     *
107
     * @param IO          $io            The I/O.
108
     * @param BorderStyle $style         The border style.
109
     * @param string[]    $row           The row cells.
110
     * @param int[]       $columnLengths The lengths of the cells.
111
     * @param int[]       $alignments    The alignments of the cells.
112
     * @param string      $cellFormat    The cell format.
113
     * @param Style       $cellStyle     The cell style.
0 ignored issues
show
Should the type for parameter $cellStyle not be null|Style?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
114
     * @param string      $paddingChar   The character used to pad cells.
115
     * @param int         $indentation   The number of spaces to indent.
116
     */
117 21
    public static function drawRow(IO $io, BorderStyle $style, array $row, array $columnLengths, array $alignments, $cellFormat, Style $cellStyle = null, $paddingChar, $indentation = 0)
118
    {
119 21
        $totalLines = 0;
120
121
        // Split all cells into lines
122 21
        foreach ($row as $col => $cell) {
123 21
            $row[$col] = explode("\n", $cell);
124 21
            $totalLines = max($totalLines, count($row[$col]));
125
        }
126
127 21
        $nbColumns = count($row);
128 21
        $borderVLChar = $io->format($style->getLineVLChar(), $style->getStyle());
129 21
        $borderVCChar = $io->format($style->getLineVCChar(), $style->getStyle());
130 21
        $borderVRChar = $io->format($style->getLineVRChar(), $style->getStyle());
131
132 21
        for ($i = 0; $i < $totalLines; ++$i) {
133 21
            $line = str_repeat(' ', $indentation);
134 21
            $line .= $borderVLChar;
135
136 21
            foreach ($row as $col => &$remainingLines) {
137 21
                $cellLine = $remainingLines ? array_shift($remainingLines) : '';
138 21
                $totalPadLength = $columnLengths[$col] - StringUtil::getLength($cellLine, $io);
139 21
                $paddingLeft = '';
140 21
                $paddingRight = '';
141
142 21
                if ($totalPadLength > 0) {
143 20
                    $alignment = isset($alignments[$col]) ? $alignments[$col] : Alignment::LEFT;
144
145
                    switch ($alignment) {
146 20
                        case Alignment::LEFT:
147 18
                            $paddingRight = str_repeat($paddingChar, $totalPadLength);
148 18
                            break;
149 3
                        case Alignment::RIGHT:
150 2
                            $paddingLeft = str_repeat($paddingChar, $totalPadLength);
151 2
                            break;
152 2
                        case Alignment::CENTER:
153 2
                            $leftPadLength = floor($totalPadLength / 2);
154 2
                            $paddingLeft = str_repeat($paddingChar, $leftPadLength);
155 2
                            $paddingRight = str_repeat($paddingChar, $totalPadLength - $leftPadLength);
156 2
                            break;
157
                    }
158
                }
159
160 21
                $line .= $io->format(sprintf($cellFormat, $paddingLeft.$cellLine.$paddingRight), $cellStyle);
161 21
                $line .= $col < $nbColumns - 1 ? $borderVCChar : $borderVRChar;
162
            }
163
164
            // Remove trailing space
165 21
            $io->write(rtrim($line)."\n");
166
        }
167 21
    }
168
169 21
    private static function drawBorder(IO $io, array $columnLengths, $indentation, $lineChar, $crossingLChar, $crossingCChar, $crossingRChar, Style $style = null)
170
    {
171 21
        $line = str_repeat(' ', $indentation);
172 21
        $line .= $crossingLChar;
173
174 21
        for ($i = 0, $l = count($columnLengths); $i < $l; ++$i) {
175 21
            $line .= str_repeat($lineChar, $columnLengths[$i]);
176 21
            $line .= $i < $l - 1 ? $crossingCChar : $crossingRChar;
177
        }
178
179
        // Remove trailing space
180 21
        $line = rtrim($line);
181
182
        // Render only non-empty separators
183 21
        if ($line) {
184 20
            $io->write($io->format($line, $style)."\n");
185
        }
186 21
    }
187
188
    private function __construct()
189
    {
190
    }
191
}
192