Issues (275)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Helpers/Money.php (4 issues)

Labels
1
<?php
2
3
namespace SaasReady\Helpers;
4
5
use DivisionByZeroError;
6
use SaasReady\Constants\CurrencyCode;
7
use SaasReady\Models\Currency;
0 ignored issues
show
The type SaasReady\Models\Currency was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Immutable Money class to store the money information
11
 *
12
 * @note $amount is storing as cents, by default you would need to do *100 for every real amount
13
 * or use self@makeFromRealAmount method to do that.
14
 */
15
final class Money
16
{
17
    public function __construct(
18
        public readonly int $amount,
19
        public readonly CurrencyCode $currencyCode
20
    ) {
21
    }
22
23
    public static function make(int $amount, CurrencyCode $currencyCode): self
24
    {
25
        return new Money($amount, $currencyCode);
26
    }
27
28
    public static function makeFromRealAmount(float $amount, CurrencyCode $currencyCode): self
29
    {
30
        return new Money($amount * 100, $currencyCode);
0 ignored issues
show
$amount * 100 of type double is incompatible with the type integer expected by parameter $amount of SaasReady\Helpers\Money::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        return new Money(/** @scrutinizer ignore-type */ $amount * 100, $currencyCode);
Loading history...
31
    }
32
33
    public function clone(?int $amount = null): self
34
    {
35
        return self::make($amount ?? $this->amount, $this->currencyCode);
36
    }
37
38
    public function getCurrency(): Currency
39
    {
40
        return Currency::findByCode($this->currencyCode);
41
    }
42
43
    public function add(Money $money): Money
44
    {
45
        return $this->clone(
46
            $this->amount + $money->amount
47
        );
48
    }
49
50
    public function subtract(Money $money): Money
51
    {
52
        return $this->clone(
53
            $this->amount - $money->amount
54
        );
55
    }
56
57
    public function multiply(float $rate): Money
58
    {
59
        return $this->clone(
60
            $this->amount * $rate
0 ignored issues
show
$this->amount * $rate of type double is incompatible with the type integer|null expected by parameter $amount of SaasReady\Helpers\Money::clone(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
            /** @scrutinizer ignore-type */ $this->amount * $rate
Loading history...
61
        );
62
    }
63
64
    public function divide(float $rate): Money
65
    {
66
        if ($rate == 0) {
67
            throw new DivisionByZeroError();
68
        }
69
70
        return $this->clone(
71
            $this->amount / $rate
0 ignored issues
show
$this->amount / $rate of type double is incompatible with the type integer|null expected by parameter $amount of SaasReady\Helpers\Money::clone(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
            /** @scrutinizer ignore-type */ $this->amount / $rate
Loading history...
72
        );
73
    }
74
75
    /**
76
     * With symbol: $1234.56
77
     * Without symbol: USD 1234.56
78
     *
79
     * With decimals: 1234.56
80
     * Without decimals: 1234
81
     */
82
    public function present(bool $withSymbol = true, bool $withDecimals = true): string
83
    {
84
        $presentedAmount = $this->presentAmountOnly($withDecimals);
85
86
        if ($withSymbol) {
87
            $currency = $this->getCurrency();
88
89
            return sprintf(
90
                '%s%s%s',
91
                $currency->symbol,
92
                $currency->space_after_symbol ? ' ' : '',
93
                $presentedAmount
94
            );
95
        }
96
97
        return $this->currencyCode->value . ' ' . $presentedAmount;
98
    }
99
100
    /**
101
     * Present the amount only - based on the configuration from Currency
102
     *
103
     * Eg: 1,234.56
104
     */
105
    public function presentAmountOnly(bool $withDecimals = true): string
106
    {
107
        $currency = $this->getCurrency();
108
109
        return number_format(
110
            $this->amount / 100,
111
            $withDecimals ? $currency->decimals : 0,
112
            $currency->decimal_separator,
113
            $currency->thousands_separator
114
        );
115
    }
116
}
117