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/Time.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\Util\Util;
6
use ValueObjects\ValueObjectInterface;
7
8
class Time implements ValueObjectInterface
9
{
10
    /** @var Hour */
11
    protected $hour;
12
13
    /** @var Minute */
14
    protected $minute;
15
16
    /** @var Second */
17
    protected $second;
18
19
    /**
20
     * Returns a nee Time object from native int hour, minute and second
21
     *
22
     * @param  int  $hour
0 ignored issues
show
There is no parameter named $hour. 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...
23
     * @param  int  $minute
0 ignored issues
show
There is no parameter named $minute. 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  int  $second
0 ignored issues
show
There is no parameter named $second. 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
     * @return self
26
     */
27 6
    public static function fromNative()
28
    {
29 6
        $args = func_get_args();
30
31 6
        $hour   = new Hour($args[0]);
32 6
        $minute = new Minute($args[1]);
33 6
        $second = new Second($args[2]);
34
35 6
        return new static($hour, $minute, $second);
36
    }
37
38
    /**
39
     * Returns a new Time from a native PHP \DateTime
40
     *
41
     * @param  \DateTime $time
42
     * @return self
43
     */
44 3
    public static function fromNativeDateTime(\DateTime $time)
45
    {
46 3
        $hour   = \intval($time->format('G'));
47 3
        $minute = \intval($time->format('i'));
48 3
        $second = \intval($time->format('s'));
49
50 3
        return static::fromNative($hour, $minute, $second);
51
    }
52
53
    /**
54
     * Returns current Time
55
     *
56
     * @return self
57
     */
58 3
    public static function now()
59
    {
60 3
        $time = new static(Hour::now(), Minute::now(), Second::now());
61
62 3
        return $time;
63
    }
64
65
    /**
66
     * Return zero time
67
     *
68
     * @return static
69
     */
70 2
    public static function zero()
71
    {
72 2
        $time = new static(new Hour(0), new Minute(0), new Second(0));
73
74 2
        return $time;
75
    }
76
77
    /**
78
     * Returns a new Time objects
79
     *
80
     * @param Hour   $hour
81
     * @param Minute $minute
82
     * @param Second $second
83
     */
84 28
    public function __construct(Hour $hour, Minute $minute, Second $second)
85
    {
86 28
        $this->hour   = $hour;
87 28
        $this->minute = $minute;
88 28
        $this->second = $second;
89 28
    }
90
91
    /**
92
     * Tells whether two Time are equal by comparing their values
93
     *
94
     * @param  ValueObjectInterface $time
95
     * @return bool
96
     */
97 13
    public function sameValueAs(ValueObjectInterface $time)
98
    {
99 13
        if (false === Util::classEquals($this, $time)) {
100 1
            return false;
101
        }
102
103 13
        return $this->getHour()->sameValueAs($time->getHour()) && $this->getMinute()->sameValueAs($time->getMinute()) && $this->getSecond()->sameValueAs($time->getSecond());
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getHour() does only exist in the following implementations of said interface: ValueObjects\DateTime\Time.

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...
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getMinute() does only exist in the following implementations of said interface: ValueObjects\DateTime\Time.

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...
It seems like you code against a concrete implementation and not the interface ValueObjects\ValueObjectInterface as the method getSecond() does only exist in the following implementations of said interface: ValueObjects\DateTime\Time.

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...
104
    }
105
106
    /**
107
     * Get hour
108
     *
109
     * @return Hour
110
     */
111 24
    public function getHour()
112
    {
113 24
        return $this->hour;
114
    }
115
116
    /**
117
     * Get minute
118
     *
119
     * @return Minute
120
     */
121 24
    public function getMinute()
122
    {
123 24
        return $this->minute;
124
    }
125
126
    /**
127
     * Get second
128
     *
129
     * @return Second
130
     */
131 24
    public function getSecond()
132
    {
133 24
        return $this->second;
134
    }
135
136
    /**
137
     * Returns a native PHP \DateTime version of the current Time.
138
     * Date is set to current.
139
     *
140
     * @return \DateTime
141
     */
142 8
    public function toNativeDateTime()
143
    {
144 8
        $hour   = $this->getHour()->toNative();
145 8
        $minute = $this->getMinute()->toNative();
146 8
        $second = $this->getSecond()->toNative();
147
148 8
        $time = new \DateTime('now');
149 8
        $time->setTime($hour, $minute, $second);
150
151 8
        return $time;
152
    }
153
154
    /**
155
     * Returns time as string in format G:i:s
156
     *
157
     * @return string
158
     */
159 7
    public function __toString()
160
    {
161 7
        return $this->toNativeDateTime()->format('G:i:s');
162
    }
163
}
164