Issues (13)

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/CurrencyManager.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 namespace Arcanedev\Currencies;
2
3
use Arcanedev\Currencies\Contracts\CurrencyManager as CurrencyManagerContract;
4
use Arcanedev\Currencies\Entities\CurrencyCollection;
5
use Illuminate\Support\Arr;
6
7
/**
8
 * Class     CurrencyManager
9
 *
10
 * @package  Arcanedev\Currencies
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class CurrencyManager implements CurrencyManagerContract
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Default currency.
21
     *
22
     * @var string
23
     */
24
    protected $default;
25
26
    /**
27
     * Supported currencies.
28
     *
29
     * @var array
30
     */
31
    protected $supported      = [];
32
33
    /**
34
     * Non ISO Currencies included.
35
     *
36
     * @var bool
37
     */
38
    protected $nonIsoIncluded = false;
39
40
    /**
41
     * The currencies collection.
42
     *
43
     * @var  \Arcanedev\Currencies\Entities\CurrencyCollection
44
     */
45
    protected $currencies;
46
47
    /* ------------------------------------------------------------------------------------------------
48
     |  Constructor
49
     | ------------------------------------------------------------------------------------------------
50
     */
51
    /**
52
     * CurrencyManager constructor.
53
     *
54
     * @param  array  $configs
55
     */
56 612
    public function __construct(array $configs)
57
    {
58 612
        $this->default        = Arr::get($configs, 'default', 'USD');
59 612
        $this->supported      = Arr::get($configs, 'supported', ['USD']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Arr:...pported', array('USD')) of type * is incompatible with the declared type array of property $supported.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60 612
        $this->nonIsoIncluded = Arr::get($configs, 'include-non-iso', false);
61 612
        $this->currencies     = new CurrencyCollection;
62 612
    }
63
64
    /* ------------------------------------------------------------------------------------------------
65
     |  Getters & Setters
66
     | ------------------------------------------------------------------------------------------------
67
     */
68
    /**
69
     * Get the default currency iso code.
70
     *
71
     * @return string
72
     */
73 84
    public function getDefault()
74
    {
75 84
        return $this->default;
76
    }
77
78
    /**
79
     * Get the default currency entity.
80
     *
81
     * @return \Arcanedev\Currencies\Contracts\Entities\Currency
82
     */
83 12
    public function getDefaultCurrency()
84
    {
85 12
        return $this->currencies->get($this->getDefault());
86
    }
87
88
    /**
89
     * Get supported currencies (iso codes).
90
     *
91
     * @return array
92
     */
93 60
    public function getSupported()
94
    {
95 60
        return $this->supported;
96
    }
97
98
    /**
99
     * Check if non ISO Currencies included.
100
     *
101
     * @return bool
102
     */
103 12
    public function isNonIsoIncluded()
104
    {
105 12
        return $this->nonIsoIncluded;
106
    }
107
108
    /**
109
     * Get the currencies collection.
110
     *
111
     * @return \Arcanedev\Currencies\Entities\CurrencyCollection
112
     */
113 612
    public function currencies()
114
    {
115 612
        return $this->currencies;
116
    }
117
118
    /* ------------------------------------------------------------------------------------------------
119
     |  Main Functions
120
     | ------------------------------------------------------------------------------------------------
121
     */
122
    /**
123
     * Load the currencies.
124
     *
125
     * @param  array  $currencies
126
     *
127
     * @return self
128
     */
129 612
    public function load(array $currencies)
130
    {
131 612
        $this->currencies()->load($currencies, $this->nonIsoIncluded);
132
133 612
        return $this;
134
    }
135
136
    /**
137
     * Get a currency from the collection by iso code.
138
     *
139
     * @param  string      $iso
140
     * @param  mixed|null  $default
141
     *
142
     * @return \Arcanedev\Currencies\Contracts\Entities\Currency
143
     */
144 12
    public function get($iso, $default = null)
145
    {
146 12
        return $this->currencies()->get($iso, $default);
147
    }
148
149
    /**
150
     * Get a currency or fail if not exists.
151
     *
152
     * @param  string  $iso
153
     *
154
     * @return \Arcanedev\Currencies\Contracts\Entities\Currency
155
     *
156
     * @throws \Arcanedev\Currencies\Exceptions\CurrencyNotFoundException
157
     */
158 60
    public function findOrFail($iso)
159
    {
160 60
        return $this->currencies()->findOrFails($iso);
161
    }
162
163
    /**
164
     * Get the supported currencies collection.
165
     *
166
     * @return \Arcanedev\Currencies\Entities\CurrencyCollection
167
     */
168 12
    public function getSupportedCurrencies()
169
    {
170 12
        $currencies = $this->currencies();
171 12
        $supported  = array_map(function ($iso) use ($currencies) {
172 12
            return $currencies->findOrFails($iso);
173 12
        }, array_combine($this->getSupported(), $this->getSupported()));
174
175 12
        return CurrencyCollection::make($supported);
176
    }
177
178
    /**
179
     * Format the amount.
180
     *
181
     * @param  string      $iso
182
     * @param  double|int  $amount
183
     * @param  int         $decimals
184
     *
185
     * @return string
186
     *
187
     * @throws \Arcanedev\Currencies\Exceptions\CurrencyNotFoundException
188
     */
189 24
    public function format($iso, $amount, $decimals = 2)
190
    {
191 24
        return $this->findOrFail($iso)->format($amount, $decimals);
192
    }
193
194
    /**
195
     * Format the amount by the default iso.
196
     *
197
     * @param  double|int  $amount
198
     * @param  int         $decimals
199
     *
200
     * @return string
201
     *
202
     * @throws \Arcanedev\Currencies\Exceptions\CurrencyNotFoundException
203
     */
204 12
    public function formatDefault($amount, $decimals = 2)
205
    {
206 12
        return $this->format($this->getDefault(), $amount, $decimals);
207
    }
208
209
    /**
210
     * Get the currency symbol by iso code.
211
     *
212
     * @param  string  $iso
213
     *
214
     * @return string
215
     */
216 12
    public function symbol($iso)
217
    {
218 12
        return $this->findOrFail($iso)->symbol;
0 ignored issues
show
Accessing symbol on the interface Arcanedev\Currencies\Contracts\Entities\Currency suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
219
    }
220
}
221