Issues (36)

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/SmsManager.php (2 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 Tzsk\Sms;
4
5
use Exception;
6
use ReflectionClass;
7
8
class SmsManager
9
{
10
    /**
11
     * Sms Configuration.
12
     *
13
     * @var array
14
     */
15
    protected $config;
16
17
    /**
18
     * Sms Driver Settings.
19
     *
20
     * @var array
21
     */
22
    protected $settings;
23
24
    /**
25
     * Sms Driver Name.
26
     *
27
     * @var string
28
     */
29
    protected $driver;
30
31
    /**
32
     * @var SmsBuilder
33
     */
34
    protected $builder;
35
36
    /**
37
     * SmsManager constructor.
38
     *
39
     * @param array $config
40
     */
41
    public function __construct($config)
42
    {
43
        $this->config = $config;
44
        $this->setBuilder(new SmsBuilder());
45
        $this->via($this->config['default']);
46
    }
47
48
    /**
49
     * @param string|array $recipients
50
     * @return self
51
     */
52
    public function to($recipients)
53
    {
54
        $this->builder->to($recipients);
55
56
        return $this;
57
    }
58
59
    /**
60
     * Change the driver on the fly.
61
     *
62
     * @param $driver
63
     * @return $this
64
     * @throws \Exception
65
     */
66 View Code Duplication
    public function via($driver)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $this->driver = $driver;
69
        $this->validateDriver();
70
        $this->builder->via($driver);
71
        $this->settings = $this->config['drivers'][$driver];
72
73
        return $this;
74
    }
75
76
    /**
77
     * Send message.
78
     *
79
     * @param $message
80
     * @param $callback
81
     * @return mixed
82
     * @throws \Exception
83
     */
84
    public function send($message, $callback = null)
85
    {
86
        if ($message instanceof SmsBuilder) {
87
            return $this->setBuilder($message)->dispatch();
88
        }
89
90
        $this->builder->send($message);
91
        if (! $callback) {
92
            return $this;
93
        }
94
95
        $driver = $this->getDriverInstance();
96
        $driver->message($message);
97
        call_user_func($callback, $driver);
98
99
        return $driver->send();
100
    }
101
102
    /**
103
     * @return mixed
104
     */
105
    public function dispatch()
106
    {
107
        $this->driver = $this->builder->getDriver() ?: $this->driver;
108
        if (empty($this->driver)) {
109
            $this->via($this->config['default']);
110
        }
111
        $driver = $this->getDriverInstance();
112
        $driver->message($this->builder->getBody());
113
        $driver->to($this->builder->getRecipients());
114
115
        return $driver->send();
116
    }
117
118
    /**
119
     * @param SmsBuilder $builder
120
     * @return self
121
     */
122
    protected function setBuilder(SmsBuilder $builder)
123
    {
124
        $this->builder = $builder;
125
126
        return $this;
127
    }
128
129
    /**
130
     * Generate driver instance.
131
     *
132
     * @return mixed
133
     */
134 View Code Duplication
    protected function getDriverInstance()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
    {
136
        $this->validateDriver();
137
        $class = $this->config['map'][$this->driver];
138
139
        return new $class($this->settings);
140
    }
141
142
    /**
143
     * Validate Parameters before sending.
144
     *
145
     * @throws \Exception
146
     */
147
    protected function validateDriver()
148
    {
149
        $conditions = [
150
            'Driver not selected or default driver does not exist.' => empty($this->driver),
151
            'Driver not found in config file. Try updating the package.' => empty($this->config['drivers'][$this->driver]) || empty($this->config['map'][$this->driver]),
152
            'Driver source not found. Please update the package.' => ! class_exists($this->config['map'][$this->driver]),
153
            'Driver must be an instance of Contracts\DriverInterface.' => ! (new ReflectionClass($this->config['map'][$this->driver]))->implementsInterface(Contracts\DriverInterface::class),
154
        ];
155
156
        foreach ($conditions as $ex => $condition) {
157
            throw_if($condition, new Exception($ex));
158
        }
159
    }
160
}
161