Issues (5)

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.

AxalianAchievements/Service/AchievementService.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
 * AchievementService
4
 *
5
 * @category  AxalianAchievements\Service
6
 * @package   AxalianAchievements\Service
7
 * @author    Michel Maas <[email protected]>
8
 */
9
10
namespace AxalianAchievements\Service;
11
12
use AxalianAchievements\AchievementProvider\AchievementProviderInterface;
13
use AxalianAchievements\AchievementProvider\AchievementProviderPluginManager;
14
use AxalianAchievements\Entity\Achievement;
15
use AxalianAchievements\Entity\Category;
16
use AxalianAchievements\StorageAdapter\StorageAdapterInterface;
17
use AxalianAchievements\User\UserInterface;
18
19
class AchievementService
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $awardedAchievements = array();
25
26
    /**
27
     * @var array
28
     */
29
    protected $removedAchievements = array();
30
31
    /**
32
     * @var AchievementProviderPluginManager
33
     */
34
    protected $pluginManager;
35
36
    /**
37
     * @var StorageAdapterInterface
38
     */
39
    protected $storage;
40
41
    /**
42
     * @param AchievementProviderPluginManager $pluginManager
43
     * @param StorageAdapterInterface $storage
44
     */
45
    public function __construct(AchievementProviderPluginManager $pluginManager, StorageAdapterInterface $storage)
46
    {
47
        $this->setPluginManager($pluginManager);
48
        $this->setStorage($storage);
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getAchievements()
55
    {
56
        $result = array();
57
58
        foreach ($this->getProviders() as $provider) {
59
            $achievements = $provider->getAchievements();
60
61
            /* @var Achievement $achievement */
62
            foreach ($achievements as $achievement) {
63
                $result[$achievement->getID()] = $achievement;
64
            }
65
        }
66
67
        return $result;
68
    }
69
70
    /**
71
     *
72
     * @return array
73
     */
74
    public function getCategories()
75
    {
76
        $result = array();
77
78
        foreach ($this->getProviders() as $provider) {
79
            $categories = $provider->getCategories();
80
81
            /* @var Category $category */
82
            foreach ($categories as $category) {
83
                $result[$category->getID()] = $category;
84
            }
85
        }
86
87
        return $result;
88
    }
89
90
    /**
91
     * Retrieve an achievement by using its name
92
     *
93
     * @param string $achievementName Name of the achievement to look for
94
     * @return \AxalianAchievements\Entity\Achievement|null  The found achievement, or null of nothing found
95
     */
96
    public function getAchievementByName($achievementName)
97
    {
98
        /** @var Achievement $achievement */
99
        foreach ($this->getAchievements() as $achievement) {
100
            if ($achievement->getName() == $achievementName) {
101
                return $achievement;
102
            }
103
        }
104
105
        return null;
106
    }
107
108
    /**
109
     * Gets all achievements for a category
110
     *
111
     * @param Category $category
112
     * @return array
113
     */
114
    public function getAchievementsByCategory(Category $category)
115
    {
116
        $achievements = array();
117
118
        /** @var Achievement $achievement */
119
        foreach ($this->getAchievements() as $achievement) {
120
            if ($achievement->getCategory() == $category) {
121
                $achievements[] = $achievement;
122
            }
123
        }
124
125
        return $achievements;
126
    }
127
128
    /**
129
     * @param Achievement $achievement
130
     * @param UserInterface $user
131
     * @param bool $store Whether to store this action using the storage adapter
132
     */
133
    public function awardAchievement(Achievement $achievement, UserInterface $user = null, $store = true)
134
    {
135
        $this->awardedAchievements[] = $achievement;
136
137
        if ($user !== null && $store == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
138
            $this->getStorage()->awardAchievementToUser($achievement, $user);
139
        }
140
    }
141
142
    /**
143
     * @param Achievement $achievement
144
     * @param UserInterface $user
145
     * @param bool $store Whether to store this action using the storage adapter
146
     */
147
    public function removeAchievement(Achievement $achievement, UserInterface $user = null, $store = true)
148
    {
149
        $this->removedAchievements[] = $achievement;
150
151
        if ($user !== null && $store == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
152
            $this->getStorage()->removeAchievementFromUser($achievement, $user);
153
        }
154
    }
155
156
    /**
157
     * @return array
158
     */
159
    public function getAwardedAchievements()
160
    {
161
        return $this->awardedAchievements;
162
    }
163
164
    /**
165
     * @return array
166
     */
167
    public function getRemovedAchievements()
168
    {
169
        return $this->removedAchievements;
170
    }
171
172
    /**
173
     * Get all possible achievement providers
174
     *
175
     * @return AchievementProviderInterface[]
176
     */
177
    public function getProviders()
178
    {
179
        $providers = array();
180
181
        foreach ($this->getPluginManager()->getCanonicalNames() as $providerAlias) {
182
            $providers[] = $this->getPluginManager()->get($providerAlias);
183
        }
184
185
        return $providers;
186
    }
187
188
    /**
189
     * @return \AxalianAchievements\AchievementProvider\AchievementProviderPluginManager
190
     */
191
    public function getPluginManager()
192
    {
193
        return $this->pluginManager;
194
    }
195
196
    /**
197
     * @param \AxalianAchievements\AchievementProvider\AchievementProviderPluginManager $pluginManager
198
     * @return AchievementService
199
     */
200
    public function setPluginManager($pluginManager)
201
    {
202
        $this->pluginManager = $pluginManager;
203
204
        return $this;
205
    }
206
207
    /**
208
     * @return \AxalianAchievements\StorageAdapter\StorageAdapterInterface
209
     */
210
    public function getStorage()
211
    {
212
        return $this->storage;
213
    }
214
215
    /**
216
     * @param \AxalianAchievements\StorageAdapter\StorageAdapterInterface $storage
217
     * @return AchievementService
218
     */
219
    public function setStorage($storage)
220
    {
221
        $this->storage = $storage;
222
223
        return $this;
224
    }
225
}
226