Skip to content

Commit 2685fa5

Browse files
feat(*): Use namespace to avoid class confilcts with other third party code (#149)
1 parent 5d11f87 commit 2685fa5

File tree

11 files changed

+30
-6
lines changed

11 files changed

+30
-6
lines changed

inc/Bouncer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
namespace CrowdSecWordPressBouncer;
6+
47
use CrowdSec\RemediationEngine\CacheStorage\CacheStorageException;
58
use CrowdSec\RemediationEngine\LapiRemediation;
69
use CrowdSec\Common\Logger\FileLog;

inc/Constants.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
namespace CrowdSecWordPressBouncer;
6+
57
use CrowdSecBouncer\Constants as LibConstants;
68

79
/**

inc/admin/advanced-settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3+
use CrowdSecWordPressBouncer\AdminNotice;
4+
use CrowdSecWordPressBouncer\Constants;
5+
use CrowdSecWordPressBouncer\Bouncer;
36
use CrowdSecBouncer\BouncerException;
47
use CrowdSec\RemediationEngine\Constants as RemConstants;
58
use IPLib\Factory;
9+
610
require_once __DIR__ . '/../Constants.php';
711
require_once __DIR__ . '/../options-config.php';
812
require_once __DIR__ . '/notice.php';

inc/admin/init.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22

3+
use CrowdSecWordPressBouncer\Constants;
34
use CrowdSecBouncer\BouncerException;
45
use CrowdSec\RemediationEngine\Geolocation;
6+
use CrowdSecWordPressBouncer\AdminNotice;
7+
use CrowdSecWordPressBouncer\Bouncer;
58

69
require_once __DIR__ . '/notice.php';
710
require_once __DIR__ . '/../Constants.php';
@@ -222,7 +225,7 @@ function testGeolocationInAdminPage($ip)
222225
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_test_connection')) {
223226
die('This link expired.');
224227
}
225-
$ip = isset($_POST['crowdsec_test_connection_ip']) ? $_POST['crowdsec_test_connection_ip'] : $_SERVER['REMOTE_ADDR'];
228+
$ip = $_POST['crowdsec_test_connection_ip'] ?? $_SERVER['REMOTE_ADDR'];
226229
testBouncerConnexionInAdminPage($ip);
227230
header("Location: {$_SERVER['HTTP_REFERER']}");
228231
exit(0);
@@ -233,7 +236,7 @@ function testGeolocationInAdminPage($ip)
233236
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_test_geolocation')) {
234237
die('This link expired.');
235238
}
236-
$ip = isset($_POST['crowdsec_test_geolocation_ip']) ? $_POST['crowdsec_test_geolocation_ip'] : $_SERVER['REMOTE_ADDR'];
239+
$ip = $_POST['crowdsec_test_geolocation_ip'] ?? $_SERVER['REMOTE_ADDR'];
237240
testGeolocationInAdminPage($ip);
238241
header("Location: {$_SERVER['HTTP_REFERER']}");
239242
exit(0);

inc/admin/notice.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
namespace CrowdSecWordPressBouncer;
4+
35
class AdminNotice
46
{
57
const NOTICE_FIELD = 'crowdsec_admin_notice_message';
68

79
public function displayAdminNotice()
810
{
911
$option = is_multisite() ? get_site_option(self::NOTICE_FIELD) : get_option(self::NOTICE_FIELD);
10-
$message = isset($option['message']) ? $option['message'] : false;
12+
$message = $option['message'] ?? false;
1113
$noticeLevel = !empty($option['notice-level']) ? $option['notice-level'] : 'notice-error';
1214

1315
if ($message) {

inc/admin/settings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
require_once __DIR__ . '/../Constants.php';
3+
use CrowdSecWordPressBouncer\Constants;
4+
35

46
function adminSettings()
57
{

inc/bounce-current-ip.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
require_once __DIR__ . '/Constants.php';
77
require_once __DIR__ . '/options-config.php';
88

9+
use CrowdSecWordPressBouncer\Constants;
10+
use CrowdSecWordPressBouncer\Bouncer;
911
use CrowdSecBouncer\BouncerException;
1012
use Psr\Cache\CacheException;
1113

inc/options-config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
require_once __DIR__ . '/Constants.php';
3+
use CrowdSecWordPressBouncer\Constants;
4+
35

46
function getCrowdSecOptionsConfig(): array
57
{

inc/plugin-setup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use CrowdSecWordPressBouncer\Constants;
4+
35
require_once __DIR__.'/options-config.php';
46
require_once __DIR__ . '/Constants.php';
57

inc/scheduling.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use CrowdSecWordPressBouncer\Bouncer;
4+
25
require_once __DIR__ . '/options-config.php';
36
require_once __DIR__ . '/Bouncer.php';
47

0 commit comments

Comments
 (0)