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/logic/bill/MonthlyQuantity.php (3 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\logic\bill;
12
13
use hipanel\modules\finance\forms\BillForm;
14
use hipanel\modules\finance\models\Bill;
15
use hipanel\modules\finance\models\Charge;
16
use hipanel\modules\server\models\Consumption;
17
use Yii;
18
19
/**
20
 * Class MonthlyQuantity.
21
 *
22
 * @author Dmytro Naumenko <[email protected]>
23
 */
24
class MonthlyQuantity extends DefaultQuantityFormatter implements ContextAwareQuantityFormatter
25
{
26
    /** @var Bill|Charge */
27
    protected $model;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function format(): string
33
    {
34
        $text = Yii::t('hipanel:finance', '{quantity, plural, one{# day} other{# days}}', ['quantity' => $this->getClientValue()]);
35
36
        return $text;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getValue(): string
43
    {
44
        return $this->getQuantity()->getQuantity() / $this->getNumberOfDays();
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getClientValue(): string
51
    {
52
        return round($this->getQuantity()->getQuantity() * $this->getNumberOfDays());
53
    }
54
55
    /**
56
     * @return false|string
57
     */
58
    protected function getNumberOfDays()
59
    {
60
        return date('t', strtotime($this->model->time));
61
    }
62
63
    /**
64
     * @param $context
65
     * @return ContextAwareQuantityFormatter
66
     */
67
    public function setContext($context): ContextAwareQuantityFormatter
68
    {
69
        if (!$context instanceof Bill && !$context instanceof Charge && !$context instanceof BillForm && !$context instanceof Consumption) {
0 ignored issues
show
The class hipanel\modules\server\models\Consumption does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
70
            throw new \OutOfBoundsException(sprintf(
71
                'Context "%s" is not supported by Monthly quantity',
72
                get_class($context)
73
            ));
74
        }
75
76
        $this->model = $context;
0 ignored issues
show
Documentation Bug introduced by
It seems like $context can also be of type object<hipanel\modules\finance\forms\BillForm> or object<hipanel\modules\server\models\Consumption>. However, the property $model is declared as type object<hipanel\modules\f...\finance\models\Charge>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
77
78
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (hipanel\modules\finance\logic\bill\MonthlyQuantity) is incompatible with the return type declared by the interface hipanel\modules\finance\...tyFormatter::setContext of type self.

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...
79
    }
80
}
81