Skip to content

Commit ed95caf

Browse files
authored
Merge pull request #8 from kg-bot/analysis-XkVDGa
Apply fixes from StyleCI
2 parents e2c4cf9 + 390ea31 commit ed95caf

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

src/Classes/ExportLocalizations.php

+49-52
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExportLocalizations implements \JsonSerializable
2626
/**
2727
* @var string
2828
*/
29-
protected $excludePath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR;
29+
protected $excludePath = DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR;
3030

3131
/**
3232
* @var string
@@ -41,29 +41,29 @@ class ExportLocalizations implements \JsonSerializable
4141
public function export()
4242
{
4343
// Check if value is cached and set array to cached version
44-
if ( Cache::has( config( 'laravel-localization.caches.key' ) ) ) {
45-
$this->strings = Cache::get( config( 'laravel-localization.caches.key' ) );
44+
if (Cache::has(config('laravel-localization.caches.key'))) {
45+
$this->strings = Cache::get(config('laravel-localization.caches.key'));
4646

4747
return $this;
4848
}
4949

5050
// Collect language files and build array with translations
51-
$files = $this->findLanguageFiles( resource_path( 'lang' ) );
51+
$files = $this->findLanguageFiles(resource_path('lang'));
5252

5353
// Parse translations and create final array
54-
array_walk( $files[ 'lang' ], [ $this, 'parseLangFiles' ] );
55-
array_walk( $files[ 'vendor' ], [ $this, 'parseVendorFiles' ] );
54+
array_walk($files['lang'], [$this, 'parseLangFiles']);
55+
array_walk($files['vendor'], [$this, 'parseVendorFiles']);
5656

5757
// Trigger event for final translated array
58-
event( new LaravelLocalizationExported( $this->strings ) );
58+
event(new LaravelLocalizationExported($this->strings));
5959

6060
// If timeout > 0 save array to cache
61-
if ( config( 'laravel-localization.caches.timeout', 0 ) > 0 ) {
62-
Cache::store( config( 'laravel-localization.caches.driver', 'file' ) )
61+
if (config('laravel-localization.caches.timeout', 0) > 0) {
62+
Cache::store(config('laravel-localization.caches.driver', 'file'))
6363
->put(
64-
config( 'laravel-localization.caches.key', 'localization.array' ),
64+
config('laravel-localization.caches.key', 'localization.array'),
6565
$this->strings,
66-
config( 'laravel-localization.caches.timeout', 60 )
66+
config('laravel-localization.caches.timeout', 60)
6767
);
6868
}
6969

@@ -77,40 +77,40 @@ public function export()
7777
*
7878
* @return array
7979
*/
80-
protected function findLanguageFiles( $path )
80+
protected function findLanguageFiles($path)
8181
{
8282
// Loop through directories
83-
$dirIterator = new \RecursiveDirectoryIterator( $path, \RecursiveDirectoryIterator::SKIP_DOTS );
84-
$recIterator = new \RecursiveIteratorIterator( $dirIterator );
83+
$dirIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
84+
$recIterator = new \RecursiveIteratorIterator($dirIterator);
8585

8686
// Fetch only php files - skip others
8787
$phpFiles = array_values(
88-
array_map( 'current',
88+
array_map('current',
8989
iterator_to_array(
90-
new \RegexIterator( $recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH )
90+
new \RegexIterator($recIterator, $this->phpRegex, \RecursiveRegexIterator::GET_MATCH)
9191
)
9292
)
9393
);
9494

9595
// Sort array by filepath
96-
sort( $phpFiles );
96+
sort($phpFiles);
9797

9898
// Remove full path from items
99-
array_walk( $phpFiles, function ( &$item ) {
100-
$item = str_replace( resource_path( 'lang' ), '', $item );
101-
} );
99+
array_walk($phpFiles, function (&$item) {
100+
$item = str_replace(resource_path('lang'), '', $item);
101+
});
102102

103103
// Fetch non-vendor files from filtered php files
104-
$nonVendorFiles = array_filter( $phpFiles, function ( $file ) {
105-
return strpos( $file, $this->excludePath ) === false;
106-
} );
104+
$nonVendorFiles = array_filter($phpFiles, function ($file) {
105+
return strpos($file, $this->excludePath) === false;
106+
});
107107

108108
// Fetch vendor files from filtered php files
109-
$vendorFiles = array_diff( $phpFiles, $nonVendorFiles );
109+
$vendorFiles = array_diff($phpFiles, $nonVendorFiles);
110110

111111
return [
112-
'lang' => array_values( $nonVendorFiles ),
113-
'vendor' => array_values( $vendorFiles ),
112+
'lang' => array_values($nonVendorFiles),
113+
'vendor' => array_values($vendorFiles),
114114
];
115115
}
116116

@@ -143,13 +143,13 @@ public function toArray()
143143
*
144144
* @return array
145145
*/
146-
public function toFlat( $prefix = '.' )
146+
public function toFlat($prefix = '.')
147147
{
148148
$results = [];
149-
foreach ( $this->strings as $lang => $strings ) {
150-
foreach ( $strings as $lang_array => $lang_messages ) {
151-
$key = $lang . $prefix . $lang_array;
152-
$results[ $key ] = $lang_messages;
149+
foreach ($this->strings as $lang => $strings) {
150+
foreach ($strings as $lang_array => $lang_messages) {
151+
$key = $lang.$prefix.$lang_array;
152+
$results[$key] = $lang_messages;
153153
}
154154
}
155155

@@ -163,29 +163,29 @@ public function toFlat( $prefix = '.' )
163163
*/
164164
public function toCollection()
165165
{
166-
return collect( $this->strings );
166+
return collect($this->strings);
167167
}
168168

169169
/**
170170
* Method to parse language files.
171171
*
172172
* @param string $file
173173
*/
174-
protected function parseLangFiles( $file )
174+
protected function parseLangFiles($file)
175175
{
176176
// Base package name without file ending
177-
$packageName = basename( $file, '.php' );
177+
$packageName = basename($file, '.php');
178178

179179
// Get package, language and file contents from language file
180180
// /<language_code>/(<package/)<filename>.php
181-
$language = explode( DIRECTORY_SEPARATOR, $file )[ 1 ];
182-
$fileContents = require resource_path( 'lang' ) . DIRECTORY_SEPARATOR . $file;
181+
$language = explode(DIRECTORY_SEPARATOR, $file)[1];
182+
$fileContents = require resource_path('lang').DIRECTORY_SEPARATOR.$file;
183183

184184
// Check if language already exists in array
185-
if ( array_key_exists( $language, $this->strings ) ) {
186-
$this->strings[ $language ][ $packageName ] = $fileContents;
185+
if (array_key_exists($language, $this->strings)) {
186+
$this->strings[$language][$packageName] = $fileContents;
187187
} else {
188-
$this->strings[ $language ] = [
188+
$this->strings[$language] = [
189189
$packageName => $fileContents,
190190
];
191191
}
@@ -196,30 +196,27 @@ protected function parseLangFiles( $file )
196196
*
197197
* @param string $file
198198
*/
199-
protected function parseVendorFiles( $file )
199+
protected function parseVendorFiles($file)
200200
{
201201
// Base package name without file ending
202-
$packageName = basename( $file, '.php' );
202+
$packageName = basename($file, '.php');
203203

204204
// Get package, language and file contents from language file
205205
// /vendor/<package>/<language_code>/<filename>.php
206-
$package = explode( DIRECTORY_SEPARATOR, $file )[ 2 ];
207-
$language = explode( DIRECTORY_SEPARATOR, $file )[ 3 ];
208-
$fileContents = require resource_path( 'lang' ) . DIRECTORY_SEPARATOR . $file;
206+
$package = explode(DIRECTORY_SEPARATOR, $file)[2];
207+
$language = explode(DIRECTORY_SEPARATOR, $file)[3];
208+
$fileContents = require resource_path('lang').DIRECTORY_SEPARATOR.$file;
209209

210210
// Check if language already exists in array
211-
if ( array_key_exists( $language, $this->strings ) ) {
211+
if (array_key_exists($language, $this->strings)) {
212212
// Check if package already exists in language
213-
if ( array_key_exists( $package, $this->strings[ $language ] ) ) {
214-
215-
array_push( $this->strings[ $language ][ $package ], [ $packageName => $fileContents ] );
213+
if (array_key_exists($package, $this->strings[$language])) {
214+
array_push($this->strings[$language][$package], [$packageName => $fileContents]);
216215
} else {
217-
218-
$this->strings[ $language ][ $package ] = [ $packageName => $fileContents ];
216+
$this->strings[$language][$package] = [$packageName => $fileContents];
219217
}
220-
221218
} else {
222-
$this->strings[ $language ] = [
219+
$this->strings[$language] = [
223220

224221
$package => [
225222

0 commit comments

Comments
 (0)