Issues (1)

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/Service/SitemapResourceBuilder.php (1 issue)

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
namespace DL\SitemapBundle\Service;
5
6
use DL\SitemapBundle\Definition\SitemapResource;
7
8
/**
9
 * Handles the construction of sitemap resources.
10
 *
11
 * @package DL\SitemapBundle\Service
12
 * @author  Petre Pătrașc <[email protected]>
13
 */
14
class SitemapResourceBuilder
15
{
16
    /**
17
     * The title of the resource.
18
     *
19
     * @var string
20
     */
21
    protected $title;
22
23
    /**
24
     * The absolute URL of where the resource can be accessed.
25
     *
26
     * @var string
27
     */
28
    protected $location;
29
30
    /**
31
     * The date at which the resource was last modified.
32
     *
33
     * @var \DateTime
34
     */
35
    protected $lastModified;
36
37
    /**
38
     * The change frequency at which this resource is updated.
39
     *
40
     * @see ChangeFrequencyEnum
41
     * @var string
42
     */
43
    protected $changeFrequency;
44
45
    /**
46
     * The priority that this resource should be given within a sitemap.
47
     *
48
     * @var float
49
     */
50
    protected $priority;
51
52
    /**
53
     * @var SitemapResourceValidator
54
     */
55
    protected $validator;
56
57
    /**
58
     * The location prefix - used when creating resources
59
     * with relative locations.
60
     *
61
     * @var string
62
     */
63
    protected $locationPrefix;
64
65
    /**
66
     * SitemapResourceBuilder constructor.
67
     *
68
     * @param SitemapResourceValidator $validator
69
     * @param string                   $locationPrefix
70
     */
71 6
    public function __construct(SitemapResourceValidator $validator, string $locationPrefix)
72
    {
73 6
        $this->validator      = $validator;
74 6
        $this->locationPrefix = $locationPrefix;
75 6
        $this->clear();
76 6
    }
77
78
    /**
79
     * Clear all of the builder properties to ensure a default state
80
     * between multiple executions.
81
     */
82 6
    private function clear()
83
    {
84 6
        $this->title           = '';
85 6
        $this->location        = '';
86 6
        $this->lastModified    = null;
87 6
        $this->changeFrequency = '';
88 6
        $this->priority        = -1;
0 ignored issues
show
Documentation Bug introduced by
The property $priority was declared of type double, but -1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
89 6
    }
90
91
    /**
92
     * Build an instance of a sitemap resource and validate it.
93
     *
94
     * @return SitemapResource
95
     */
96 2
    public function build(): SitemapResource
97
    {
98 2
        $resource = new SitemapResource(
99 2
            $this->title,
100 2
            $this->location,
101 2
            $this->lastModified,
102 2
            $this->changeFrequency,
103 2
            $this->priority
104
        );
105
106 2
        $this->clear();
107 2
        $this->validator->validate($resource);
108
109 2
        return $resource;
110
    }
111
112
    /**
113
     * @param string $title
114
     *
115
     * @return SitemapResourceBuilder
116
     */
117 3
    public function withTitle(string $title): SitemapResourceBuilder
118
    {
119 3
        $this->title = $title;
120
121 3
        return $this;
122
    }
123
124
    /**
125
     * @param string $location
126
     *
127
     * @return SitemapResourceBuilder
128
     */
129 1
    public function withAbsoluteLocation(string $location): SitemapResourceBuilder
130
    {
131 1
        $this->location = $location;
132
133 1
        return $this;
134
    }
135
136
    /**
137
     * @param string $location
138
     *
139
     * @return SitemapResourceBuilder
140
     */
141 4
    public function withRelativeLocation(string $location): SitemapResourceBuilder
142
    {
143 4
        $this->location = $this->locationPrefix . $location;
144
145 4
        return $this;
146
    }
147
148
    /**
149
     * @param string $changeFrequency
150
     *
151
     * @return SitemapResourceBuilder
152
     */
153 3
    public function withChangeFrequency(string $changeFrequency): SitemapResourceBuilder
154
    {
155 3
        $this->changeFrequency = $changeFrequency;
156
157 3
        return $this;
158
    }
159
160
    /**
161
     * @param \DateTime $lastModified
162
     *
163
     * @return SitemapResourceBuilder
164
     */
165 3
    public function withLastModified(\DateTime $lastModified): SitemapResourceBuilder
166
    {
167 3
        $this->lastModified = $lastModified;
168
169 3
        return $this;
170
    }
171
172
    /**
173
     * @param float $priority
174
     *
175
     * @return SitemapResourceBuilder
176
     */
177 3
    public function withPriority(float $priority): SitemapResourceBuilder
178
    {
179 3
        $this->priority = $priority;
180
181 3
        return $this;
182
    }
183
}
184