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/Tariff.php (5 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\modules\finance\models\query\TariffQuery;
14
use hipanel\modules\finance\models\stubs\ServerResourceStub;
15
use Yii;
16
17
/**
18
 * Class Tariff.
19
 * @property resource[]|DomainResource[]|ServerResource[] $resources
20
 */
21
class Tariff extends \hipanel\base\Model implements CalculableModelInterface
22
{
23
    use \hipanel\base\ModelTrait;
24
25
    const TYPE_DOMAIN = 'domain';
26
    const TYPE_XEN = 'svds';
27
    const TYPE_OPENVZ = 'ovds';
28
    const TYPE_SERVER = 'server';
29
    const TYPE_CERT = 'certificate';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function rules()
35
    {
36
        return [
37
            [['id'], 'filter', 'filter' => function ($value) { return explode(',', $value); }, 'on' => ['search']],
38
            [['id'], 'each', 'rule' => ['trim', 'integer'], 'on' => ['search']],
39
            [['client_id', 'seller_id', 'id', 'parent_id'], 'integer', 'on' => ['create', 'update']],
40
            [['client', 'seller', 'bill', 'name'], 'safe'],
41
            [['domain', 'server'], 'safe'],
42
            [['tariff', 'tariff_id'], 'safe'],
43
            [['type_id', 'state_id'], 'integer'],
44
            [['type', 'state', 'currency'], 'safe'],
45
            [['used'], 'integer'],
46
            [['note', 'label'], 'safe'],
47
            [['is_personal'], 'boolean'],
48
            [['id'], 'required', 'on' => ['delete', 'set-note']],
49
            [['note'], 'string', 'on' => ['set-note']],
50
        ];
51
    }
52
53
    public function getResources()
54
    {
55
        if ($this->getGeneralType() === 'domain') {
56
            return $this->hasMany(DomainResource::class, ['tariff_id' => 'id'])->inverseOf('tariff');
57
        } elseif ($this->getGeneralType() === 'server') {
58
            return $this->hasMany(ServerResource::class, ['tariff_id' => 'id'])->inverseOf('tariff');
59
        } elseif ($this->getGeneralType() === 'certificate') {
60
            return $this->hasMany(CertificateResource::class, ['tariff_id' => 'id'])->inverseOf('tariff');
61
        }
62
63
        return $this->hasMany(Resource::class, ['tariff_id' => 'id'])->inverseOf('tariff');
64
    }
65
66
    /**
67
     * @param $type
68
     * @param bool $stubWhenNotFound whether to return [[ServerResourceStub]] when
69
     * the tariff does not have a relevant resource
70
     * @return DomainResource|ServerResource|ServerResourceStub|resource
71
     */
72
    public function getResourceByType($type, $stubWhenNotFound = true)
73
    {
74
        foreach ($this->resources as $resource) {
75
            if ($resource->type === $type) {
76
                return $resource;
77
            }
78
        }
79
80
        return $stubWhenNotFound ? $this->getStubResource($type) : null;
81
    }
82
83
    /**
84
     * @param string $type
85
     * @return ServerResourceStub
86
     */
87
    public function getStubResource($type)
88
    {
89
        return new ServerResourceStub([
90
            'tariff' => $this,
91
            'type' => $type,
92
        ]);
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function attributeLabels()
99
    {
100
        return $this->mergeAttributeLabels([
101
            'used' => Yii::t('hipanel:finance:tariff', 'Used'),
102
        ]);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     * @return TariffQuery
108
     */
109
    public static function find($options = [])
110
    {
111
        return new TariffQuery(get_called_class(), [
112
            'options' => $options,
113
        ]);
114
    }
115
116
    public function getGeneralType()
117
    {
118
        if ($this->type === static::TYPE_DOMAIN) {
0 ignored issues
show
The property type does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
119
            return 'domain';
120
        } elseif ($this->type === static::TYPE_CERT) {
0 ignored issues
show
The property type does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
            return 'certificate';
122
        } elseif (in_array($this->type, [static::TYPE_OPENVZ, static::TYPE_XEN, static::TYPE_SERVER], true)) {
0 ignored issues
show
The property type does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
            return 'server';
124
        }
125
126
        return null;
127
    }
128
129
    /**
130
     * Method creates and returns corresponding Calculation model.
131
     *
132
     * @return Calculation
133
     */
134
    public function getCalculationModel()
135
    {
136
        return new Calculation([
137
            'calculation_id' => $this->id,
0 ignored issues
show
The property id does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
138
            'tariff_id' => $this->id,
0 ignored issues
show
The property id does not exist on object<hipanel\modules\finance\models\Tariff>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
139
            'object' => $this->getGeneralType(),
140
        ]);
141
    }
142
}
143