Issues (3)

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/UrbanWordsManager.php (1 issue)

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 John\Cp;
4
5
use John\Exceptions\UrbanWordException;
6
use John\Exceptions\WordManagerException;
7
8
/**
9
 * Class handles the CRUD methods on the static $data array defined in UrbanWordsDataStore class
10
 * Class UrbanWordsManager.
11
 */
12
class UrbanWordsManager
13
{
14
    private $words;
15
    private $slang;
16
    private $desc;
17
    private $sentence;
18
19
    /**
20
     * UrbanWordsCRUD constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->words = UrbanWordsDataStore::$data;
25
    }
26
27
    /**
28
     * return Urban array of words from John\Cp\UrbanWords.
29
     *
30
     * @return array
31
     */
32
    public function getWords()
33
    {
34
        return $this->words;
35
    }
36
37
    /**
38
     * Add new word into the Urban Word dictionary
39
     *
40
     * @param string $slang
41
     * @param string $desc
42
     * @param string $sentence
43
     *
44
     * @return bool
45
     *
46
     * @throws \John\Exceptions\WordManagerException
47
     */
48
    public function addWord($slang = '', $desc = '', $sentence = '')
49
    {
50
        $this->slang = $slang;
51
        $this->desc = $desc;
52
        $this->sentence = $sentence;
53
54
        if (! empty($this->slang) && ! empty($this->desc) && ! empty($this->sentence)) {
55
56
            foreach ($this->words as $urbanWord) {
57
58
                if (strtolower($urbanWord['slang']) === strtolower($this->slang)) {
59
60
                    throw new WordManagerException('Urban word already exists.');
61
                }
62
            }
63
64
            $newWord = [
65
                'slang' => $this->slang,
66
                'description' => $this->desc,
67
                'sample-sentence' => $this->sentence,
68
            ];
69
70
            array_push($this->words, $newWord);
71
72
            return $newWord;
73
        }
74
75
        throw new WordManagerException('Urban word detail omitted.');
76
    }
77
78
    /**
79
     * Read words from the Urban Words Dictionary
80
     *
81
     * @param string $slang
82
     *
83
     * @return bool
84
     *
85
     * @throws \John\Exceptions\WordManagerException
86
     */
87
    public function readWord($slang = '')
88
    {
89
        $this->slang = $slang;
90
91
        $foundWord = [
92
            'success' => false,
93
            'key' => null,
94
        ];
95
96
        if (! empty($this->slang)) {
97
98
            foreach ($this->words as $urbanWordKey => $urbanWord) {
99
100
                if (strtolower($urbanWord['slang']) === strtolower($this->slang)) {
101
102
                    $foundWord['success'] = true;
103
                    $foundWord['key'] = $urbanWordKey;
104
105
                    break;
106
                }
107
            }
108
        } else {
109
110
            throw new WordManagerException('Urban word omitted.');
111
        }
112
113
        if ($foundWord['success']) {
114
115
            return [
116
                'word' =>  $this->words[$foundWord['key']],
117
                'position' => $foundWord['key']
118
            ];
119
        }
120
121
        throw new WordManagerException('Urban word not found in our data store.');
122
    }
123
124
    /**
125
     * Update slang Words in the Urban Dictionary
126
     *
127
     * @param string $slang
128
     * @param string $slangUpdate
129
     * @param string $descUpdate
130
     * @param string $sentenceUpdate
131
     *
132
     * @return mixed
133
     *
134
     * @throws \John\Exceptions\UrbanWordException
135
     */
136
    public function updateWord($slang = '', $slangUpdate = '', $descUpdate = '', $sentenceUpdate = '')
137
    {
138
        if (! empty($slangUpdate) && ! empty($descUpdate) && ! empty($sentenceUpdate)) {
139
140
            $this->slang = $slang;
141
            $wordKey = $this->readWord($this->slang);
142
143
            if ($wordKey) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $wordKey of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
144
145
                $position = $wordKey["position"];
146
147
                $this->words[$position]['slang'] = $slangUpdate;
148
                $this->words[$position]['description'] = $descUpdate;
149
                $this->words[$position]['sample-sentence'] = $sentenceUpdate;
150
151
                return $this->words[$position];
152
            }
153
        } else {
154
155
            throw new WordManagerException('Cannot Update: Urban word details omitted.');
156
        }
157
    }
158
159
    /**
160
     * Delete word from Urban dictionary
161
     *
162
     * @param string $slang
163
     *
164
     * @return bool
165
     *
166
     * @throws \John\Exceptions\UrbanWordException
167
     */
168
    public function deleteWord($slang = '')
169
    {
170
        $this->slang = $slang;
171
172
        $foundWord = [
173
            'success' => false,
174
            'key' => null,
175
            'urbanWord' => [],
176
        ];
177
178
        if (! empty($this->slang)) {
179
180
            foreach ($this->words as $urbanWordKey => $urbanWord) {
181
182
                if (strtolower($urbanWord['slang']) === strtolower($this->slang)) {
183
184
                    $foundWord['success'] = true;
185
                    $foundWord['key'] = $urbanWordKey;
186
                    $foundWord['urbanWord'] = $this->words[$urbanWordKey];
187
188
                    break;
189
                }
190
            }
191
        } else {
192
193
            throw new WordManagerException('Urban word omitted.');
194
        }
195
196
        if ($foundWord['success']) {
197
198
            unset($this->words[$foundWord['key']]);
199
200
            return $foundWord['urbanWord'];
201
        }
202
        throw new WordManagerException('Urban word not found in our data store.');
203
    }
204
}
205