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/Util/StringUtil.php (5 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\Util;
13
14
use Webmozart\Console\Api\Args\Format\InvalidValueException;
15
use Webmozart\Console\Api\Formatter\Formatter;
16
17
/**
18
 * @since  1.0
19
 *
20
 * @author Bernhard Schussek <[email protected]>
21
 */
22
class StringUtil
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
23
{
24 277
    public static function parseString($value, $nullable = true)
25
    {
26 277
        if ($nullable && (null === $value || 'null' === $value)) {
27 10
            return null;
28
        }
29
30 267
        if (null === $value) {
31 2
            return 'null';
32
        }
33
34 265
        if (true === $value) {
35 1
            return 'true';
36
        }
37
38 264
        if (false === $value) {
39 1
            return 'false';
40
        }
41
42 263
        return (string) $value;
43
    }
44
45 28
    public static function parseBoolean($value, $nullable = true)
46
    {
47 28
        if ($nullable && (null === $value || 'null' === $value)) {
48 4
            return null;
49
        }
50
51 24
        if (is_bool($value)) {
52 2
            return $value;
53
        }
54
55 22
        if (is_string($value) || is_int($value)) {
56 20
            switch ((string) $value) {
57 20
                case '':
58 19
                case 'false':
59 16
                case '0':
60 14
                case 'no':
61 13
                case 'off':
62 8
                    return false;
63
64 12
                case 'true':
65 9
                case '1':
66 7
                case 'yes':
67 6
                case 'on':
68 7
                    return true;
69
            }
70
        }
71
72 7
        throw new InvalidValueException(sprintf(
73 7
            'The value "%s" cannot be parsed as boolean.',
74
            $value
75
        ));
76
    }
77
78 36 View Code Duplication
    public static function parseInteger($value, $nullable = true)
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...
79
    {
80 36
        if ($nullable && (null === $value || 'null' === $value)) {
81 4
            return null;
82
        }
83
84 32
        if (is_numeric($value) || is_bool($value)) {
85 20
            return (int) $value;
86
        }
87
88 12
        throw new InvalidValueException(sprintf(
89 12
            'The value "%s" cannot be parsed as integer.',
90
            $value
91
        ));
92
    }
93
94 30 View Code Duplication
    public static function parseFloat($value, $nullable = true)
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...
95
    {
96 30
        if ($nullable && (null === $value || 'null' === $value)) {
97 4
            return null;
98
        }
99
100 26
        if (is_numeric($value) || is_bool($value)) {
101 14
            return (float) $value;
102
        }
103
104 12
        throw new InvalidValueException(sprintf(
105 12
            'The value "%s" cannot be parsed as float.',
106
            $value
107
        ));
108
    }
109
110 21
    public static function getLength($string, Formatter $formatter = null)
111
    {
112 21
        if ($formatter) {
113 21
            $string = $formatter->removeFormat($string);
114
        }
115
116 21
        if (!function_exists('mb_strwidth')) {
117
            return strlen($string);
118
        }
119
120 21
        if (false === $encoding = mb_detect_encoding($string)) {
121
            return strlen($string);
122
        }
123
124 21
        return mb_strwidth($string, $encoding);
125
    }
126
127 14 View Code Duplication
    public static function getMaxWordLength($string, Formatter $formatter = null)
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...
128
    {
129 14
        if ($formatter) {
130 14
            $string = $formatter->removeFormat($string);
131
        }
132
133 14
        $maxLength = 0;
134 14
        $words = preg_split('/\s+/', $string);
135
136 14
        foreach ($words as $word) {
137
            // No need to pass the formatter because the tags are already
138
            // removed
139 14
            $maxLength = max($maxLength, self::getLength($word));
140
        }
141
142 14
        return $maxLength;
143
    }
144
145 14 View Code Duplication
    public static function getMaxLineLength($string, Formatter $formatter = null)
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...
146
    {
147 14
        if ($formatter) {
148 14
            $string = $formatter->removeFormat($string);
149
        }
150
151 14
        $maxLength = 0;
152 14
        $lines = explode("\n", $string);
153
154 14
        foreach ($lines as $word) {
155
            // No need to pass the formatter because the tags are already
156
            // removed
157 14
            $maxLength = max($maxLength, self::getLength($word));
158
        }
159
160 14
        return $maxLength;
161
    }
162
163
    private function __construct()
164
    {
165
    }
166
}
167