Issues (4)

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.

src/Money/PhpMoney.php (1 issue)

Labels
Severity

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
namespace Lukeraymonddowning\Mula\Money;
4
5
use Exception;
6
use Illuminate\Support\Collection;
7
use Lukeraymonddowning\Mula\Exceptions\UnreadableMonetaryValue;
8
use Lukeraymonddowning\Mula\Money\PhpMoney\FormatResolver\FormatResolver;
9
use Lukeraymonddowning\Mula\Money\PhpMoney\ParserResolver\ParserResolver;
10
use Money\Currency;
11
12
class PhpMoney implements Money
13
{
14
    public \Money\Money $value;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_NS_SEPARATOR, expecting T_FUNCTION or T_CONST
Loading history...
15
    public FormatResolver $formatResolver;
16
    public ParserResolver $parserResolver;
17
18
    public function __construct(FormatResolver $formatResolver, ParserResolver $parserResolver)
19
    {
20
        $this->formatResolver = $formatResolver;
21
        $this->parserResolver = $parserResolver;
22
    }
23
24
    public static function locale()
25
    {
26
        return config('mula.options.phpmoney.locale');
27
    }
28
29
    public function create($amount, $currency = null): Money
30
    {
31
        $currency ??= config('mula.currency');
32
33
        try {
34
            $this->value = new \Money\Money($amount, new Currency($currency));
35
        } catch (Exception $exception) {
36
            throw new UnreadableMonetaryValue($exception->getMessage());
37
        }
38
39
        return $this;
40
    }
41
42
    public function parse($amount, $currency = null): Money
43
    {
44
        try {
45
            $this->value = $this->parserResolver->resolve()->parse(strval($amount), $currency);
46
        } catch (Exception $exception) {
47
            throw new UnreadableMonetaryValue($exception->getMessage());
48
        }
49
50
        return $this;
51
    }
52
53
    public function displayWithoutCurrency(): string
54
    {
55
        return $this->display(false);
56
    }
57
58
    public function display(bool $includeCurrency = true): string
59
    {
60
        return $this->formatResolver->resolve($includeCurrency)->format($this->value);
61
    }
62
63
    public function currency(): string
64
    {
65
        return $this->value->getCurrency();
66
    }
67
68
    public function value(): string
69
    {
70
        return $this->value->getAmount();
71
    }
72
73
    public function add(...$money): Money
74
    {
75
        return $this->alterValue(fn ($instance) => $instance->value->add(...Collection::make($money)->map->value));
76
    }
77
78
    protected function alterValue(callable $closure)
79
    {
80
        $instance = $this->copy();
81
        $instance->value = $closure($instance);
82
83
        return $instance;
84
    }
85
86
    public function copy(): Money
87
    {
88
        return $this->newInstance($this->value);
89
    }
90
91
    protected function newInstance(\Money\Money $phpMoney)
92
    {
93
        $instance = app(self::class);
94
        $instance->value = $phpMoney;
95
96
        return $instance;
97
    }
98
99
    public function subtract(...$money): Money
100
    {
101
        return $this->alterValue(fn ($instance) => $instance->value->subtract(...Collection::make($money)->map->value));
102
    }
103
104
    public function multiplyBy($multiplier): Money
105
    {
106
        return $this->alterValue(fn ($instance) => $instance->value->multiply($multiplier));
107
    }
108
109
    public function divideBy($divisor): Money
110
    {
111
        return $this->alterValue(fn ($instance) => $instance->value->divide($divisor));
112
    }
113
114
    public function mod(Money $divisor): Money
115
    {
116
        return $this->alterValue(fn ($instance) => $instance->value->mod($divisor->value));
117
    }
118
119
    public function hasSameCurrencyAs(...$money): bool
120
    {
121
        return $this->check($money, fn ($value) => $value->isSameCurrency($this->value));
122
    }
123
124
    protected function check(array $money, callable $check)
125
    {
126
        return empty(Collection::make($money)->first(fn ($amount) => ! $check($amount->value)));
127
    }
128
129
    public function equals(...$money): bool
130
    {
131
        return $this->check($money, fn ($value) => $value->equals($this->value));
132
    }
133
134
    public function isGreaterThan(...$money): bool
135
    {
136
        return $this->check($money, fn ($value) => $value->lessThan($this->value));
137
    }
138
139
    public function isGreaterThanOrEqualTo(...$money): bool
140
    {
141
        return $this->check($money, fn ($value) => $value->lessThanOrEqual($this->value));
142
    }
143
144
    public function isLessThan(...$money): bool
145
    {
146
        return $this->check($money, fn ($value) => $value->greaterThan($this->value));
147
    }
148
149
    public function isLessThanOrEqualTo(...$money): bool
150
    {
151
        return $this->check($money, fn ($value) => $value->greaterThanOrEqual($this->value));
152
    }
153
154
    public function split($allocation): Collection
155
    {
156
        return collect($this->getAllocatedAmounts($allocation))
157
            ->map(fn ($phpMoney) => $this->newInstance($phpMoney));
158
    }
159
160
    protected function getAllocatedAmounts($allocation)
161
    {
162
        if (is_int($allocation)) {
163
            return $this->value->allocateTo($allocation);
164
        }
165
166
        $allocation = is_array($allocation) ? $allocation : $allocation->toArray();
167
168
        return $this->value->allocate($allocation);
169
    }
170
171
    public function __toString()
172
    {
173
        return $this->display();
174
    }
175
}
176