Issues (32)

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.

api/Controllers/EmojiController.php (11 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
/**
4
 * Emojinaija is a rest API service that provide access to
5
 * unlimited emoji images
6
 *
7
 * @package Ibonly\NaijaEmoji\EmojiController
8
 * @author  Ibraheem ADENIYI <[email protected]>
9
 * @license MIT <https://opensource.org/licenses/MIT>
10
 */
11
12
namespace Ibonly\NaijaEmoji;
13
14
use Slim\Slim;
15
use Ibonly\NaijaEmoji\Emoji;
16
use Firebase\JWT\ExpiredException;
17
use Ibonly\NaijaEmoji\EmojiInterface;
18
use Ibonly\NaijaEmoji\AuthController;
19
use Ibonly\PotatoORM\DataNotFoundException;
20
use Ibonly\PotatoORM\EmptyDatabaseException;
21
use Ibonly\NaijaEmoji\ProvideTokenException;
22
use Ibonly\NaijaEmoji\InvalidTokenException;
23
use Ibonly\PotatoORM\DataAlreadyExistException;
24
25
class EmojiController implements EmojiInterface
26
{
27
    protected $dataName;
28
    protected $auth;
29
30
    public function __construct ()
31
    {
32
        $this->dataName = new Emoji();
33
        $this->auth = new AuthController();
34
    }
35
36
    /**
37
     * getAllEmoji Get all the emoji's available
38
     *
39
     * @param  $app
40
     *
41
     * @return json
42
     */
43 View Code Duplication
    public function getAllEmoji (Slim $app)
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...
44
    {
45
        $app->response->headers->set('Content-Type', 'application/json');
46
        try
47
        {
48
            $data = $this->dataName->getAll()->toJson();
49
            $newData = json_decode($data);
50
            foreach ( $newData as $key ) {
51
                $key->keywords = explode(", ", $key->keywords);
52
            }
53
            return json_encode($newData);
54
        } catch ( EmptyDatabaseException $e ) {
55
            $app->halt(204, json_encode(['Message' => 'No content']));
56
        }
57
    }
58
59
    /**
60
     * findEmoji Find a particular emoji
61
     *
62
     * @param  $id
63
     * @param  $app
64
     *
65
     * @return json
66
     */
67 View Code Duplication
    public function findEmoji ($id, Slim $app)
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...
68
    {
69
        $app->response->headers->set('Content-Type', 'application/json');
70
        try
71
        {
72
            $data =  $this->dataName->where(['id' => $id])->toJson();
73
            $newData = json_decode($data);
74
            foreach ( $newData as $key ) {
75
                $key->keywords = explode(", ", $key->keywords);
76
            }
77
            return json_encode($newData);
78
        } catch ( DataNotFoundException $e ) {
79
            $app->halt(404, json_encode(['Message' => 'Not Found']));
80
        }
81
    }
82
83
    /**
84
     * insertEmoji Insert new emoji
85
     *
86
     * @param  $app
87
     *
88
     * @return json
89
     */
90
    public function insertEmoji (Slim $app)
91
    {
92
        $app->response->headers->set('Content-Type', 'application/json');
93
        $tokenData = $app->request->headers->get('Authorization');
94
        try
95
        {
96
            if ( ! isset( $tokenData ) )
97
                throw new ProvideTokenException();
98
99
            $data = $this->auth->authorizationDecode($tokenData);
100
            $this->dataName->id = NULL;
0 ignored issues
show
The property id does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
101
            $this->dataName->name = $app->request->params('name');
0 ignored issues
show
The property name does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
102
            $this->dataName->char = $app->request->params('char');
0 ignored issues
show
The property char does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
103
            $this->dataName->keywords = $app->request->params('keywords');
0 ignored issues
show
The property keywords does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
104
            $this->dataName->category = $app->request->params('category');
0 ignored issues
show
The property category does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
105
            $this->dataName->date_created = date('Y-m-d G:i:s');
0 ignored issues
show
The property date_created does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
106
            $this->dataName->date_modified = date('Y-m-d G:i:s');
0 ignored issues
show
The property date_modified does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
107
            $this->dataName->created_by = $data->user;
0 ignored issues
show
The property created_by does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
109
            $save = $this->dataName->save();
110
            if ( $save )
111
                $app->halt(200, json_encode(['Message' => 'Success']));
112
        } catch ( ExpiredException $e ) {
113
            $app->halt(401, json_encode(['Message' => 'Token has expired']));
114
        } catch ( DataAlreadyExistException $e ) {
115
            $app->halt(202, json_encode(['Message' => 'Not Created']));
116
        } catch ( InvalidTokenException $e ) {
117
            $app->halt(405, json_encode(['Message' => 'Invalid Token']));
118
        } catch ( ProvideTokenException $e ) {
119
            $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
120
        }
121
    }
122
123
    /**
124
     * updateEmoji update emoji details
125
     *
126
     * @param  $id
127
     * @param  $app
128
     *
129
     * @return json
130
     */
131
    public function updateEmoji ($id, Slim $app)
132
    {
133
        $app->response->headers->set('Content-Type', 'application/json');
134
        $tokenData = $app->request->headers->get('Authorization');
135
        try
136
        {
137
            if ( ! isset($tokenData) )
138
                throw new ProvideTokenException();
139
140
            $find = Emoji::find($id);
141
            $this->auth->authorizationDecode($tokenData);
142
            $fields = $app->request->isPut() ? $app->request->put() : $app->request->patch();
143
            foreach ( $fields as $key => $value )
144
            {
145
                $find->$key = $value;
146
            }
147
            $find->date_modified = date('Y-m-d G:i:s');
0 ignored issues
show
The property date_modified does not seem to exist in Ibonly\NaijaEmoji\Emoji.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
148
            $update = $find->update();
149
            if( $update )
150
                $app->halt(200, json_encode(['Message' => 'Emoji Updated Successfully']));
151
        } catch ( ExpiredException $e ) {
152
            $app->halt(401, json_encode(['Message' => 'Token has expired']));
153
        } catch ( DataNotFoundException $e ) {
154
            $app->halt(303, json_encode(['Message' => 'Invalid Credential supplied']));
155
        } catch ( InvalidTokenException $e ) {
156
            $app->halt(405, json_encode(['Message' => 'Invalid Token']));
157
        } catch ( ProvideTokenException $e ) {
158
            $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
159
        }
160
    }
161
162
    /**
163
     * deleteEmoji Delete already existing emoji
164
     *
165
     * @param  $id
166
     * @param  $app
167
     *
168
     * @return json
169
     */
170
    public function deleteEmoji ($id, Slim $app)
171
    {
172
        $app->response->headers->set('Content-Type', 'application/json');
173
        $tokenData = $app->request->headers->get('Authorization');
174
        try
175
        {
176
            if ( ! isset( $tokenData ) )
177
                throw new ProvideTokenException();
178
179
            $this->auth->authorizationDecode($tokenData);
180
            $deleted = $this->dataName->destroy($id);
181
            if ( $deleted )
182
                $app->halt(200, json_encode(['Message' => 'Emoji Deleted']));
183
        } catch ( ExpiredException $e ) {
184
            $app->halt(401, json_encode(['Message' => 'Token has expired']));
185
        } catch ( InvalidTokenException $e ) {
186
            $app->halt(405, json_encode(['Message' => 'Invalid Token']));
187
        } catch ( ProvideTokenException $e ) {
188
            $app->halt(406, json_encode(['Message' => 'Enter a valid Token']));
189
        } catch ( DataNotFoundException $e ) {
190
            $app->halt(401, json_encode(['Message' => 'Emoji not found']));
191
        }
192
    }
193
}