Issues (10)

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/Builder.php (3 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\Laralang;
4
5
use Aitor24\Laralang\Builder\ApertiumTrans;
6
use Aitor24\Laralang\Builder\GoogleTrans;
7
use Aitor24\Laralang\Builder\MymemoryTrans;
8
use Aitor24\Laralang\Models\DB_Translation;
9
10
class Builder
11
{
12
    /**
13
     * Get the translation.
14
     *
15
     * @param string $string
16
     *
17
     * @return object
18
     */
19
    public static function trans($string, $vars = [])
20
    {
21
        $translator = config('laralang.default.translator');
22
        if (!in_array(config('laralang.default.translator'), ['apertium', 'mymemory', 'google'])) {
23
            return "<font style='color:red;'>Laralang doesn't support $translator translator. Check config</font>";
24
        } else {
25
            if (config('laralang.default.translator') == 'mymemory') {
26
                return new MymemoryTrans($string, $vars);
27
            } elseif (config('laralang.default.translator') == 'apertium') {
28
                return new ApertiumTrans($string, $vars);
29
            } elseif (config('laralang.default.translator') == 'google') {
30
                return new GoogleTrans($string, $vars);
31
            }
32
        }
33
    }
34
35
    /**
36
     * Generate files json for a specify package.
37
     *
38
     * @param string $string
0 ignored issues
show
There is no parameter named $string. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
39
     *
40
     * @return object
41
     */
42
    public static function generateTranslations($is_package, $package, $translationsPath, $toLangs = 'es')
43
    {
44
        if ($is_package) {
45
            $path = realpath(__DIR__.'/../../../'.$package.$translationsPath);
46
        } else {
47
            $path = resource_path().'/'.$translationsPath;
48
        }
49
        $toLangs = explode('|', $toLangs);
50
        $files = glob($path.'/*.php');
51
        foreach ($files as $file) {
52
            foreach ($toLangs as $lang) {
53
                $lines = include $file;
54
                $array = self::transArray($lines, $lang);
55
                $data = '<?php return '.str_replace(')', ']', str_replace('array (', '[', str_replace(")'", ']', str_replace("'array (", '[', $array)))).";\n";
56
57
                $savePath = $path.'/../'.$lang;
58
                if (!is_dir($savePath)) {
59
                    mkdir($savePath, 0777, true);
60
                }
61
                file_put_contents($savePath.'/'.basename($file), $data);
62
            }
63
        }
64
    }
65
66
    private static function transArray($array, $lang)
67
    {
68
        foreach ($array as $var => $text) {
69
            $vars = [];
70
            if (is_array($text)) {
71
                $array[$var] = self::transArray($text, $lang);
72
            } else {
73
                foreach (explode(' ', $text) as $word) {
74
                    if (strpos($word, ':') !== false && mb_substr($word, -1) != ':') {
75
                        array_push($vars, $word);
76
                    }
77
                }
78
                $entry = $text;
79
                foreach ($vars as $key => $varreplace) {
80
                    $entry = str_replace($varreplace, '14741469'.$key, $entry);
81
                }
82
                $array[$var] = self::trans($entry, $vars)->from('en')->to($lang)->load(false)->Save(false)->__toString();
83
            }
84
        }
85
86
        return stripslashes(var_export($array, true));
87
    }
88
89
    /**
90
     * Get the languages that translations has been translated.
91
     *
92
     * @return array
93
     */
94 View Code Duplication
    public static function toLanguages()
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...
95
    {
96
        $locales = [];
97
        $translations = DB_Translation::distinct()->select('to_lang')->get();
98
        foreach ($translations as $object) {
99
            array_push($locales, $object->to_lang);
100
        }
101
102
        return $locales;
103
    }
104
105
    /**
106
     * Get the languages from translations has been translated.
107
     *
108
     * @return array
109
     */
110 View Code Duplication
    public static function fromLanguages()
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...
111
    {
112
        $locales = [];
113
        $translations = DB_Translation::distinct()->select('from_lang')->get();
114
        foreach ($translations as $object) {
115
            array_push($locales, $object->from_lang);
116
        }
117
118
        return $locales;
119
    }
120
121
    /**
122
     * Get all the available languages.
123
     *
124
     * @return array
125
     */
126
    public static function allLanguages()
127
    {
128
        return [
129
            'en' => 'English',
130
            'es' => 'Spanish',
131
            'ca' => 'Catalan',
132
            'pt' => 'Portuguese',
133
            'zh' => 'Chinese',
134
            'ja' => 'Japanese',
135
            'de' => 'German',
136
            'fr' => 'French',
137
            'eu' => 'Basque',
138
            'ru' => 'Russian',
139
        ];
140
    }
141
}
142