Issues (2)

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.

models/Demo.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
/**
4
 * @package Demo 
5
 * @author Iurii Makukh <[email protected]> 
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> 
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ 
8
 */
9
10
namespace gplcart\modules\demo\models;
11
12
use gplcart\core\Cache,
13
    gplcart\core\Model,
14
    gplcart\core\Handler;
15
use gplcart\core\models\Language as LanguageModel;
16
17
/**
18
 * Manages basic behaviors and data related to Demo module
19
 */
20
class Demo extends Model
21
{
22
23
    /**
24
     * Language model instance
25
     * @var \gplcart\core\models\Language $language
26
     */
27
    protected $language;
28
29
    /**
30
     * @param LanguageModel $language
31
     */
32
    public function __construct(LanguageModel $language)
33
    {
34
        parent::__construct();
35
36
        $this->language = $language;
37
    }
38
39
    /**
40
     * Returns an array of handlers
41
     */
42
    public function getHandlers()
43
    {
44
        $handlers = &Cache::memory(__METHOD__);
45
46
        if (isset($handlers)) {
47
            return $handlers;
48
        }
49
50
        $handlers = array();
51
52
        $handlers['default'] = array(
53
            'title' => $this->language->text('Default (watches)'),
54
            'description' => $this->language->text('Create basic demo set containing products, categories and banners'),
55
            'handlers' => array(
56
                'create' => array('gplcart\\modules\\demo\\handlers\\Demo', 'create'),
57
                'delete' => array('gplcart\\modules\\demo\\handlers\\Demo', 'delete')
58
            )
59
        );
60
61
        $this->hook->fire('module.demo.handlers', $handlers, $this);
62
        return $handlers;
63
    }
64
65
    /**
66
     * Returns a handler
67
     * @param string $handler_id
68
     * @return array
69
     */
70
    public function getHandler($handler_id)
71
    {
72
        $handlers = $this->getHandlers();
73
        return empty($handlers[$handler_id]) ? array() : $handlers[$handler_id];
74
    }
75
76
    /**
77
     * Create a demo content
78
     * @param string $handler_id
79
     * @param integer $store_id
80
     * @return string|integer
81
     */
82
    public function create($handler_id, $store_id)
83
    {
84
        $existing = $this->getCreatedEntityId($handler_id, $store_id);
85
86
        if (!empty($existing)) {
87
            return $this->language->text('Demo content already exists');
88
        }
89
90
        $handlers = $this->getHandlers();
91
        return Handler::call($handlers, $handler_id, 'create', array($store_id, $this));
92
    }
93
94
    /**
95
     * Deletes the demo content
96
     * @param string $handler_id
97
     * @param integer $store_id
98
     * @return string|integer
99
     */
100
    public function delete($handler_id, $store_id)
101
    {
102
        $existing = $this->getCreatedEntityId($handler_id, $store_id);
103
104
        if (empty($existing)) {
105
            return true;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return true; (boolean) is incompatible with the return type documented by gplcart\modules\demo\models\Demo::delete of type string|integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
106
        }
107
108
        $handlers = $this->getHandlers();
109
        return Handler::call($handlers, $handler_id, 'delete', array($store_id, $this));
110
    }
111
112
    /**
113
     * Set an array of created entity IDs in the database
114
     * @param string $handler_id
115
     * @param integer $store_id
116
     * @param array $data
117
     * @return boolean
118
     */
119
    public function setCreatedEntityId($handler_id, $store_id, array $data)
120
    {
121
        // Remove unneeded keys before saving
122
        $cleaned = array_map('array_values', $data);
123
        return $this->config->set("module_demo_{$handler_id}_{$store_id}", $cleaned);
124
    }
125
126
    /**
127
     * Returns an array of previously created entity IDs
128
     * @param string $handler_id
129
     * @param integer $store_id
130
     * @return array
131
     */
132
    public function getCreatedEntityId($handler_id, $store_id)
133
    {
134
        return $this->config->get("module_demo_{$handler_id}_{$store_id}", array());
135
    }
136
137
    /**
138
     * Removes all saved data about previously created entity IDs from the database
139
     * @param string $handler_id
140
     * @param integer $store_id
141
     * @return boolean
142
     */
143
    public function resetCreatedEntityId($handler_id, $store_id)
144
    {
145
        return $this->config->reset("module_demo_{$handler_id}_{$store_id}");
146
    }
147
148
}
149