Issues (35)

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/Resource/Resource.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 TomPHP\HalClient\Resource;
4
5
use Assert\Assertion;
6
use TomPHP\HalClient\Exception\FieldNotFoundException;
7
use TomPHP\HalClient\Exception\LinkNotFoundException;
8
use TomPHP\HalClient\Exception\ResourceNotFoundException;
9
10
final class Resource implements ResourceNode
11
{
12
    /** @var array */
13
    private $fields = [];
14
15
    /** @var Link[] */
16
    private $links = [];
17
18
    /** @var Resource[] */
19
    private $resources = [];
20
21
    /**
22
     * @param FieldNode[]    $fields
23
     * @param Link[]         $links
24
     * @param ResourceNode[] $resources
25
     */
26
    public function __construct(array $fields, array $links = [], array $resources = [])
27
    {
28
        Assertion::allIsInstanceOf($fields, FieldNode::class);
29
        Assertion::allIsInstanceOf($links, Link::class);
30
        Assertion::allIsInstanceOf($resources, ResourceNode::class);
31
32
        $this->fields    = $fields;
33
        $this->links     = $links;
34
        $this->resources = $resources;
0 ignored issues
show
Documentation Bug introduced by
It seems like $resources of type array<integer,object<Tom...Resource\ResourceNode>> is incompatible with the declared type array<integer,resource> of property $resources.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
    }
36
37
    /**
38
     * @param string $name
39
     *
40
     * @return FieldNode
41
     */
42
    public function __get($name)
43
    {
44
        return $this->getField($name);
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return FieldNode
51
     *
52
     * @throws FieldNotFoundException
53
     */
54 View Code Duplication
    public function getField($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...
55
    {
56
        if (!array_key_exists($name, $this->fields)) {
57
            throw new FieldNotFoundException($name);
58
        }
59
60
        return $this->fields[$name];
61
    }
62
63
    /** @return string[] */
0 ignored issues
show
Should the return type not be integer[]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
64
    public function getLinks()
65
    {
66
        return array_keys($this->links);
67
    }
68
69
    /**
70
     * @return Link
71
     *
72
     * @throws LinkNotFoundException
73
     */
74
    public function getLink($name)
75
    {
76
        if (!array_key_exists($name, $this->links)) {
77
            throw new LinkNotFoundException($name);
78
        }
79
80
        return $this->links[$name];
81
    }
82
83
    /**
84
     * @return Resource
85
     */
86
    public function getResource($name)
87
    {
88
        if (!array_key_exists($name, $this->resources)) {
89
            throw new ResourceNotFoundException($name);
90
        }
91
92
        return $this->resources[$name];
93
    }
94
95
    public function matches($criteria)
96
    {
97
        foreach ($criteria as $name => $value) {
98
            if (!$this->matchesItem($name, $value)) {
99
                return false;
100
            }
101
        }
102
103
        return true;
104
    }
105
106
    /**
107
     * @param string|int $name
108
     * @param mixed      $value
109
     *
110
     * @return bool
111
     */
112
    private function matchesItem($name, $value)
113
    {
114
        if ($this->isResourceSearchCriteria($name, $value)) {
115
            return $this->matchesResource($value);
116
        }
117
118
        return $this->matchField($name, $value);
119
    }
120
121
    /**
122
     * @param string|int $name
123
     * @param mixed      $value
124
     *
125
     * @return bool
126
     */
127
    private function isResourceSearchCriteria($name, $value)
128
    {
129
        return is_int($name)
130
            && is_array($value)
131
            && array_key_exists(0, $value)
132
            && $value[0] === 'resource';
133
    }
134
135
    /** @return bool */
136
    private function matchesResource(array $value)
137
    {
138
        $name = $value[1];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
139
        $search = $value[2];
140
141
        if (!array_key_exists($name, $this->resources)) {
142
            return false;
143
        }
144
145
        return $this->resources[$name]->matches($search);
0 ignored issues
show
The method matches cannot be called on $this->resources[$name] (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
146
    }
147
148
    /**
149
     * @param string $name
150
     * @param mixed  $value
151
     *
152
     * @return bool
153
     */
154
    public function matchField($name, $value)
155
    {
156
        if (!array_key_exists($name, $this->fields)) {
157
            return false;
158
        }
159
160
        return $this->fields[$name]->matches($value);
161
    }
162
}
163