Issues (23)

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/Currency.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
2
3
namespace Propaganistas\LaravelIntl;
4
5
use CommerceGuys\Intl\Formatter\CurrencyFormatter;
6
use CommerceGuys\Intl\Currency\CurrencyRepository;
7
use CommerceGuys\Intl\NumberFormat\NumberFormatRepository;
8
use Illuminate\Support\Arr;
9
use Propaganistas\LaravelIntl\Concerns\WithLocales;
10
use Propaganistas\LaravelIntl\Contracts\Intl;
11
12
class Currency extends Intl
13
{
14
    use WithLocales;
15
16
    /**
17
     * Loaded localized currency data.
18
     *
19
     * @var array
20
     */
21
    protected $data;
22
23
    /**
24
     * Array of localized currency formatters.
25
     *
26
     * @var array
27
     */
28
    protected $formatters;
29
30
    /**
31
     * Get a localized record by key.
32
     *
33
     * @param string $currencyCode
34
     * @return string
35
     */
36 15
    public function get($currencyCode)
37
    {
38 15
        return $this->data()->get($currencyCode)->getName();
39
    }
40
41
    /**
42
     * Alias of get().
43
     *
44
     * @param string $currencyCode
45
     * @return string
46
     */
47 12
    public function name($currencyCode)
48
    {
49 12
        return $this->get($currencyCode);
50
    }
51
52
    /**
53
     * Get the symbol of the given currency.
54
     *
55
     * @param string $currencyCode
56
     * @return string
57
     */
58 3
    public function symbol($currencyCode)
59
    {
60 3
        return $this->data()->get($currencyCode)->getSymbol();
61
    }
62
63
    /**
64
     * Format a number.
65
     *
66
     * @param string|int|float $number
67
     * @param string $currencyCode
68
     * @param array $options
69
     * @return mixed|string
70
     */
71 12
    public function format($number, $currencyCode, $options = [])
72
    {
73 12
        return $this->formatter()->format($number, $currencyCode,
74 12
            $this->mergeOptions($options)
75
        );
76
    }
77
78
    /**
79
     * Format a number.
80
     *
81
     * @param string|int|float $number
82
     * @param string $currencyCode
83
     * @param array $options
84
     * @return mixed|string
85
     */
86 3
    public function formatAccounting($number, $currencyCode, $options = [])
87
    {
88 3
        return $this->formatter()->format($number, $currencyCode,
89 3
            $this->mergeOptions($options, ['style' => 'accounting'])
90
        );
91
    }
92
93
    /**
94
     * Parse a localized currency string into a number.
95
     *
96
     * @param string $number
97
     * @param string $currencyCode
98
     * @param array $options
99
     * @return mixed|string
100
     */
101 3
    public function parse($number, $currencyCode, $options = [])
102
    {
103 3
        return $this->formatter()->parse($number, $currencyCode,
104 3
            $this->mergeOptions($options)
105
        );
106
    }
107
108
    /**
109
     * Get all localized records.
110
     *
111
     * @return array
112
     */
113 3
    public function all()
114
    {
115 3
        return $this->data()->getList();
116
    }
117
118
    /**
119
     * Get the formatter's key.
120
     *
121
     * @param string $locale
122
     * @param string $fallbackLocale
123
     * @return string
124
     */
125 33
    protected function getLocalesKey($locale, $fallbackLocale)
126
    {
127 33
        return implode('|', [
128 33
            $locale,
129 33
            $fallbackLocale,
130
        ]);
131
    }
132
133
    /**
134
     * The currency repository.
135
     *
136
     * @return \CommerceGuys\Intl\Currency\CurrencyRepository
137
     */
138 33 View Code Duplication
    protected function data()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140 33
        $key = $this->getLocalesKey(
141 33
            $locale = $this->getLocale(),
142 33
            $fallbackLocale = $this->getFallbackLocale()
143
        );
144
145 33
        if (! isset($this->data[$key])) {
146 33
            $this->data[$key] = new CurrencyRepository($locale, $fallbackLocale);
147
        }
148
149 33
        return $this->data[$key];
150
    }
151
152
    /**
153
     * The current number formatter.
154
     *
155
     * @return \CommerceGuys\Intl\Formatter\CurrencyFormatter
156
     */
157 18 View Code Duplication
    protected function formatter()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159 18
        $key = $this->getLocalesKey(
160 18
            $locale = $this->getLocale(),
161 18
            $fallbackLocale = $this->getFallbackLocale()
162
        );
163
164 18
        if (! isset($this->formatters[$key])) {
165 18
            $this->formatters[$key] = new CurrencyFormatter(
166 18
                new NumberFormatRepository($fallbackLocale),
167 18
                $this->data(),
168 18
                ['locale' => $locale]
169
            );
170
        }
171
172 18
        return $this->formatters[$key];
173
    }
174
175
    /**
176
     * Merges the options array.
177
     *
178
     * @param array $options
179
     * @param array $defaults
180
     * @return array
181
     */
182 18
    protected function mergeOptions(array $options, array $defaults = [])
183
    {
184 18
        Arr::forget($options, 'locale');
185
186 18
        return $defaults + $options;
187
    }
188
}