Issues (194)

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/Common/BasicAttribute.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
namespace Bpost\BpostApiClient\Common;
4
5
use Bpost\BpostApiClient\Exception\BpostLogicException;
6
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException;
7
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidPatternException;
8
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
9
10
abstract class BasicAttribute
11
{
12
    /** @var mixed */
13
    private $value;
14
15
    /** @var string */
16
    private $key;
17
18
    /**
19
     * BasicAttribute constructor.
20
     * @param mixed  $value
21
     * @param string $key
22
     */
23 13
    public function __construct($value, $key = '')
24
    {
25 13
        $this->value = $value;
26 13
        $this->setKey($key);
27 13
        $this->validate();
28 13
    }
29
30
    /**
31
     * @return mixed
32
     */
33 13
    public function getValue()
34
    {
35 13
        return $this->value;
36
    }
37
38
    /**
39
     * @param string $key
40
     */
41 13
    private function setKey($key)
42
    {
43 13
        $this->key = (string)($key ?: $this->getDefaultKey());
44 13
    }
45
46
    /**
47
     * @return string
48
     */
49 8
    public function getKey()
50
    {
51 8
        return $this->key;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 1
    public function __toString()
58
    {
59 1
        return (string)$this->getValue();
60
    }
61
62
    /**
63
     * Prefix $tagName with the $prefix, if needed
64
     * @param string $prefix
0 ignored issues
show
Should the type for parameter $prefix not be string|null?

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...
65
     * @param string $tagName
66
     * @return string
67
     */
68
    public function getPrefixedTagName($tagName, $prefix = null)
69
    {
70
        if (empty($prefix)) {
71
            return $tagName;
72
        }
73
        return $prefix . ':' . $tagName;
74
    }
75
76
    /**
77
     * @param int $length
78
     * @throws BpostInvalidLengthException
79
     */
80 8
    public function validateLength($length)
81
    {
82 8 View Code Duplication
        if (mb_strlen($this->getValue()) > $length) {
0 ignored issues
show
This code seems to be duplicated across 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...
83 4
            throw new BpostInvalidLengthException($this->getKey(), mb_strlen($this->getValue()), $length);
84
        }
85 8
    }
86
87
    /**
88
     * @param array $allowedValues
89
     * @throws BpostInvalidValueException
90
     */
91 5
    public function validateChoice(array $allowedValues)
92
    {
93 5
        if (!in_array($this->getValue(), $allowedValues)) {
94 2
            throw new BpostInvalidValueException($this->getKey(), $this->getValue(), $allowedValues);
95
        }
96 5
    }
97
98
    /**
99
     * @param string $regexPattern
100
     * @throws BpostInvalidPatternException
101
     */
102 5
    public function validatePattern($regexPattern)
103
    {
104 5
        if (!preg_match("/^$regexPattern\$/", $this->getValue())) {
105 2
            throw new BpostInvalidPatternException($this->getKey(), $this->getValue(), $regexPattern);
106
        }
107 5
    }
108
109
    /**
110
     * @return string
111
     */
112
    protected abstract function getDefaultKey();
0 ignored issues
show
The abstract declaration must precede the visibility declaration
Loading history...
113
114
    /**
115
     * @throws BpostLogicException
116
     */
117
    public abstract function validate();
0 ignored issues
show
The abstract declaration must precede the visibility declaration
Loading history...
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
118
119
}
120