Skip to content

Commit 3f80d7c

Browse files
committed
Refactoring conditional statement.
Update change log.
1 parent dd49252 commit 3f80d7c

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to `laravel-ip-gateway` will be documented in this file.
44

5+
## 2.1.0 - 2023-06-19
6+
7+
- Code refactoring - remove unnecessary conditions.
8+
9+
## 2.0.0 - 2023-04-12
10+
11+
- Code refactoring and version upgrade.
12+
513
## 1.0.0 - 2018-01-10
614

7-
- First release
15+
- First release

src/IpGatewayProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ class IpGatewayProvider extends ServiceProvider
2020
public function boot()
2121
{
2222
$router = $this->app['router'];
23-
24-
if (config('ip-gateway')) {
25-
foreach (config('ip-gateway.middleware') as $middlewareName) {
26-
$router->pushMiddlewareToGroup($middlewareName, IpGatewayMiddleware::class);
27-
}
23+
foreach (config('ip-gateway.middleware') as $middlewareName) {
24+
$router->pushMiddlewareToGroup($middlewareName, IpGatewayMiddleware::class);
2825
}
2926
}
3027

@@ -50,6 +47,5 @@ public function publishFiles()
5047
foreach ($publishableFiles as $storedPath => $publishPath) {
5148
$this->publishes([$storedPath => $publishPath]);
5249
}
53-
5450
}
5551
}

src/Middleware/IpGatewayMiddleware.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class IpGatewayMiddleware
2020
/**
2121
* Handle an incoming request.
2222
*
23-
* @param \Illuminate\Http\Request $request
24-
* @param \Closure $next
25-
*
23+
* @param $request
24+
* @param Closure $next
2625
* @return mixed
2726
*/
2827
public function handle($request, Closure $next)
@@ -33,7 +32,7 @@ public function handle($request, Closure $next)
3332
$enableBlacklist = config('ip-gateway.enable_blacklist') === true;
3433
$redirectRoute = config('ip-gateway.redirect_route_to');
3534

36-
if (config('ip-gateway') && config('ip-gateway.enable_package') === true) {
35+
if (config('ip-gateway.enable_package') === true) { // Check if package status is enable.
3736
foreach ($getClientIps as $ip) {
3837
if ($enableBlacklist && $this->grantIpAddress($ip)) { // Its check blacklisted ip-addresses from ip-config file.
3938
$prohibitRequest = true;
@@ -43,18 +42,18 @@ public function handle($request, Closure $next)
4342
Log::warning($ip . ' IP address has tried to access.');
4443
}
4544
}
46-
}
4745

48-
if ($prohibitRequest) {
49-
return redirect($redirectRoute != '' ? $redirectRoute : '/404');
46+
if ($prohibitRequest) {
47+
return redirect($redirectRoute != '' ? $redirectRoute : '/404');
48+
}
5049
}
5150

5251
return $next($request);
5352

5453
} catch (\Exception $ex) {
5554
Log::error('Problem occurred while handle an incoming request '.$ex->getMessage());
55+
return redirect('/404');
5656
}
57-
5857
}
5958

6059
/**
@@ -65,7 +64,6 @@ public function handle($request, Closure $next)
6564
*/
6665
protected function grantIpAddress(string $ip) : bool
6766
{
68-
$this->ipList = config('ip-gateway.ip-list');
69-
return in_array($ip, $this->ipList);
67+
return in_array($ip, config('ip-gateway.ip-list'));
7068
}
7169
}

0 commit comments

Comments
 (0)