Issues (434)

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.

src/models/CertificateResource.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
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\models;
12
13
use hipanel\base\ModelTrait;
14
use Money\Formatter\IntlMoneyFormatter;
15
use Money\Money;
16
use Money\MoneyParser;
17
use Yii;
18
use yii\base\InvalidConfigException;
19
use yii\validators\NumberValidator;
20
21
/**
22
 * Class CertificateResource.
23
 *
24
 * @author Dmytro Naumenko <[email protected]>
25
 * @deprecated Is implemented in plan module
26
 */
27
class CertificateResource extends Resource
28
{
29
    use ModelTrait;
30
31
    public $certificateType;
32
33
    public static function tableName()
34
    {
35
        return 'resource';
36
    }
37
38
    const TYPE_CERT_PURCHASE = 'certificate_purchase';
39
    const TYPE_CERT_RENEWAL = 'certificate_renewal';
40
41 View Code Duplication
    public function rules()
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...
42
    {
43
        $rules = parent::rules();
44
        $rules['create-required'] = [
45
            ['object_id'],
46
            'required',
47
            'on' => ['create', 'update'],
48
            'when' => function ($model) {
49
                /** @var self $model */
50
                return $model->isTypeCorrect();
51
            },
52
        ];
53
        $rules[] = [['certificateType'], 'safe'];
54
        $rules[] = [['data'], 'validatePrices', 'on' => ['create', 'update']];
55
56
        return $rules;
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public static function getPeriods()
63
    {
64
        return [
65
            1 => Yii::t('hipanel:finance:tariff', '{n, plural, one{# year} other{# years}}', ['n' => 1]),
66
            2 => Yii::t('hipanel:finance:tariff', '{n, plural, one{# year} other{# years}}', ['n' => 2]),
67
        ];
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public function getAvailablePeriods()
74
    {
75
        $periods = [];
76
        foreach ([1, 2] as $period) {
77
            if ($this->hasPriceForPeriod($period)) {
78
                $periods[$period] = Yii::t('hipanel:finance:tariff', '{n, plural, one{# year} other{# years}}', ['n' => $period]);
79
            }
80
        }
81
82
        return $periods;
83
    }
84
85
    public function getPriceForPeriod($period)
86
    {
87
        $sums = $this->data['sums'][$period];
88
        if (empty($sums)) {
89
            return null;
90
            /// XXX throw new InvalidConfigException('Period ' . $period . ' is not available');
91
        }
92
93
        return (float) $sums;
94
    }
95
96
    /**
97
     * @param int $period
98
     * @return string|null
99
     */
100
    public function getMoneyForPeriod(int $period)
101
    {
102
        $this->price = $this->getPriceForPeriod($period);
103
        if (empty($this->currency))
104
            return null;
105
        return $this->getMoney();
106
    }
107
108
    public function validatePrices()
109
    {
110
        $periods = $this->getPeriods();
111
        $validator = new NumberValidator();
112
113
        foreach (array_keys($periods) as $period) {
114
            $validation = $validator->validate($this->data['sums'][$period]);
115
            if ($validation === false) {
116
                unset($this->data['sums'][$period]);
117
            }
118
        }
119
120
        $this->data = ['sums' => $this->data['sums']];
121
122
        return true;
123
    }
124
125
    /**
126
     * @param int $period
127
     * @return bool
128
     */
129
    public function hasPriceForPeriod(int $period)
130
    {
131
        return !empty($this->data['sums'][$period]);
132
    }
133
134
    /**
135
     * @return array
136
     */
137 View Code Duplication
    public function getTypes()
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
        return [
140
            static::TYPE_CERT_PURCHASE => Yii::t('hipanel:finance:tariff', 'Purchase'),
141
            static::TYPE_CERT_RENEWAL => Yii::t('hipanel:finance:tariff', 'Renewal'),
142
        ];
143
    }
144
}
145