Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit d02b597

Browse files
authored
Merge pull request #7 from fryiee/psr-fixes
Fix typehinting causing error and PSR fixes.
2 parents 097f7b2 + 1b3d1e9 commit d02b597

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

src/LanguageSwitcher/Command/RenderLanguageSwitcher.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Filesystem\Filesystem;
99

10+
/**
11+
* Class RenderLanguageSwitcher
12+
* @package Wirelab\LanguageSwitcherPlugin\LanguageSwitcher\Command
13+
*/
1014
class RenderLanguageSwitcher
1115
{
1216
use DispatchesJobs;
1317

18+
/**
19+
* @var string
20+
*/
1421
private $type;
22+
23+
/**
24+
* @var Filesystem
25+
*/
1526
private $filesystem;
16-
public $options;
1727

18-
public function __construct(String $type, Array $options)
28+
/**
29+
* @var array
30+
*/
31+
public $options;
32+
33+
/**
34+
* RenderLanguageSwitcher constructor.
35+
* @param string $type
36+
* @param array $options
37+
*/
38+
public function __construct(string $type, array $options)
1939
{
2040
// Set type and filesystem
2141
$this->type = $type;
@@ -31,7 +51,6 @@ public function __construct(String $type, Array $options)
3151
'a_class' => $options['a_class'] ?? '',
3252
'pecl' => $options['pecl'] ?? true
3353
];
34-
3554
}
3655

3756

@@ -40,7 +59,8 @@ public function __construct(String $type, Array $options)
4059
* @return string
4160
* @throws Exception
4261
*/
43-
protected function findViewFolder() {
62+
protected function findViewFolder()
63+
{
4464
$composer_folder = base_path() . '/core/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin using composer
4565
$manual_folder = base_path() . '/addons/' . env('APPLICATION_REFERENCE') . '/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin manually
4666
$published_folder = base_path() . '/resources' . env('APPLICATION_REFERENCE') . 'addons/wirelab/language_switcher-plugin/views'; // The locations of the views if the user published the views
@@ -50,24 +70,27 @@ protected function findViewFolder() {
5070

5171
// Loop trough targets and see if the folder exists
5272
foreach ($targets as $target) {
53-
54-
if( $this->filesystem->exists($target) ) {
73+
if ($this->filesystem->exists($target)) {
5574
return (string) $target;
5675
};
5776
}
5877

5978
// If we can't find it throw a new exception
6079
throw new Exception("[language_switcher-plugin] Couldn't find view folder.");
61-
6280
}
6381

6482

83+
/**
84+
* @param SettingRepositoryInterface $settings
85+
* @param Request $request
86+
* @param Repository $config
87+
* @return mixed
88+
*/
6589
public function handle(
6690
SettingRepositoryInterface $settings,
6791
Request $request,
68-
Repository $config)
69-
{
70-
92+
Repository $config
93+
) {
7194
$locales = $settings->value('streams::enabled_locales'); // Get an array of all currently enables locales.
7295
$current_path = $request->path(); // Get the current request path. For example /pages/some-page-title
7396
$current_locale = $config->get('app.locale'); // Get the current request locale.
@@ -79,12 +102,12 @@ public function handle(
79102
$custom_title = $this->options['toggle_title'] != false; // Check if the user has set a custom title. Used in building the ul of locales
80103

81104
// Loopps trough the views
82-
foreach ($this->filesystem->allFiles($this->findViewFolder()) as $file){
105+
foreach ($this->filesystem->allFiles($this->findViewFolder()) as $file) {
83106
// Use the names of the views as networks
84107
$types[] = $file->getBaseName('.' . $file->getExtension());
85108
}
86109

87-
if(($key = array_search($current_locale, $locales)) !== false && !$custom_title) {
110+
if (($key = array_search($current_locale, $locales)) !== false && !$custom_title) {
88111
// If the user has not set a button title we're going to use the currently enabled locale as title
89112
// here we unset it to prevent the locale from showing up both as a list item and title
90113
unset($locales[$key]);

src/LanguageSwitcherPlugin.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php namespace Wirelab\LanguageSwitcherPlugin;
22

3-
43
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
54
use Wirelab\LanguageSwitcherPlugin\LanguageSwitcher\Command\RenderLanguageSwitcher;
65

6+
/**
7+
* Class LanguageSwitcherPlugin
8+
* @package Wirelab\LanguageSwitcherPlugin
9+
*/
710
class LanguageSwitcherPlugin extends Plugin
811
{
912

@@ -26,5 +29,4 @@ function ($type = "dropdown", $options = []) {
2629
)
2730
];
2831
}
29-
3032
}

src/LanguageSwitcherPluginServiceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
44

5+
/**
6+
* Class LanguageSwitcherPluginServiceProvider
7+
* @package Wirelab\LanguageSwitcherPlugin
8+
*/
59
class LanguageSwitcherPluginServiceProvider extends AddonServiceProvider
610
{
711

12+
/**
13+
* @var array
14+
*/
815
protected $plugins = [
916
'Wirelab\LanguageSwitcherPlugin\LanguageSwitcherPlugin'
1017
];
11-
1218
}

0 commit comments

Comments
 (0)