Skip to content

Commit 4e019fa

Browse files
authored
Merge pull request #21 from kg-bot/analysis-8nwZLy
Apply fixes from StyleCI
2 parents 635d30c + 2178e3f commit 4e019fa

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

src/Classes/ExportLocalizations.php

+72-72
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ExportLocalizations implements \JsonSerializable
3131
/**
3232
* @var string
3333
*/
34-
protected $excludePath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR;
34+
protected $excludePath = DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR;
3535

3636
/**
3737
* @var string
@@ -46,30 +46,30 @@ class ExportLocalizations implements \JsonSerializable
4646
public function export()
4747
{
4848
// Check if value is cached and set array to cached version
49-
if ( Cache::has( config( 'laravel-localization.caches.key' ) ) ) {
50-
$this->strings = Cache::get( config( 'laravel-localization.caches.key' ) );
49+
if (Cache::has(config('laravel-localization.caches.key'))) {
50+
$this->strings = Cache::get(config('laravel-localization.caches.key'));
5151

5252
return $this;
5353
}
5454

5555
// Collect language files and build array with translations
56-
$files = $this->findLanguageFiles( resource_path( 'lang' ) );
56+
$files = $this->findLanguageFiles(resource_path('lang'));
5757

5858
// Parse translations and create final array
59-
array_walk( $files[ 'lang' ], [ $this, 'parseLangFiles' ] );
60-
array_walk( $files[ 'vendor' ], [ $this, 'parseVendorFiles' ] );
61-
array_walk( $files[ 'json' ], [ $this, 'parseJsonFiles' ] );
59+
array_walk($files['lang'], [$this, 'parseLangFiles']);
60+
array_walk($files['vendor'], [$this, 'parseVendorFiles']);
61+
array_walk($files['json'], [$this, 'parseJsonFiles']);
6262

6363
// Trigger event for final translated array
64-
event( new LaravelLocalizationExported( $this->strings ) );
64+
event(new LaravelLocalizationExported($this->strings));
6565

6666
// If timeout > 0 save array to cache
67-
if ( config( 'laravel-localization.caches.timeout', 0 ) > 0 ) {
68-
Cache::store( config( 'laravel-localization.caches.driver', 'file' ) )
67+
if (config('laravel-localization.caches.timeout', 0) > 0) {
68+
Cache::store(config('laravel-localization.caches.driver', 'file'))
6969
->put(
70-
config( 'laravel-localization.caches.key', 'localization.array' ),
70+
config('laravel-localization.caches.key', 'localization.array'),
7171
$this->strings,
72-
config( 'laravel-localization.caches.timeout', 60 )
72+
config('laravel-localization.caches.timeout', 60)
7373
);
7474
}
7575

@@ -83,58 +83,58 @@ public function export()
8383
*
8484
* @return array
8585
*/
86-
protected function findLanguageFiles( $path )
86+
protected function findLanguageFiles($path)
8787
{
8888
// Loop through directories
89-
$dirIterator = new \RecursiveDirectoryIterator( $path, \RecursiveDirectoryIterator::SKIP_DOTS );
90-
$recIterator = new \RecursiveIteratorIterator( $dirIterator );
89+
$dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
90+
$recIterator = new \RecursiveIteratorIterator($dirIterator);
9191

9292
// Fetch only php files - skip others
9393
$phpFiles = array_values(
94-
array_map( 'current',
94+
array_map('current',
9595
iterator_to_array(
96-
new \RegexIterator( $recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH )
96+
new \RegexIterator($recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH)
9797
)
9898
)
9999
);
100100

101101
$jsonFiles = array_values(
102-
array_map( 'current',
102+
array_map('current',
103103
iterator_to_array(
104-
new \RegexIterator( $recIterator, $this->jsonRegex, \RecursiveRegexIterator::GET_MATCH )
104+
new \RegexIterator($recIterator, $this->jsonRegex, \RecursiveRegexIterator::GET_MATCH)
105105
)
106106
)
107107
);
108108

109-
$files = array_merge( $phpFiles, $jsonFiles );
109+
$files = array_merge($phpFiles, $jsonFiles);
110110

111111
// Sort array by filepath
112-
sort( $files );
112+
sort($files);
113113

114114
// Remove full path from items
115-
array_walk( $files, function ( &$item ) {
116-
$item = str_replace( resource_path( 'lang' ), '', $item );
117-
} );
115+
array_walk($files, function (&$item) {
116+
$item = str_replace(resource_path('lang'), '', $item);
117+
});
118118

119119
// Fetch non-vendor files from filtered php files
120-
$nonVendorFiles = array_filter( $files, function ( $file ) {
121-
return strpos( $file, $this->excludePath ) === false && strpos( $file, '.json' ) === false;
122-
} );
120+
$nonVendorFiles = array_filter($files, function ($file) {
121+
return strpos($file, $this->excludePath) === false && strpos($file, '.json') === false;
122+
});
123123

124124
// Fetch vendor files from filtered php files
125-
$vendorFiles = array_filter( array_diff( $files, $nonVendorFiles ), function ( $file ) {
126-
return strpos( $file, 'json' ) === false;
127-
} );
125+
$vendorFiles = array_filter(array_diff($files, $nonVendorFiles), function ($file) {
126+
return strpos($file, 'json') === false;
127+
});
128128

129129
// Fetch .json files from filtered files
130-
$jsonFiles = array_filter( $files, function ( $file ) {
131-
return strpos( $file, '.json' ) !== false;
132-
} );
130+
$jsonFiles = array_filter($files, function ($file) {
131+
return strpos($file, '.json') !== false;
132+
});
133133

134134
return [
135-
'lang' => array_values( $nonVendorFiles ),
136-
'vendor' => array_values( $vendorFiles ),
137-
'json' => array_values( $jsonFiles ),
135+
'lang' => array_values($nonVendorFiles),
136+
'vendor' => array_values($vendorFiles),
137+
'json' => array_values($jsonFiles),
138138
];
139139
}
140140

@@ -167,22 +167,22 @@ public function toArray()
167167
*
168168
* @return array
169169
*/
170-
public function toFlat( $prefix = '.' )
170+
public function toFlat($prefix = '.')
171171
{
172172
$results = [];
173-
foreach ( $this->strings as $lang => $strings ) {
174-
if ( $lang !== 'json' ) {
175-
foreach ( $strings as $lang_array => $lang_messages ) {
176-
$key = $lang . $prefix . $lang_array;
177-
$results[ $key ] = $lang_messages;
173+
foreach ($this->strings as $lang => $strings) {
174+
if ($lang !== 'json') {
175+
foreach ($strings as $lang_array => $lang_messages) {
176+
$key = $lang.$prefix.$lang_array;
177+
$results[$key] = $lang_messages;
178178
}
179179
} else {
180-
foreach ( $strings as $json_lang => $json_strings ) {
181-
$key = $json_lang . $prefix . '__JSON__';
182-
if ( array_key_exists( $key, $results ) ) {
183-
$results[ $key ] = $json_strings;
180+
foreach ($strings as $json_lang => $json_strings) {
181+
$key = $json_lang.$prefix.'__JSON__';
182+
if (array_key_exists($key, $results)) {
183+
$results[$key] = $json_strings;
184184
} else {
185-
$results[ $key ] = $json_strings;
185+
$results[$key] = $json_strings;
186186
}
187187
}
188188
}
@@ -198,29 +198,29 @@ public function toFlat( $prefix = '.' )
198198
*/
199199
public function toCollection()
200200
{
201-
return collect( $this->strings );
201+
return collect($this->strings);
202202
}
203203

204204
/**
205205
* Method to parse language files.
206206
*
207207
* @param string $file
208208
*/
209-
protected function parseLangFiles( $file )
209+
protected function parseLangFiles($file)
210210
{
211211
// Base package name without file ending
212-
$packageName = basename( $file, '.php' );
212+
$packageName = basename($file, '.php');
213213

214214
// Get package, language and file contents from language file
215215
// /<language_code>/(<package/)<filename>.php
216-
$language = explode( DIRECTORY_SEPARATOR, $file )[ 1 ];
217-
$fileContents = require resource_path( 'lang' ) . DIRECTORY_SEPARATOR . $file;
216+
$language = explode(DIRECTORY_SEPARATOR, $file)[1];
217+
$fileContents = require resource_path('lang').DIRECTORY_SEPARATOR.$file;
218218

219219
// Check if language already exists in array
220-
if ( array_key_exists( $language, $this->strings ) ) {
221-
$this->strings[ $language ][ $packageName ] = $fileContents;
220+
if (array_key_exists($language, $this->strings)) {
221+
$this->strings[$language][$packageName] = $fileContents;
222222
} else {
223-
$this->strings[ $language ] = [
223+
$this->strings[$language] = [
224224
$packageName => $fileContents,
225225
];
226226
}
@@ -231,27 +231,27 @@ protected function parseLangFiles( $file )
231231
*
232232
* @param string $file
233233
*/
234-
protected function parseVendorFiles( $file )
234+
protected function parseVendorFiles($file)
235235
{
236236
// Base package name without file ending
237-
$packageName = basename( $file, '.php' );
237+
$packageName = basename($file, '.php');
238238

239239
// Get package, language and file contents from language file
240240
// /vendor/<package>/<language_code>/<filename>.php
241-
$package = explode( DIRECTORY_SEPARATOR, $file )[ 2 ];
242-
$language = explode( DIRECTORY_SEPARATOR, $file )[ 3 ];
243-
$fileContents = require resource_path( 'lang' ) . DIRECTORY_SEPARATOR . $file;
241+
$package = explode(DIRECTORY_SEPARATOR, $file)[2];
242+
$language = explode(DIRECTORY_SEPARATOR, $file)[3];
243+
$fileContents = require resource_path('lang').DIRECTORY_SEPARATOR.$file;
244244

245245
// Check if language already exists in array
246-
if ( array_key_exists( $language, $this->strings ) ) {
246+
if (array_key_exists($language, $this->strings)) {
247247
// Check if package already exists in language
248-
if ( array_key_exists( $package, $this->strings[ $language ] ) ) {
249-
$this->strings[ $language ][ $package ][ $packageName ] = $fileContents;
248+
if (array_key_exists($package, $this->strings[$language])) {
249+
$this->strings[$language][$package][$packageName] = $fileContents;
250250
} else {
251-
$this->strings[ $language ][ $package ] = [ $packageName => $fileContents ];
251+
$this->strings[$language][$package] = [$packageName => $fileContents];
252252
}
253253
} else {
254-
$this->strings[ $language ] = [
254+
$this->strings[$language] = [
255255

256256
$package => [
257257

@@ -261,22 +261,22 @@ protected function parseVendorFiles( $file )
261261
}
262262
}
263263

264-
protected function parseJsonFiles( $file )
264+
protected function parseJsonFiles($file)
265265
{
266266
// Base package name without file ending
267-
$language = basename( $file, '.json' );
267+
$language = basename($file, '.json');
268268

269269
// Get package, language and file contents from language file
270270
// /<language_code>/(<package/)<filename>.php
271-
$fileContents = json_decode( file_get_contents( resource_path( 'lang' ) . $file ) );
271+
$fileContents = json_decode(file_get_contents(resource_path('lang').$file));
272272

273273
// Check if language already exists in array
274-
if ( array_key_exists( 'json', $this->strings ) ) {
275-
if ( array_key_exists( $language, $this->strings[ 'json' ] ) ) {
276-
$this->strings[ 'json' ][ $language ] = $fileContents;
274+
if (array_key_exists('json', $this->strings)) {
275+
if (array_key_exists($language, $this->strings['json'])) {
276+
$this->strings['json'][$language] = $fileContents;
277277
}
278278
} else {
279-
$this->strings[ 'json' ] = [
279+
$this->strings['json'] = [
280280

281281
$language => $fileContents,
282282
];

0 commit comments

Comments
 (0)