Issues (4)

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/Graph/Builder.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 PHPAlgorithms\GraphTools\Graph;
4
5
use PHPAlgorithms\GraphTools\Abstracts\BuilderAbstract;
6
use PHPAlgorithms\GraphTools\Graph;
7
8
/**
9
 * Class Builder
10
 * @package PHPAlgorithms\GraphTools\Graph
11
 * @method  Connection[] getConnections()
12
 * @method Node[] getNodes()
13
 * @property-read Connection[] $connections
14
 * @property-read Node[] $nodes
15
 */
16
class Builder extends BuilderAbstract
17
{
18
    private const OPERATION_ADD_CONNECTION = 2;
19
20
    private const OPERATION_ADD_NODE = 1;
21
22
    private const OPERATION_NO_OPERATION = 0;
23
24
    /**
25
     * @var array $allowedGet
26
     */
27
    protected $allowedGet = array('connections', 'nodes');
28
29
    /**
30
     * @var Connection[] $connections
31
     */
32
    protected $connections = array();
33
34
    /**
35
     * @var Connection|null $lastConnection
36
     */
37
    private $lastConnection = null;
38
39
    /**
40
     * @var integer $lastOperation
41
     */
42
    private $lastOperation = self::OPERATION_NO_OPERATION;
43
44
    /**
45
     * @var Node[] $nodes
46
     */
47
    protected $nodes = array();
48
49
    /**
50
     * @param Connection $connection
51
     * @return Builder
52
     */
53
    public function addConnection(Connection $connection) : Builder
54
    {
55
        try {
56
            $this->addNode($connection->from);
57
        } catch (Builder\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
58
        }
59
60
61
        try {
62
            $this->addNode($connection->to);
63
        } catch (Builder\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
64
        }
65
66
        $this->connections[] = $connection;
67
68
        $this->lastOperation = self::OPERATION_ADD_CONNECTION;
69
70
        $this->lastConnection = $connection;
71
72
        return $this;
73
    }
74
75
    /**
76
     * @param Node $node
77
     * @return Builder
78
     * @throws Builder\Exception
79
     */
80
    public function addNode(Node $node) : Builder
81
    {
82
        if (in_array($node, $this->nodes, true)) {
83
            throw new Builder\Exception('Node was added before');
84
        }
85
86
        $this->nodes[] = $node;
87
88
        $this->lastOperation = self::OPERATION_ADD_NODE;
89
90
        return $this;
91
    }
92
93
    /**
94
     * @return Graph
95
     */
96
    public function build() : Graph
97
    {
98
        return new Graph($this->nodes, $this->connections);
99
    }
100
101
    /**
102
     * @param Node $from
103
     * @param Node $to
104
     * @param float|null $weight
105
     * @return Builder
106
     */
107
    public function connect(Node $from, Node $to, float $weight = null) : Builder
108
    {
109
        $this->addConnection(new Connection($from, $to, $weight));
110
111
        return $this;
112
    }
113
114
    /**
115
     * @return Node\Builder
116
     */
117
    public function createNode() : Node\Builder
118
    {
119
        return new Node\Builder($this);
120
    }
121
122
    /**
123
     * @return Connection\Builder
124
     */
125
    public function createConnection() : Connection\Builder
126
    {
127
        return new Connection\Builder($this);
128
    }
129
130
    /**
131
     * @param integer $index
132
     * @return Node
133
     */
134
    public function getNode(int $index) : Node
135
    {
136
        return $this->nodes[$index];
137
    }
138
139
    /**
140
     * @return Builder
141
     * @throws Builder\Exception
142
     */
143
    public function viceVersa() : Builder
144
    {
145
        if (($this->lastOperation !== self::OPERATION_ADD_CONNECTION) || is_null($this->lastConnection)) {
146
            throw new Builder\Exception('To which connection, hm?');
147
        }
148
149
        $lastConnection = $this->lastConnection;
150
151
        $this->addConnection(new Connection($lastConnection->to, $lastConnection->from, $lastConnection->weight));
152
153
        $this->lastOperation = self::OPERATION_NO_OPERATION;
154
155
        $this->lastConnection = null;
156
157
        return $this;
158
    }
159
}
160