Skip to content

Commit

Permalink
Merge pull request #2 from yemenifree/analysis-zY0eL9
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
salkhwlani authored Oct 4, 2017
2 parents 65f344a + c4f12f7 commit 3e18aab
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 34 deletions.
6 changes: 3 additions & 3 deletions config/arabic-numbers-middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| Supported Middleware: "arabic-to-eastern", "eastern-to-arabic"
*/
'auto_middleware' => [
Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformEasternToArabicNumbers::class
Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformEasternToArabicNumbers::class,
],

/*
Expand Down Expand Up @@ -59,5 +59,5 @@
*/
'except_from_arabic_to_eastern' => [
// 'mobile'
]
];
],
];
18 changes: 9 additions & 9 deletions src/Middleware/BaseNumbersMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(Repository $config)
}

/**
* get except fields
* get except fields.
*
* @return array
*/
Expand All @@ -40,7 +40,7 @@ public function getExcept()
}

/**
* get options from config
* get options from config.
* @param string $key
* @param null $default
* @return array
Expand All @@ -51,9 +51,9 @@ protected function getOption($key, $default = null)
}

/**
* check if transform from (arabic|english) to eastern
* check if transform from (arabic|english) to eastern.
*
* @return boolean
* @return bool
*/
public function isFromArabic()
{
Expand All @@ -77,7 +77,7 @@ protected function transform($key, $value)
}

/**
* transform eastern/(arabic|english) numbers to (arabic|english)/eastern numbers inside string
* transform eastern/(arabic|english) numbers to (arabic|english)/eastern numbers inside string.
*
* @param string $value
* @return string
Expand All @@ -88,7 +88,7 @@ protected function transformNumber($value)
}

/**
* get array numbers to transforms
* get array numbers to transforms.
*
* @return string
*/
Expand All @@ -98,17 +98,17 @@ protected function getNumbers()
}

/**
* check if transform from (arabic|english) to eastern
* check if transform from (arabic|english) to eastern.
*
* @return boolean
* @return bool
*/
public function isFromEastern()
{
return $this->from == 'eastern';
}

/**
* Get eastern numbers array
* Get eastern numbers array.
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/TransformArabicToEasternNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TransformArabicToEasternNumbers extends BaseNumbersMiddleware
protected $from = 'arabic';

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getExcept()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/TransformEasternToArabicNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TransformEasternToArabicNumbers extends BaseNumbersMiddleware
protected $from = 'eastern';

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getExcept()
{
Expand Down
21 changes: 11 additions & 10 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ServiceProvider extends BaseServiceProvider
*/
protected $middleware = [
'arabic-to-eastern' => TransformArabicToEasternNumbers::class,
'eastern-to-arabic' => TransformEasternToArabicNumbers::class
'eastern-to-arabic' => TransformEasternToArabicNumbers::class,
];

/**
* list of group middleware to auto append middleware to them
* list of group middleware to auto append middleware to them.
*
* true => all groups
* false => none
Expand All @@ -31,13 +31,12 @@ class ServiceProvider extends BaseServiceProvider
protected $groupMiddleware = false;

/**
* auto append middleware
* auto append middleware.
*
* @var Collection
*/
protected $auto_middleware;


/**
* Perform post-registration booting of services.
*
Expand All @@ -46,29 +45,31 @@ class ServiceProvider extends BaseServiceProvider
public function boot()
{
$this->publishes([
__DIR__ . '/../config/arabic-numbers-middleware.php' => config_path('arabic-numbers-middleware.php'),
__DIR__.'/../config/arabic-numbers-middleware.php' => config_path('arabic-numbers-middleware.php'),
], 'config');

$this->autoAppendMiddleware();
}

/**
* auto append middleware to router
* auto append middleware to router.
*
* @return Collection|bool
*/
protected function autoAppendMiddleware()
{
$this->groupMiddleware = $this->app['config']->get('arabic-numbers-middleware.auto_register_middleware', false);

if ($this->groupMiddleware === false)
if ($this->groupMiddleware === false) {
return false;
}

$this->auto_middleware = collect($this->app['config']->get('arabic-numbers-middleware.auto_middleware', []));

// Register as global Middleware
if ($this->groupMiddleware === true) {
$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');

return $this->auto_middleware->each(function ($middleware) use ($kernel) {
$kernel->pushMiddleware($middleware);
});
Expand All @@ -93,17 +94,17 @@ protected function autoAppendMiddleware()
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/arabic-numbers-middleware.php', 'arabic-numbers-middleware');
$this->mergeConfigFrom(__DIR__.'/../config/arabic-numbers-middleware.php', 'arabic-numbers-middleware');
$this->registerAliasMiddleware();
}

/**
* register alias middleware
* register alias middleware.
*/
protected function registerAliasMiddleware()
{
foreach ($this->middleware as $alias => $middleware) {
$this->app['router']->aliasMiddleware($alias, $middleware);
}
}
}
}
4 changes: 1 addition & 3 deletions tests/ArabicMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yemenifree\LaravelArabicNumbersMiddleware\Test;


use Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformArabicToEasternNumbers;

class ArabicMiddlewareTest extends TestCase
Expand Down Expand Up @@ -54,5 +53,4 @@ protected function getEnvironmentSetUp($app)
parent::getEnvironmentSetUp($app);
$app['config']->set('arabic-numbers-middleware.auto_middleware', TransformArabicToEasternNumbers::class);
}

}
}
4 changes: 1 addition & 3 deletions tests/EasternMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Yemenifree\LaravelArabicNumbersMiddleware\Test;


class EasternMiddlewareTest extends TestCase
{

/** @test */
public function it_will_transform_numbers_to_arabic_with_auto_append_middleware()
{
Expand Down Expand Up @@ -47,4 +45,4 @@ public function it_will_not_transform_numbers_to_arabic_without_auto_append_midd
$this->refreshApp();
$this->post('login-eastern-to-arabic-auto-append', $this->easternTestData)->assertExactJson($this->easternTestData);
}
}
}
8 changes: 4 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Yemenifree\LaravelArabicNumbersMiddleware\Test;

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Foundation\Application;
use Illuminate\Routing\RouteCollection;
use Orchestra\Testbench\TestCase as Orchestra;
use Yemenifree\LaravelArabicNumbersMiddleware\ServiceProvider;
Expand Down Expand Up @@ -31,15 +31,15 @@ protected function getPackageProviders($app)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('arabic-numbers-middleware.auto_register_middleware', $this->auto_register_middleware);
}

/**
* refresh (reboot) app
* refresh (reboot) app.
*
* because auto register middleware as global happen when boot app so if we need disabled it we need reboot app also
*/
Expand Down Expand Up @@ -80,4 +80,4 @@ protected function responseRequest()
return response()->json($request, 200, [], JSON_UNESCAPED_UNICODE);
};
}
}
}

0 comments on commit 3e18aab

Please sign in to comment.