Issues (12)

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/string/VariableFixedCG.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 declare(strict_types=1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 06.04.17 at 07:34
5
 */
6
namespace samsonframework\stringconditiontree\string;
7
8
/**
9
 * This class describes character group with next structure:
10
 * - variable length character group
11
 * - fixed length character group
12
 *
13
 * @author Vitaly Egorov <[email protected]>
14
 */
15
class VariableFixedCG extends AbstractCG
16
{
17
    /** string Character group matching regexp pattern matching group name */
18
    const PATTERN_GROUP = 'variableFixed';
19
20
    /** string Character group matching regexp pattern */
21
    const PATTERN = '(?<'.self::PATTERN_GROUP.'>'.VariableCG::PATTERN_REGEXP.FixedCG::PATTERN_REGEXP.')';
22
23
    /** @var VariableCG */
24
    protected $variableCG;
25
26
    /** @var FixedCG */
27
    protected $fixedCG;
28
29
    /**
30
     * @inheritdoc
31
     */
32 24 View Code Duplication
    public function __construct(string $string, int $length = 0)
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...
33
    {
34 24
        parent::__construct($string, $length);
35
36
        // Parse internal character groups
37 24
        $this->variableCG = VariableCG::fromString($string);
38 24
        $this->fixedCG = FixedCG::fromString($string);
39 24
    }
40
41
    /**
42
     * Get variable character group common prefix, if exists then
43
     * append fixed character group prefix.
44
     *
45
     * @inheritdoc
46
     */
47 2
    public function getCommonPrefix(AbstractCG $group): string
48
    {
49
        // Get common prefix as concatenation of variable and fixed character groups common prefixes
50 2
        if ($this->isSameType($group)) {
51
            /** @var VariableFixedCG $group */
52 2
            if (($prefix = $this->variableCG->getCommonPrefix($group->variableCG)) !== ''){
53 2
                return $prefix . $this->fixedCG->getCommonPrefix($group->fixedCG);
54
            }
55
        }
56
57
        // Compare only first variable character groups
58 2
        if ($group instanceof VariableCG) {
59 2
            return $this->variableCG->getCommonPrefix($group);
60
        }
61
62 1
        return '';
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 16
    public function compare(AbstractCG $group): int
69
    {
70
        // Always Fixed character group has higher priority over VariableFixed character group
71 16
        if ($group instanceof FixedCG) {
72 3
            return -1;
73
        }
74
75
        // Always FixedVariable character group has higher priority over VariableFixed character group
76 14
        if ($group instanceof FixedVariableCG) {
77 2
            return -1;
78
        }
79
80
        // VariableFixed character group always has priority over variable character group
81 13
        if ($group instanceof VariableCG) {
82 5
            return 1;
83
        }
84
85 12
        if ($this->isSameType($group)) {
86 12
            return $this->compareLength($group);
87
        }
88
89
        return 0;
90
    }
91
92
    /**
93
     * @inheritdoc
94
     * @param VariableFixedCG $group
95
     */
96 12 View Code Duplication
    protected function compareLength(AbstractCG $group): int
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...
97
    {
98
        // Fixed CG are equal
99 12
        if (($return = $this->compareFixed($group)) === 0) {
0 ignored issues
show
$group of type object<samsonframework\s...tree\string\AbstractCG> is not a sub-type of object<samsonframework\s...string\VariableFixedCG>. It seems like you assume a child class of the class samsonframework\stringco...ntree\string\AbstractCG to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
100
            // Compare variable character groups
101 7
            $return = $this->variableCG->compare($group->variableCG);
0 ignored issues
show
The property variableCG does not seem to exist in samsonframework\stringco...ntree\string\AbstractCG.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
102
        }
103
104 12
        return $return;
105
    }
106
107
    /**
108
     * Longer fixed character group has higher priority.
109
     *
110
     * @param VariableFixedCG $group Compared character group
111
     *
112
     * @return int Comparison result
113
     */
114 12
    private function compareFixed(VariableFixedCG $group): int
115
    {
116
        // Opposite fixed CG comparison
117 12
        return $this->fixedCG->length <=> $group->fixedCG->length;
0 ignored issues
show
The property length cannot be accessed from this context as it is declared protected in class samsonframework\stringco...ntree\string\AbstractCG.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
118
    }
119
}
120