Issues (14)

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/Builder.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 Aitor24\Localizer;
4
5
use Illuminate\Support\Facades\App;
6
7
class Builder
8
{
9
    /**
10
     * Get all allowed languages.
11
     *
12
     * @return array
13
     **/
14
    public static function allowedLanguages()
15
    {
16
        if (config('localizer.allowed_langs')) {
17
            return self::addNames(array_merge(config('localizer.allowed_langs'), [config('localizer.default_lang')]));
18
        } else {
19
            return self::addNames([config('localizer.default_lang')]);
20
        }
21
    }
22
23
    /**
24
     * Return true if $code is an allowed lang.
25
     *
26
     * @return bool
27
     **/
28
    public static function isAllowedLanguage($code)
29
    {
30
        return in_array($code, array_keys(self::allowedLanguages()));
31
    }
32
33
    /**
34
     * Add names to an array of language codes as [$code => $language].
35
     *
36
     * @param array $codes
37
     *
38
     * @return array
39
     **/
40 View Code Duplication
    public static function addNames($codes)
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...
41
    {
42
        // Get languages from config
43
        $languages = config('localizer_languages.languages');
44
45
        $array = [];
46
47
        // Generate an array with $code as key and $code language as value
48
        foreach ($codes as $code) {
49
            $lang_name = 'Unknown';
50
51
            foreach ($languages as $language) {
52
                if ($language['code'] == $code) {
53
                    $lang_name = $language['name'];
54
                }
55
            }
56
57
            $array[$code] = $lang_name;
58
        }
59
60
        return $array;
61
    }
62
63
    /**
64
     * Add names to an array of language codes as [$language => $code].
65
     *
66
     * @param array $langs
67
     *
68
     * @return array
69
     **/
70 View Code Duplication
    public static function addCodes($langs)
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...
71
    {
72
        // Get languages from config
73
        $languages = config('localizer_languages.languages');
74
75
        $array = [];
76
77
        // Generate an array with $lang as key and $lang code as value
78
        foreach ($langs as $lang) {
79
            $lang_code = 'unk';
80
81
            foreach ($languages as $language) {
82
                if ($language['name'] == $lang) {
83
                    $lang_code = $language['code'];
84
                }
85
            }
86
87
            $array[$lang] = $lang_code;
88
        }
89
90
        return $array;
91
    }
92
93
    /**
94
     * Returns the url to set up language and return back.
95
     *
96
     * @param string $code
97
     *
98
     * @return string
99
     **/
100
    public static function setRoute($code)
101
    {
102
        return route('localizer::setLocale', ['locale' => $code]);
103
    }
104
105
    /**
106
     * Returns the url to set up language and return to url('/').
107
     *
108
     * @param string $code
109
     *
110
     * @return string
111
     **/
112
    public static function setRouteHome($code)
113
    {
114
        return route('localizer::setLocaleHome', ['locale' => $code]);
115
    }
116
117
    /**
118
     * Returns the current language code.
119
     *
120
     * @return string
121
     **/
122
    public static function getCode($name = 'default')
123
    {
124
        if ($name == 'default') {
125
            $name = self::getLanguage();
126
        }
127
128
        return self::addCodes([$name])[$name];
129
    }
130
131
    /**
132
     * Returns the language name.
133
     *
134
     * @return string
135
     **/
136
    public static function getLanguage($code = 'default')
137
    {
138
        if ($code == 'default') {
139
            $code = App::getLocale();
140
        }
141
142
        return self::addNames([$code])[$code];
143
    }
144
}
145