Skip to content

Commit 7b78ed4

Browse files
style(*): Pass through Phpcs fixer
1 parent eff2fb1 commit 7b78ed4

File tree

10 files changed

+72
-79
lines changed

10 files changed

+72
-79
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
->setFinder(
2424
PhpCsFixer\Finder::create()
2525
->in(__DIR__.'/src')
26-
->in(__DIR__.'/tests')
26+
->in(__DIR__.'/tests')->depth(0)
2727
)
2828
;

src/AbstractBounce.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function getArraySettings(string $name): array
5252

5353
/**
5454
* Run a bounce.
55+
*
5556
* @throws Exception
5657
*/
5758
public function run(

src/ApiCache.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,14 @@ public function configure(
150150
*/
151151
private function getScopes(): ?array
152152
{
153-
if($this->scopes === null){
153+
if (null === $this->scopes) {
154154
$scopes = [Constants::SCOPE_IP, Constants::SCOPE_RANGE];
155155
if (!empty($this->geolocConfig['enabled'])) {
156-
$scopes[] = Constants::SCOPE_COUNTRY;
156+
$scopes[] = Constants::SCOPE_COUNTRY;
157157
}
158158
$this->scopes = $scopes;
159159
}
160+
160161
return $this->scopes;
161162
}
162163

src/ApiClient.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,16 @@ public function getFilteredDecisions(array $filter): array
5656
return $this->restClient->request('/v1/decisions', $filter) ?: [];
5757
}
5858

59-
6059
/**
6160
* Request decisions using the stream mode. When the $startup flag is used, all the decisions are returned.
6261
* Else only the decisions updates (add or remove) from the last stream call are returned.
63-
* @param bool $startup
64-
* @param array $scopes
65-
* @return array
6662
*/
6763
public function getStreamedDecisions(bool $startup = false, array $scopes = [Constants::SCOPE_IP, Constants::SCOPE_RANGE]): array
6864
{
6965
/** @var array */
7066
return $this->restClient->request(
7167
'/v1/decisions/stream',
72-
['startup' => $startup ? 'true': 'false', 'scopes' => implode(',', $scopes)]
68+
['startup' => $startup ? 'true' : 'false', 'scopes' => implode(',', $scopes)]
7369
);
7470
}
7571
}

src/Bouncer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct(AbstractAdapter $cacheAdapter = null, LoggerInterfac
5353
* Configure this instance.
5454
*
5555
* @param array $config An array with all configuration parameters
56+
*
5657
* @throws \Psr\Cache\InvalidArgumentException
5758
*/
5859
public function configure(array $config): void
@@ -108,6 +109,7 @@ private function capRemediationLevel(string $remediation): string
108109
* @param string $ip The IP to check
109110
*
110111
* @return string the remediation to apply (ex: 'ban', 'captcha', 'bypass')
112+
*
111113
* @throws \Psr\Cache\InvalidArgumentException
112114
*/
113115
public function getRemediationForIp(string $ip): string
@@ -169,6 +171,7 @@ public static function getCaptchaHtmlTemplate(bool $error, string $captchaImageS
169171
* This method should be called only to force a cache warm up.
170172
*
171173
* @return array "count": number of decisions added, "errors": decisions not added
174+
*
172175
* @throws \Psr\Cache\InvalidArgumentException
173176
*/
174177
public function warmBlocklistCacheUp(): array
@@ -181,6 +184,7 @@ public function warmBlocklistCacheUp(): array
181184
* This method should be called periodically (ex: crontab) in an asynchronous way to update the bouncer cache.
182185
*
183186
* @return array Number of deleted and new decisions, and errors when processing decisions
187+
*
184188
* @throws \Psr\Cache\InvalidArgumentException
185189
*/
186190
public function refreshBlocklistCache(): array
@@ -192,6 +196,7 @@ public function refreshBlocklistCache(): array
192196
* This method clear the full data in cache.
193197
*
194198
* @return bool If the cache has been successfully cleared or not
199+
*
195200
* @throws \Psr\Cache\InvalidArgumentException
196201
*/
197202
public function clearCache(): bool

src/StandAloneBounce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getBouncerInstance(): Bouncer
137137
'cache_expiration_for_clean_ip' => $cleanIpCacheDuration,
138138
'cache_expiration_for_bad_ip' => $badIpCacheDuration,
139139
'geolocation' => $geolocation,
140-
'forced_test_ip' => $forcedTestIp
140+
'forced_test_ip' => $forcedTestIp,
141141
]);
142142

143143
return $this->bouncer;

tests/GeolocationTest.php

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

33
declare(strict_types=1);
4-
require __DIR__ . '/TestHelpers.php';
5-
require __DIR__ . '/WatcherClient.php';
4+
require __DIR__.'/TestHelpers.php';
5+
require __DIR__.'/WatcherClient.php';
66

77
use CrowdSecBouncer\ApiCache;
88
use CrowdSecBouncer\ApiClient;
@@ -32,24 +32,21 @@ public function maxmindConfigProvider(): array
3232
return TestHelpers::maxmindConfigProvider();
3333
}
3434

35-
/**
36-
* @param array $maxmindConfig
37-
* @return array
38-
*/
3935
private function handleMaxMindConfig(array $maxmindConfig): array
4036
{
4137
// Check if MaxMind database exist
4238
if (!file_exists($maxmindConfig['database_path'])) {
4339
$this->fail('There must be a MaxMind Database here: '.$maxmindConfig['database_path']);
4440
}
41+
4542
return [
4643
'save_in_session' => false,
4744
'enabled' => true,
4845
'type' => 'maxmind',
4946
'maxmind' => [
5047
'database_type' => $maxmindConfig['database_type'],
51-
'database_path' => $maxmindConfig['database_path']
52-
]
48+
'database_path' => $maxmindConfig['database_path'],
49+
],
5350
];
5451
}
5552

@@ -58,11 +55,11 @@ private function handleMaxMindConfig(array $maxmindConfig): array
5855
* @covers \Bouncer
5956
* @dataProvider maxmindConfigProvider
6057
* @group ignore_
58+
*
6159
* @throws \Symfony\Component\Cache\Exception\CacheException
6260
* @throws \Psr\Cache\InvalidArgumentException
6361
*/
64-
public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindConfig):
65-
void
62+
public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindConfig): void
6663
{
6764
$geolocationConfig = $this->handleMaxMindConfig($maxmindConfig);
6865
// Init context
@@ -80,7 +77,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
8077
$bouncerConfig = [
8178
'api_key' => TestHelpers::getBouncerKey(),
8279
'api_url' => TestHelpers::getLapiUrl(),
83-
'geolocation' => $geolocationConfig
80+
'geolocation' => $geolocationConfig,
8481
];
8582
$bouncer = new Bouncer(null, $this->logger, $apiCache);
8683
$bouncer->configure($bouncerConfig);
@@ -110,7 +107,6 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
110107
'Get decisions for a clean IP and bad country but with geolocation disabled'
111108
);
112109

113-
114110
// Enable again geolocation and change testing conditions
115111
$this->watcherClient->setSecondState();
116112
$geolocationConfig['enabled'] = true;
@@ -125,24 +121,22 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
125121
'Get decisions for a bad IP (ban) and bad country (captcha)'
126122
);
127123

128-
129124
$this->assertEquals(
130125
'ban',
131126
$bouncer->getRemediationForIp(TestHelpers::IP_FRANCE),
132127
'Get decisions for a bad IP (ban) and clean country'
133128
);
134129
}
135130

136-
137131
/**
138132
* @group integration
139133
* @covers \Bouncer
140134
* @dataProvider maxmindConfigProvider
141135
* @group ignore_
136+
*
142137
* @throws \Symfony\Component\Cache\Exception\CacheException|\Psr\Cache\InvalidArgumentException
143138
*/
144-
public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindConfig):
145-
void
139+
public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindConfig): void
146140
{
147141
$geolocationConfig = $this->handleMaxMindConfig($maxmindConfig);
148142
// Init context
@@ -161,7 +155,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindC
161155
'api_key' => TestHelpers::getBouncerKey(),
162156
'api_url' => TestHelpers::getLapiUrl(),
163157
'live_mode' => false,
164-
'geolocation' => $geolocationConfig
158+
'geolocation' => $geolocationConfig,
165159
];
166160
$bouncer = new Bouncer(null, $this->logger, $apiCache);
167161
$bouncer->configure($bouncerConfig);

tests/TestHelpers.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class TestHelpers
2323
public const IP_JAPAN = '210.249.74.42';
2424
public const IP_FRANCE = '78.119.253.85';
2525

26-
27-
2826
public const PHP_FILES_CACHE_ADAPTER_DIR = __DIR__.'/../var/phpFiles.cache';
2927

3028
public const LOG_LEVEL = Logger::DEBUG; // set to Logger::DEBUG to get high verbosity
@@ -40,7 +38,6 @@ public static function createLogger(): Logger
4038
}
4139

4240
/**
43-
* @return array
4441
* @throws ErrorException
4542
* @throws CacheException
4643
*/
@@ -71,17 +68,16 @@ public static function cacheAdapterProvider(): array
7168
];
7269
}
7370

74-
7571
public static function maxmindConfigProvider(): array
7672
{
7773
return [
7874
'country database' => [[
7975
'database_type' => 'country',
80-
'database_path' => __DIR__.'/GeoLite2-Country.mmdb'
76+
'database_path' => __DIR__.'/GeoLite2-Country.mmdb',
8177
]],
8278
'city database' => [[
8379
'database_type' => 'city',
84-
'database_path' => __DIR__.'/GeoLite2-City.mmdb'
80+
'database_path' => __DIR__.'/GeoLite2-City.mmdb',
8581
]],
8682
];
8783
}

tests/WatcherClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public function deleteAllDecisions(): void
104104
$this->request('/v1/decisions', null, null, 'DELETE');
105105
}
106106

107-
protected function getFinalScope($scope, $value){
108-
return ($scope === Constants::SCOPE_IP && 2 === count(explode('/', $value))) ? Constants::SCOPE_RANGE : $scope;
107+
protected function getFinalScope($scope, $value)
108+
{
109+
return (Constants::SCOPE_IP === $scope && 2 === count(explode('/', $value))) ? Constants::SCOPE_RANGE : $scope;
109110
}
110111

111-
public function addDecision(DateTime $now, string $durationString, string $dateTimeDurationString, string
112-
$value, string $type, string $scope = Constants::SCOPE_IP)
112+
public function addDecision(DateTime $now, string $durationString, string $dateTimeDurationString, string $value, string $type, string $scope = Constants::SCOPE_IP)
113113
{
114114
$stopAt = (clone $now)->modify($dateTimeDurationString)->format('Y-m-d\TH:i:s.000\Z');
115115
$startAt = $now->format('Y-m-d\TH:i:s.000\Z');

0 commit comments

Comments
 (0)