Issues (11)

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/Tags/Url.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
3
namespace Spatie\Sitemap\Tags;
4
5
use Carbon\Carbon;
6
use DateTime;
7
8
class Url extends Tag
9
{
10
    const CHANGE_FREQUENCY_ALWAYS = 'always';
11
    const CHANGE_FREQUENCY_HOURLY = 'hourly';
12
    const CHANGE_FREQUENCY_DAILY = 'daily';
13
    const CHANGE_FREQUENCY_WEEKLY = 'weekly';
14
    const CHANGE_FREQUENCY_MONTHLY = 'monthly';
15
    const CHANGE_FREQUENCY_YEARLY = 'yearly';
16
    const CHANGE_FREQUENCY_NEVER = 'never';
17
18
    /** @var string */
19
    public $url = '';
20
21
    /** @var \Carbon\Carbon */
22
    public $lastModificationDate;
23
24
    /** @var string */
25
    public $changeFrequency;
26
27
    /** @var float */
28
    public $priority = 0.8;
29
30
    /** @var array */
31
    public $alternates = [];
32
33
    public static function create(string $url): self
34
    {
35
        return new static($url);
36
    }
37
38
    public function __construct(string $url)
39
    {
40
        $this->url = $url;
41
42
        $this->lastModificationDate = Carbon::now();
43
44
        $this->changeFrequency = static::CHANGE_FREQUENCY_DAILY;
45
    }
46
47
    /**
48
     * @param string $url
49
     *
50
     * @return $this
51
     */
52
    public function setUrl(string $url = '')
53
    {
54
        $this->url = $url;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @param \DateTime $lastModificationDate
61
     *
62
     * @return $this
63
     */
64
    public function setLastModificationDate(DateTime $lastModificationDate)
65
    {
66
        $this->lastModificationDate = $lastModificationDate;
0 ignored issues
show
Documentation Bug introduced by
$lastModificationDate is of type object<DateTime>, but the property $lastModificationDate was declared to be of type object<Carbon\Carbon>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param string $changeFrequency
73
     *
74
     * @return $this
75
     */
76
    public function setChangeFrequency(string $changeFrequency)
77
    {
78
        $this->changeFrequency = $changeFrequency;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param float $priority
85
     *
86
     * @return $this
87
     */
88
    public function setPriority(float $priority)
89
    {
90
        $this->priority = max(0, min(1, $priority));
91
92
        return $this;
93
    }
94
95
    /**
96
     * @param Alternate $alternate
97
     *
98
     * @param string $url
99
     * @param string $locale
100
     * @return $this
101
     */
102
    public function addAlternate(string $url, string $locale = '')
103
    {
104
        $this->alternates[] = new Alternate($url, $locale);
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function path(): string
113
    {
114
        return parse_url($this->url)['path'] ?? '';
115
    }
116
117
    /**
118
     * @param int|null $index
119
     *
120
     * @return array|null|string
121
     */
122
    public function segments(int $index = null)
123
    {
124
        $segments = collect(explode('/', $this->path()))
125
            ->filter(function ($value) {
126
                return $value !== '';
127
            })
128
            ->values()
129
            ->toArray();
130
131
        if (! is_null($index)) {
132
            return $this->segment($index);
133
        }
134
135
        return $segments;
136
    }
137
138
    /**
139
     * @param int $index
140
     *
141
     * @return string|null
142
     */
143
    public function segment(int $index)
144
    {
145
        return $this->segments()[$index - 1] ?? null;
146
    }
147
}
148