Issues (71)

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/Service/UserService.php (7 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
namespace OmnideskBundle\Service;
3
4
use GuzzleHttp\Exception\ClientException;
5
use OmnideskBundle\Exception\UserAlreadyExistException;
6
use OmnideskBundle\Exception\UserWrongEmailException;
7
use OmnideskBundle\Factory\User\UserConfigurationFactory;
8
use OmnideskBundle\Factory\User\UserDataTransformerFactory;
9
use OmnideskBundle\Request\User\AddUserRequest;
10
use OmnideskBundle\Request\User\EditUserRequest;
11
use OmnideskBundle\Request\User\ListUserRequest;
12
use OmnideskBundle\Request\User\ViewUserRequest;
13
use OmnideskBundle\Response\User\ListUserResponse;
14
use OmnideskBundle\Response\User\UserResponse;
15
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
16
17
/**
18
 * Class UserService
19
 * @package OmnideskBundle\Service
20
 */
21
class UserService extends AbstractService
22
{
23
    /**
24
     * @var RequestService
25
     */
26
    protected $requestService;
27
28
    /**
29
     * @var UserDataTransformerFactory
30
     */
31
    protected $transformerFactory;
32
33
    /**
34
     * @var UserConfigurationFactory
35
     */
36
    protected $configurationFactory;
37
38
    /**
39
     * UserService constructor.
40
     * @param RequestService              $requestService
41
     * @param UserDataTransformerFactory $transformerFactory
42
     * @param UserConfigurationFactory   $configurationFactory
43
     */
44
    public function __construct(
45
        RequestService $requestService,
46
        UserDataTransformerFactory $transformerFactory,
47
        UserConfigurationFactory $configurationFactory
48
    ) {
49
        $this->requestService = $requestService;
50
        $this->transformerFactory = $transformerFactory;
51
        $this->configurationFactory = $configurationFactory;
52
    }
53
54
    /**
55
     * @param AddUserRequest $request
56
     * @return UserResponse
57
     * @throws UserAlreadyExistException
58
     * @throws UserWrongEmailException
59
     */
60
    public function add(AddUserRequest $request)
61
    {
62
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_ADD);
63
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_ADD);
64
65
        try {
66
            $params = $this->checkRequest($request, $transformer, $configuration);
67
        } catch (InvalidConfigurationException $exception) {
68
            throw new InvalidConfigurationException($exception->getMessage());
69
        }
70
71
        try {
72
            $result = $this->requestService->post('users', ['user' => $params]);
73
        } catch (ClientException $exception) {
74
            $contents = json_decode($exception->getResponse()->getBody(), JSON_UNESCAPED_UNICODE);
75
76
            switch ($contents['error']) {
77
                case UserResponse::ERROR_EMAIL_ALREADY_EXIST:
78
                    throw new UserAlreadyExistException();
79
                case UserResponse::ERROR_PHONE_ALREADY_EXIST:
80
                    throw new UserAlreadyExistException();
81
                case UserResponse::ERROR_WRONG_EMAIL:
82
                    throw new UserWrongEmailException();
83
            }
84
85
            throw $exception;
86
        }
87
88
89
90
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
91
    }
92
93
    /**
94
     * @param EditUserRequest $request
95
     * @return UserResponse
96
     */
97 View Code Duplication
    public function edit(EditUserRequest $request)
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...
98
    {
99
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_EDIT);
100
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_EDIT);
101
102
        try {
103
            $params = $this->checkRequest($request, $transformer, $configuration);
104
        } catch (InvalidConfigurationException $exception) {
105
            throw new InvalidConfigurationException($exception->getMessage());
106
        }
107
108
        $result = $this->requestService->put("users/{$params['user_id']}", ['user' => $params]);
109
110
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
111
    }
112
113
    /**
114
     * @param ListUserRequest $request
115
     * @return ListUserResponse
116
     */
117 View Code Duplication
    public function lists(ListUserRequest $request)
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...
118
    {
119
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_LIST);
120
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_LIST);
121
122
        try {
123
            $params = $this->checkRequest($request, $transformer, $configuration);
124
        } catch (InvalidConfigurationException $exception) {
125
            throw new InvalidConfigurationException($exception->getMessage());
126
        }
127
128
        $result = $this->requestService->get('users', $params);
129
130
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_LIST)->transform($result);
131
    }
132
133
    /**
134
     * @param ViewUserRequest $request
135
     * @return UserResponse
136
     */
137 View Code Duplication
    public function view(ViewUserRequest $request)
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...
138
    {
139
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_VIEW);
140
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_VIEW);
141
142
        try {
143
            $params = $this->checkRequest($request, $transformer, $configuration);
144
        } catch (InvalidConfigurationException $exception) {
145
            throw new InvalidConfigurationException($exception->getMessage());
146
        }
147
148
        $result = $this->requestService->get("users/{$params['user_id']}");
149
150
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
151
    }
152
153
    /**
154
     * @param ViewUserRequest $request
155
     * @return UserResponse
156
     */
157 View Code Duplication
    public function block(ViewUserRequest $request)
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...
158
    {
159
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_VIEW);
160
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_VIEW);
161
162
        try {
163
            $params = $this->checkRequest($request, $transformer, $configuration);
164
        } catch (InvalidConfigurationException $exception) {
165
            throw new InvalidConfigurationException($exception->getMessage());
166
        }
167
168
        $result = $this->requestService->put("users/{$params['user_id']}/block");
169
170
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
171
    }
172
173
    /**
174
     * @param ViewUserRequest $request
175
     * @return UserResponse
176
     */
177 View Code Duplication
    public function restore(ViewUserRequest $request)
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...
178
    {
179
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_VIEW);
180
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_VIEW);
181
182
        try {
183
            $params = $this->checkRequest($request, $transformer, $configuration);
184
        } catch (InvalidConfigurationException $exception) {
185
            throw new InvalidConfigurationException($exception->getMessage());
186
        }
187
188
        $result = $this->requestService->put("users/{$params['user_id']}/restore");
189
190
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
191
    }
192
193
    /**
194
     * @param ViewUserRequest $request
195
     * @return UserResponse
196
     */
197 View Code Duplication
    public function disable(ViewUserRequest $request)
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...
198
    {
199
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_VIEW);
200
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_VIEW);
201
202
        try {
203
            $params = $this->checkRequest($request, $transformer, $configuration);
204
        } catch (InvalidConfigurationException $exception) {
205
            throw new InvalidConfigurationException($exception->getMessage());
206
        }
207
208
        $result = $this->requestService->put("users/{$params['user_id']}/disable");
209
210
        return $this->transformerFactory->get(UserDataTransformerFactory::RESPONSE_VIEW)->transform($result);
211
    }
212
213
    /**
214
     * @param ViewUserRequest $request
215
     */
216 View Code Duplication
    public function delete(ViewUserRequest $request)
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...
217
    {
218
        $transformer = $this->transformerFactory->get(UserDataTransformerFactory::REQUEST_VIEW);
219
        $configuration = $this->configurationFactory->get(UserConfigurationFactory::CONFIGURATION_VIEW);
220
221
        try {
222
            $params = $this->checkRequest($request, $transformer, $configuration);
223
        } catch (InvalidConfigurationException $exception) {
224
            throw new InvalidConfigurationException($exception->getMessage());
225
        }
226
227
        $this->requestService->delete("users/{$params['user_id']}");
228
    }
229
}
230