Issues (69)

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.

tests/ScopesTest.php (8 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
use Dimsav\Translatable\Test\Model\Country;
4
use Dimsav\Translatable\Test\Model\Vegetable;
5
6
class ScopesTest extends TestsBase
7
{
8
    public function test_translated_in_scope_returns_only_translated_records_for_this_locale()
9
    {
10
        $translatedCountries = Country::translatedIn('fr')->get();
11
        $this->assertEquals($translatedCountries->count(), 1);
12
    }
13
14
    public function test_translated_in_scope_works_with_default_locale()
15
    {
16
        App::setLocale('de');
17
        $translatedCountries = Country::translatedIn()->get();
18
19
        $this->assertSame($translatedCountries->count(), 1);
20
        $this->assertSame('Griechenland', $translatedCountries->first()->name);
21
    }
22
23 View Code Duplication
    public function test_not_translated_in_scope_returns_only_not_translated_records_for_this_locale()
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...
24
    {
25
        $notTranslatedCountries = Country::notTranslatedIn('en')->get();
26
        $this->assertCount(2, $notTranslatedCountries);
27
28
        foreach ($notTranslatedCountries as $notTranslatedCountry) {
29
            $this->assertFalse($notTranslatedCountry->hasTranslation('en'));
30
        }
31
    }
32
33 View Code Duplication
    public function test_not_translated_in_scope_works_with_default_locale()
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...
34
    {
35
        App::setLocale('en');
36
        $notTranslatedCountries = Country::notTranslatedIn()->get();
37
        $this->assertCount(2, $notTranslatedCountries);
38
39
        foreach ($notTranslatedCountries as $notTranslatedCountry) {
40
            $this->assertFalse($notTranslatedCountry->hasTranslation('en'));
41
        }
42
    }
43
44
    public function test_translated_scope_returns_records_with_at_least_one_translation()
45
    {
46
        $translatedCountries = Country::translated()->get();
47
        $this->assertEquals($translatedCountries->count(), 2);
48
    }
49
50
    public function test_lists_of_translated_fields()
51
    {
52
        App::setLocale('de');
53
        App::make('config')->set('translatable.to_array_always_loads_translations', false);
54
55
        $arr = Country::listsTranslations('name')->get()->toArray();
56
57
        $this->assertEquals(1, count($arr));
58
        $this->assertEquals('1', $arr[0]['id']);
59
        $this->assertEquals('Griechenland', $arr[0]['name']);
60
    }
61
62
    public function test_lists_of_translated_fields_with_fallback()
63
    {
64
        App::make('config')->set('translatable.fallback_locale', 'en');
65
        App::make('config')->set('translatable.to_array_always_loads_translations', false);
66
        App::setLocale('de');
67
        $country = new Country();
68
        $country->useTranslationFallback = true;
69
        $list = [[
0 ignored issues
show
$list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
            'id'   => 1,
71
            'name' => 'Griechenland',
72
        ], [
73
            'id'   => 2,
74
            'name' => 'France',
75
        ]];
76
77
        $arr = $country->listsTranslations('name')->get()->toArray();
78
79
        $this->assertEquals(2, count($arr));
80
81
        $this->assertEquals(1, $arr[0]['id']);
82
        $this->assertEquals('Griechenland', $arr[0]['name']);
83
84
        $this->assertEquals(2, $arr[1]['id']);
85
        $this->assertEquals('France', $arr[1]['name']);
86
    }
87
88
    public function test_lists_of_translated_fields_disable_autoload_translations()
89
    {
90
        App::setLocale('de');
91
        App::make('config')->set('translatable.to_array_always_loads_translations', true);
92
93
        $list = [[
94
            'id'   => 1,
95
            'name' => 'Griechenland',
96
        ]];
97
        Country::disableAutoloadTranslations();
98
        $this->assertEquals($list, Country::listsTranslations('name')->get()->toArray());
99
        Country::defaultAutoloadTranslations();
100
    }
101
102
    public function test_scope_withTranslation_without_fallback()
103
    {
104
        $result = Country::withTranslation()->first();
105
        $loadedTranslations = $result->toArray()['translations'];
106
        $this->assertCount(1, $loadedTranslations);
107
        $this->assertSame('Greece', $loadedTranslations[0]['name']);
108
    }
109
110
    public function test_scope_withTranslation_with_fallback()
111
    {
112
        App::make('config')->set('translatable.fallback_locale', 'de');
113
        App::make('config')->set('translatable.use_fallback', true);
114
115
        $result = Country::withTranslation()->first();
116
        $loadedTranslations = $result->toArray()['translations'];
117
        $this->assertCount(2, $loadedTranslations);
118
        $this->assertSame('Greece', $loadedTranslations[0]['name']);
119
        $this->assertSame('Griechenland', $loadedTranslations[1]['name']);
120
    }
121
122
    public function test_scope_withTranslation_with_country_based_fallback()
123
    {
124
        App::make('config')->set('translatable.fallback_locale', 'en');
125
        App::make('config')->set('translatable.use_fallback', true);
126
        App::setLocale('en-GB');
127
        $result = Vegetable::withTranslation()->find(1)->toArray();
128
        $this->assertSame('courgette', $result['name']);
129
130
        App::setLocale('de-CH');
131
        $result = Vegetable::withTranslation()->find(1)->toArray();
132
        $expectedTranslations = [
0 ignored issues
show
$expectedTranslations is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
133
            ['name' => 'zucchini', 'locale' => 'en'],
134
            ['name' => 'Zucchini', 'locale' => 'de'],
135
            ['name' => 'Zucchetti', 'locale' => 'de-CH'],
136
        ];
137
        $translations = $result['translations'];
138
139
        $this->assertEquals(3, count($translations));
140
141
        $this->assertEquals('en', $translations[0]['locale']);
142
        $this->assertEquals('zucchini', $translations[0]['name']);
143
144
        $this->assertEquals('de', $translations[1]['locale']);
145
        $this->assertEquals('Zucchini', $translations[1]['name']);
146
147
        $this->assertEquals('de-CH', $translations[2]['locale']);
148
        $this->assertEquals('Zucchetti', $translations[2]['name']);
149
    }
150
151
    public function test_whereTranslation_filters_by_translation()
152
    {
153
        /** @var Country $country */
154
        $country = Country::whereTranslation('name', 'Greece')->first();
155
        $this->assertSame('gr', $country->code);
156
    }
157
158 View Code Duplication
    public function test_orWhereTranslation_filters_by_translation()
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...
159
    {
160
        $result = Country::whereTranslation('name', 'Greece')->orWhereTranslation('name', 'France')->get();
161
        $this->assertCount(2, $result);
162
        $this->assertSame('Greece', $result[0]->name);
163
        $this->assertSame('France', $result[1]->name);
164
    }
165
166 View Code Duplication
    public function test_whereTranslation_filters_by_translation_and_locale()
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...
167
    {
168
        Country::create(['code' => 'some-code', 'name' => 'Griechenland']);
169
170
        $this->assertSame(2, Country::whereTranslation('name', 'Griechenland')->count());
171
172
        $result = Country::whereTranslation('name', 'Griechenland', 'de')->get();
173
        $this->assertSame(1, $result->count());
174
        $this->assertSame('gr', $result->first()->code);
175
    }
176
177
    public function test_whereTranslationLike_filters_by_translation()
178
    {
179
        /** @var Country $country */
180
        $country = Country::whereTranslationLike('name', '%Greec%')->first();
181
        $this->assertSame('gr', $country->code);
182
    }
183
184 View Code Duplication
    public function test_orWhereTranslationLike_filters_by_translation()
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...
185
    {
186
        $result = Country::whereTranslationLike('name', '%eece%')->orWhereTranslationLike('name', '%ance%')->get();
187
        $this->assertCount(2, $result);
188
        $this->assertSame('Greece', $result[0]->name);
189
        $this->assertSame('France', $result[1]->name);
190
    }
191
192 View Code Duplication
    public function test_whereTranslationLike_filters_by_translation_and_locale()
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...
193
    {
194
        Country::create(['code' => 'some-code', 'name' => 'Griechenland']);
195
196
        $this->assertSame(2, Country::whereTranslationLike('name', 'Griechen%')->count());
197
198
        $result = Country::whereTranslationLike('name', '%riechenlan%', 'de')->get();
199
        $this->assertSame(1, $result->count());
200
        $this->assertSame('gr', $result->first()->code);
201
    }
202
203
    public function test_orderByTranslation_sorts_by_key_asc()
204
    {
205
        $result = Country::orderByTranslation('name')->get();
206
        $this->assertSame(2, $result->first()->id);
207
    }
208
209
    public function test_orderByTranslation_sorts_by_key_desc()
210
    {
211
        $result = Country::orderByTranslation('name', 'desc')->get();
212
        $this->assertSame(1, $result->first()->id);
213
    }
214
}
215