Issues (98)

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/Version/Version.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
namespace Sugarcrm\UpgradeSpec\Version;
4
5
final class Version implements \Serializable
6
{
7
    /**
8
     * @var string
9
     */
10
    private $version;
11
12
    /**
13
     * Version constructor.
14
     *
15
     * @param $version
16
     */
17
    public function __construct($version)
18
    {
19
        if (!is_string($version) || !preg_match('/\d+(\.\d+){1,3}/', $version)) {
20
            throw new \InvalidArgumentException(sprintf('"%s" is not a valid SugarCRM version', $version));
21
        }
22
23
        $this->version = $version;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29
    public function isMajor()
30
    {
31
        return count(explode('.', $this->version)) == 2;
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function isFull()
38
    {
39
        return count(explode('.', $this->version)) == 4;
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function isMinor()
46
    {
47
        return !$this->isMajor();
48
    }
49
50
    /**
51
     * @param Version $version
52
     *
53
     * @param bool $strict
54
     *
55
     * @return bool
56
     */
57
    public function isEqualTo(Version $version, $strict = false)
58
    {
59
        if ($strict) {
60
            return $this->version == (string) $version;
61
        }
62
63
        return (string) $this->getFull() == (string) $version->getFull();
64
    }
65
66
    /**
67
     * Checks if the current version is a subversion of given parent
68
     *
69
     * @param Version $parent
70
     *
71
     * @return bool
72
     */
73
    public function isChildOf(Version $parent)
74
    {
75
        $parent = (string) $parent;
0 ignored issues
show
Consider using a different name than the parameter $parent. This often makes code more readable.
Loading history...
76
77
        // exactly the same version is not a child
78
        if ((string) $this === $parent) {
79
            return false;
80
        }
81
82
        return implode('.', array_slice(explode('.', $this->version), 0, count(explode('.', $parent)))) === $parent;
83
    }
84
85
    /**
86
     * @return Version
87
     */
88
    public function getMajor()
89
    {
90
        if ($this->isMajor()) {
91
            return clone $this;
92
        }
93
94
        return new self(implode('.', array_slice(explode('.', $this->version), 0, 2)));
95
    }
96
97
    /**
98
     * @return Version
99
     */
100
    public function getFull()
101
    {
102
        $parts = explode('.', $this->version);
103
        if (count($parts) == 4) {
104
            return $this->version;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->version; (string) is incompatible with the return type documented by Sugarcrm\UpgradeSpec\Version\Version::getFull of type Sugarcrm\UpgradeSpec\Version\Version.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
105
        }
106
107
        $parts = array_merge($parts, array_fill(0, 4 - count($parts), '0'));
108
109
        return new self(implode('.', $parts));
110
    }
111
112
    /**
113
     * Gets all version aliases
114
     * 7.6.0 -> [7.6, 7.6.0, 7.6.0.0], 7.6.1 -> [7.6.1, 7.6.1.0]
115
     *
116
     * @return OrderedList
117
     */
118
    public function getAliases()
119
    {
120
        if ($this->isMajor()) {
121
            return new OrderedList([$this, $this->version . '.0', $this->version . '.0.0']);
122
        }
123
124
        $parts = explode('.', $this->version);
125
        if ($parts[count($parts) - 1] === '0') {
126
            return $this->getParent()->getAliases();
127
        }
128
129
        $aliases = [$this];
130
        while (count($parts) < 4) {
131
            $parts[] = '0';
132
            $aliases[] = implode('.', $parts);
133
        }
134
135
        return new OrderedList($aliases);
136
    }
137
138
    /**
139
     *
140
     *
141
     * @return Version
142
     */
143
    public function getParent()
144
    {
145
        if ($this->isMajor()) {
146
            throw new \LogicException('Major version doesn\'t have parent');
147
        }
148
149
        $parts = explode('.', $this->version);
150
        array_pop($parts);
151
152
        return new self(implode('.', $parts));
153
    }
154
155
    /**
156
     * String representation of object.
157
     *
158
     * @return string the string representation of the object or null
159
     */
160
    public function serialize()
161
    {
162
        return serialize($this->version);
163
    }
164
165
    /**
166
     * Constructs the object.
167
     *
168
     * @param string $serialized
169
     */
170
    public function unserialize($serialized)
171
    {
172
        $this->version = unserialize($serialized);
173
    }
174
175
    /**
176
     * @return string
177
     */
178
    public function __toString()
179
    {
180
        return $this->version;
181
    }
182
}
183