Issues (457)

Security Analysis    not enabled

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/Entity/Helpers/SubClassData.php (6 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
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/4/16
7
 * Time: 10:10 PM
8
 */
9
10
namespace Tfboe\FmLib\Entity\Helpers;
11
12
use Tfboe\FmLib\Exceptions\MethodNotExistingException;
13
use Tfboe\FmLib\Exceptions\PropertyNotExistingException;
14
15
/**
16
 * Trait SubClassData
17
 * implements magic methods for getting and setting subclass data. Stores them in one field, which is stored via
18
 * doctrine as json_array / string (if json_array is not supported).
19
 * @package Tfboe\FmLib\Entity
20
 */
21
trait SubClassData
22
{
23
//<editor-fold desc="Fields">
24
  /**
25
   * @var array
26
   * @ORM\Column(type="json_array")
27
   */
28
  private $subClassData;
29
30
//</editor-fold desc="Fields">
31
32
//<editor-fold desc="Public Final Methods">
33
  /**
34
   * Gets a property or throws an error if the property does not exist.
35
   * @param string $name the name of the property
36
   * @return mixed the value of the property
37
   * @throws PropertyNotExistingException
38
   */
39 View Code Duplication
  public final function getProperty($name)
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...
40
  {
41
    if (!array_key_exists(strtolower($name), $this->subClassData)) {
42
      throw new PropertyNotExistingException(get_class($this), strtolower($name), "getProperty");
43
    }
44
    return $this->subClassData[strtolower($name)];
45
  }
46
47
  /**
48
   * Sets a property with the given name and the given value
49
   * @param string $name the name of the property to set
50
   * @param mixed $value the new value for the property
51
   * @return $this|SubClassData
0 ignored issues
show
Comprehensibility Bug introduced by
The return type SubClassData is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
52
   * @throws PropertyNotExistingException
53
   */
54 View Code Duplication
  public final function setProperty(string $name, $value)
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...
55
  {
56
    if (!array_key_exists(strtolower($name), $this->subClassData)) {
57
      throw new PropertyNotExistingException(get_class($this), strtolower($name), "setProperty");
58
    }
59
    $this->subClassData[strtolower($name)] = $value;
60
    return $this;
61
  }
62
//</editor-fold desc="Public Final Methods">
63
64
//<editor-fold desc="Public Methods">
65
  /**
66
   * Magic function call for getters and setters of subclass data.
67
   * Triggers an error if the function was not a get or set method.
68
   * @param string $name function name
69
   * @param mixed[] $arguments the function arguments
70
   * @return $this|SubClassData|mixed either the value if it was a get request or $this if it was a set method
71
   * @throws MethodNotExistingException
72
   * @throws PropertyNotExistingException
73
   */
74
  public function __call(string $name, $arguments)
75
  {
76
    if (substr($name, 0, 3) === "get") {
77
      return $this->getProperty(substr($name, 3));
78
    } else if (substr($name, 0, 2) === "is") {
79
      return $this->getProperty(substr($name, 2));
80
    } else if (substr($name, 0, 3) === "set" && count($arguments) == 1) {
81
      return $this->setProperty(substr($name, 3), $arguments[0]);
82
    }
83
    throw new MethodNotExistingException(get_class($this), $name);
84
  }
85
86
  /**
87
   * Adds an subclass property if it is not already existent. The default value is used as value.
88
   * @param string $name the property name
89
   * @param mixed $default the default value for the property
90
   * @return $this|SubClassData
0 ignored issues
show
Comprehensibility Bug introduced by
The return type SubClassData is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
91
   */
92
  public function addPropertyIfNotExistent(string $name, $default)
93
  {
94
    if (!array_key_exists(strtolower($name), $this->subClassData)) {
95
      $this->subClassData[strtolower($name)] = $default;
96
    }
97
    return $this;
98
  }
99
100
  /**
101
   * clones the subclass data from other into this
102
   * @param SubClassData $other
0 ignored issues
show
The type SubClassData for parameter $other is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
103
   */
104
  public function cloneSubClassDataFrom($other)
105
  {
106
    $this->subClassData = $other->subClassData;
107
  }
108
109
  /**
110
   * Checks if the contains the given property as subclass data.
111
   * @param string $property the property name
112
   * @return bool true if it has the property and false otherwise
113
   */
114
  public function hasProperty(string $property): bool
115
  {
116
    return array_key_exists(strtolower($property), $this->subClassData) || property_exists($this, $property);
117
  }
118
119
  /**
120
   * Initializes the subclassData structure and adds the given keys with null values to it.
121
   * @param string[] $keys the keys of the subclass data properties (the names).
122
   * @return $this|SubClassData
0 ignored issues
show
Comprehensibility Bug introduced by
The return type SubClassData is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
123
   */
124
  public function initSubClassData(array $keys)
125
  {
126
    $this->subClassData = [];
127
    foreach ($keys as $key) {
128
      $this->subClassData[strtolower($key)] = null;
129
    }
130
    return $this;
131
  }
132
133
  /**
134
   * Checks if a method with the given name exists considering also getter and setter for subclass properties
135
   * @param string $method
136
   * @return bool
137
   */
138
  public function methodExists(string $method): bool
139
  {
140
    if (method_exists($this, $method)) {
141
      return true;
142
    }
143
    //check if method corresponds to existing property
144
    if (substr($method, 0, 3) === "get") {
145
      return $this->hasProperty(substr($method, 3));
146
    } else if (substr($method, 0, 2) === "is") {
147
      return $this->hasProperty(substr($method, 2));
148
    } else if (substr($method, 0, 3) === "set") {
149
      return $this->hasProperty(substr($method, 3));
150
    }
151
152
    return false;
153
  }
154
//</editor-fold desc="Public Methods">
155
156
//<editor-fold desc="Private Methods">
157
//</editor-fold desc="Private Methods">
158
}