Issues (115)

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/DateTime/Date.php (6 issues)

Labels
Severity

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 ValueObjects\DateTime;
4
5
use ValueObjects\DateTime\Exception\InvalidDateException;
6
use ValueObjects\Util\Util;
7
use ValueObjects\ValueObjectInterface;
8
9
class Date implements ValueObjectInterface
10
{
11
    /** @var Year */
12
    protected $year;
13
14
    /** @var Month */
15
    protected $month;
16
17
    /** @var MonthDay */
18
    protected $day;
19
20
    /**
21
     * Returns a new Date from native year, month and day values
22
     *
23
     * @param  int    $year
0 ignored issues
show
There is no parameter named $year. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
24
     * @param  string $month
0 ignored issues
show
There is no parameter named $month. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
25
     * @param  int    $day
0 ignored issues
show
There is no parameter named $day. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
     * @return Date
27
     */
28 3
    public static function fromNative()
29
    {
30 3
        $args = func_get_args();
31
32 3
        $year  = new Year($args[0]);
33 3
        $month = Month::fromNative($args[1]);
34 3
        $day   = new MonthDay($args[2]);
35
36 3
        return new static($year, $month, $day);
37
    }
38
39
    /**
40
     * Returns a new Date from a native PHP \DateTime
41
     *
42
     * @param  \DateTime $date
43
     * @return Date
44
     */
45 3
    public static function fromNativeDateTime(\DateTime $date)
46
    {
47 3
        $year  = \intval($date->format('Y'));
48 3
        $month = Month::fromNativeDateTime($date);
49 3
        $day   = \intval($date->format('d'));
50
51 3
        return new static(new Year($year), $month, new MonthDay($day));
52
    }
53
54
    /**
55
     * Returns current Date
56
     *
57
     * @return Date
58
     */
59 3
    public static function now()
60
    {
61 3
        $date = new static(Year::now(), Month::now(), MonthDay::now());
62
63 3
        return $date;
64
    }
65
66
    /**
67
     * Create a new Date
68
     *
69
     * @param  Year                 $year
70
     * @param  Month                $month
71
     * @param  MonthDay             $day
72
     * @throws InvalidDateException
73
     */
74 28
    public function __construct(Year $year, Month $month, MonthDay $day)
75
    {
76 28
        \DateTime::createFromFormat('Y-F-j', \sprintf('%d-%s-%d', $year->toNative(), $month, $day->toNative()));
77 28
        $nativeDateErrors = \DateTime::getLastErrors();
78
79 28
        if ($nativeDateErrors['warning_count'] > 0 || $nativeDateErrors['error_count'] > 0) {
80 1
            throw new InvalidDateException($year->toNative(), $month->toNative(), $day->toNative());
81
        }
82
83 27
        $this->year  = $year;
84 27
        $this->month = $month;
85 27
        $this->day   = $day;
86 27
    }
87
88
    /**
89
     * Tells whether two Date are equal by comparing their values
90
     *
91
     * @param  ValueObjectInterface $date
92
     * @return bool
93
     */
94 12
    public function sameValueAs(ValueObjectInterface $date)
95
    {
96 12
        if (false === Util::classEquals($this, $date)) {
97 1
            return false;
98
        }
99
100 12
        return $this->getYear()->sameValueAs($date->getYear()) &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getYear() does only exist in the following implementations of said interface: ValueObjects\DateTime\Date.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
101 12
               $this->getMonth()->sameValueAs($date->getMonth()) &&
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getMonth() does only exist in the following implementations of said interface: ValueObjects\DateTime\Date.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
102 12
               $this->getDay()->sameValueAs($date->getDay());
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getDay() does only exist in the following implementations of said interface: ValueObjects\DateTime\Date.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
103
    }
104
105
    /**
106
     * Get year
107
     *
108
     * @return Year
109
     */
110 22
    public function getYear()
111
    {
112 22
        return clone $this->year;
113
    }
114
115
    /**
116
     * Get month
117
     *
118
     * @return Month
119
     */
120 22
    public function getMonth()
121
    {
122 22
        return $this->month;
123
    }
124
125
    /**
126
     * Get day
127
     *
128
     * @return MonthDay
129
     */
130 22
    public function getDay()
131
    {
132 22
        return clone $this->day;
133
    }
134
135
    /**
136
     * Returns a native PHP \DateTime version of the current Date
137
     *
138
     * @return \DateTime
139
     */
140 7
    public function toNativeDateTime()
141
    {
142 7
        $year  = $this->getYear()->toNative();
143 7
        $month = $this->getMonth()->getNumericValue();
144 7
        $day   = $this->getDay()->toNative();
145
146 7
        $date = new \DateTime();
147 7
        $date->setDate($year, $month, $day);
148 7
        $date->setTime(0, 0, 0);
149
150 7
        return $date;
151
    }
152
153
    /**
154
     * Returns date as string in format Y-n-j
155
     *
156
     * @return string
157
     */
158 6
    public function __toString()
159
    {
160 6
        return $this->toNativeDateTime()->format('Y-n-j');
161
    }
162
}
163