Issues (14)

Security Analysis    not enabled

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.

SMS/StorableSender.php (5 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 DoS\SMSBundle\SMS;
4
5
use DoS\SMSBundle\Provider\RecordProvider;
6
use SmsSender\DelayedSenderInterface;
7
use SmsSender\SmsSender;
8
use SmsSender\SmsSenderInterface;
9
10
class StorableSender implements DelayedSenderInterface
11
{
12
    /**
13
     * @var RecordProvider
14
     */
15
    protected $recordProvider;
16
17
    /**
18
     * @var SmsSenderInterface
19
     */
20
    protected $sender;
21
22
    /**
23
     * @var Logger
24
     */
25
    protected $logger;
26
27
    public function __construct(RecordProvider $recordProvider, SmsSender $sender, Logger $logger = null)
28
    {
29
        $this->recordProvider = $recordProvider;
30
        $this->sender = $sender;
31
        $this->logger = $logger;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function flush()
38
    {
39
        if ($this->sender instanceof DelayedSenderInterface) {
40
            list($sentMessages, $errors) = $this->sender->flush();
0 ignored issues
show
The assignment to $sentMessages is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
41
42
            foreach ($errors as $error) {
43
                $this->logger->logError($error, $this->getProviderClass());
44
            }
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function send($recipient, $body, $originator = '')
52
    {
53
        $this->activateProvider();
54
55
        if ($this->logger) {
56
            $time = microtime(true);
57
            $result = $this->sender->send($recipient, $body, $originator);
58
            $duration = microtime(true) - $time;
59
60
            $this->logger->logMessage($result, $duration, $this->getProviderClass());
61
        } else {
62
            $result = $this->sender->send($recipient, $body, $originator);
63
        }
64
65
        $this->recordProvider->storeResult($result);
66
67
        return $result;
68
    }
69
70
    /**
71
     * Activate default provider.
72
     */
73
    public function activateProvider()
74
    {
75
        $provider = $this->recordProvider->getProvider()->getActivedProvider();
76
        $this->using($provider->getName());
77
    }
78
79
    /**
80
     * @param $name
81
     *
82
     * @return $this
83
     */
84
    public function using($name)
85
    {
86
        $this->sender->using($name);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SmsSender\SmsSenderInterface as the method using() does only exist in the following implementations of said interface: DoS\SMSBundle\SMS\StorableSender, SmsSender\SmsSender.

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...
87
88
        $pvd = $this->recordProvider->getProvider()->findByName($name);
89
        $provider = $this->sender->getProvider();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.

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...
90
91
        if ($provider instanceof ProviderInterface && $pvd) {
92
            $provider->applyOptions($pvd->getParameters());
93
        }
94
95
        return $this;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function acceptCallback($provider, array $response)
102
    {
103
        $provider = $this->using($provider)->sender->getProvider();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.

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
        if ($provider instanceof ProviderInterface) {
106
            $provider->processCallback($response);
107
            $provider->accept($this->recordProvider);
108
        }
109
    }
110
111
    /**
112
     * Allows to proxy method calls to the real SMS sender.
113
     *
114
     * @param $name
115
     * @param $arguments
116
     *
117
     * @return StorableSender|SmsSenderInterface
118
     */
119
    public function __call($name, $arguments)
120
    {
121
        if (is_callable(array($this->sender, $name))) {
122
            $result = call_user_func_array(array($this->sender, $name), $arguments);
123
124
            // don't break fluid interfaces
125
            return $result instanceof SmsSenderInterface ? $this : $result;
126
        }
127
    }
128
129
    /**
130
     * @return null|string
131
     */
132
    protected function getProviderClass()
133
    {
134
        return ($provider = $this->sender->getProvider()) ? get_class($provider) : null;
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.

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...
135
    }
136
}
137