Skip to content

Commit 6e5d83a

Browse files
committed
lint pass
1 parent 392b5d0 commit 6e5d83a

File tree

10 files changed

+48
-47
lines changed

10 files changed

+48
-47
lines changed

docs/api/ApiCache.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Used for the stream mode when we have to update the remediations list.
164164

165165
`array`
166166

167-
> number of deleted and new decisions.
167+
> number of deleted and new decisions
168168
169169

170170
<hr />
@@ -191,7 +191,7 @@ Used when the stream mode has just been activated.
191191

192192
`int`
193193

194-
> number of decisions added.
194+
> number of decisions added
195195
196196

197197
<hr />

docs/api/Bouncer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ This method should be called periodically (ex: crontab) in a asynchronous way to
289289

290290
`array`
291291

292-
> number of deleted and new decisions.
292+
> number of deleted and new decisions
293293
294294

295295
<hr />
@@ -315,7 +315,7 @@ This method should be called only to force a cache warm up.
315315

316316
`int`
317317

318-
> number of decisions added.
318+
> number of decisions added
319319
320320

321321
<hr />

docs/contribute.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ git checkout -b <basic-name> # the name is not important now, you can type "new-
7171
git commit # as mush as necessary.
7272

7373
PHP_CS_FIXER_IGNORE_ENV=1 tools/php-cs-fixer/vendor/bin/php-cs-fixer fix # fix coding standards
74+
docker run -e "FILTER_REGEX_INCLUDE=/tmp/lint/src/.*" -e RUN_LOCAL=true -v ${PWD}:/tmp/lint github/super-linter # super linter local pass
7475
./tests-local.sh # check tests are still OK
7576
docker-compose run --rm app vendor/bin/phpdoc-md # Regenerate php doc
7677

src/ApiCache.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ class ApiCache
2525
/** @var LoggerInterface */
2626
private $logger;
2727

28+
/** @var ApiClient */
29+
private $apiClient;
30+
2831
/** @var AbstractAdapter */
2932
private $adapter;
3033

3134
/** @var bool */
32-
private $liveMode;
35+
private $liveMode = null;
3336

3437
/** @var int */
35-
private $cacheExpirationForCleanIp;
38+
private $cacheExpirationForCleanIp = null;
3639

3740
/** @var int */
38-
private $cacheExpirationForBadIp;
39-
40-
/** @var ApiClient */
41-
private $apiClient;
41+
private $cacheExpirationForBadIp = null;
4242

4343
/** @var bool */
44-
private $warmedUp;
44+
private $warmedUp = null;
4545

4646
public function __construct(LoggerInterface $logger, ApiClient $apiClient = null, AbstractAdapter $adapter = null)
4747
{
@@ -69,7 +69,7 @@ public function configure(
6969
$cacheConfig = $cacheConfigItem->get();
7070
$this->warmedUp = (\is_array($cacheConfig) && isset($cacheConfig['warmed_up'])
7171
&& true === $cacheConfig['warmed_up']);
72-
$this->logger->debug(null, [
72+
$this->logger->debug('', [
7373
'type' => 'API_CACHE_INIT',
7474
'adapter' => \get_class($this->adapter),
7575
'mode' => ($liveMode ? 'live' : 'stream'),
@@ -92,7 +92,7 @@ private function addRemediationToCacheItem(string $ip, string $type, int $expira
9292

9393
$index = array_search(Constants::REMEDIATION_BYPASS, array_column($remediations, 0));
9494
if (false !== $index) {
95-
$this->logger->debug(null, [
95+
$this->logger->debug('', [
9696
'type' => 'IP_CLEAN_TO_BAD',
9797
'ip' => $ip,
9898
'old_remediation' => Constants::REMEDIATION_BYPASS,
@@ -142,7 +142,7 @@ private function removeDecisionFromRemediationItem(string $ip, int $decisionId):
142142
unset($remediations[$index]);
143143

144144
if (!$remediations) {
145-
$this->logger->debug(null, [
145+
$this->logger->debug('', [
146146
'type' => 'CACHE_ITEM_REMOVED',
147147
'ip' => $ip,
148148
]);
@@ -161,7 +161,7 @@ private function removeDecisionFromRemediationItem(string $ip, int $decisionId):
161161
if (!$this->adapter->saveDeferred($item)) {
162162
throw new BouncerException("cache#$ip: Unable to save item");
163163
}
164-
$this->logger->debug(null, [
164+
$this->logger->debug('', [
165165
'type' => 'DECISION_REMOVED',
166166
'decision' => $decisionId,
167167
'ips' => [$ip],
@@ -251,7 +251,7 @@ private function removeRemediations(array $decisions): bool
251251
foreach ($decisions as $decision) {
252252
if (\is_int($decision['start_ip']) && \is_int($decision['end_ip'])) {
253253
$ipRange = array_map('long2ip', range($decision['start_ip'], $decision['end_ip']));
254-
$this->logger->debug(null, [
254+
$this->logger->debug('', [
255255
'type' => 'DECISION_REMOVED', 'decision' => $decision['id'], 'ips' => $ipRange,
256256
]);
257257
$success = true;
@@ -263,7 +263,7 @@ private function removeRemediations(array $decisions): bool
263263
if (!$success) {
264264
// The API may return stale deletion events due to API design.
265265
// Ignoring them is therefore not a problem.
266-
$this->logger->debug(null, ['type' => 'DECISION_TO_REMOVE_NOT_FOUND_IN_CACHE', 'decision' => $decision['id']]);
266+
$this->logger->debug('', ['type' => 'DECISION_TO_REMOVE_NOT_FOUND_IN_CACHE', 'decision' => $decision['id']]);
267267
}
268268
}
269269
}
@@ -282,7 +282,7 @@ private function saveRemediationsForIp(array $decisions, string $ip): string
282282
if (!\in_array($decision['type'], Constants::ORDERED_REMEDIATIONS)) {
283283
$highestRemediationLevel = Constants::ORDERED_REMEDIATIONS[0];
284284
// TODO P1 test the case of unknown remediation type
285-
$this->logger->warning(null, ['type' => 'UNKNOWN_REMEDIATION', 'remediation' => $decision['type']]);
285+
$this->logger->warning('', ['type' => 'UNKNOWN_REMEDIATION', 'remediation' => $decision['type']]);
286286
// TODO P2 use the fallback parameter instead.
287287
$decision['type'] = $highestRemediationLevel;
288288
}
@@ -304,7 +304,7 @@ public function clear(): bool
304304
$this->warmedUp = false;
305305
$this->defferUpdateCacheConfig(['warmed_up' => $this->warmedUp]);
306306
$this->adapter->commit();
307-
$this->logger->info(null, ['type' => 'CACHE_CLEARED']);
307+
$this->logger->info('', ['type' => 'CACHE_CLEARED']);
308308

309309
return $cleared;
310310
}
@@ -321,7 +321,7 @@ public function warmUp(): int
321321
if ($this->warmedUp) {
322322
$this->clear();
323323
}
324-
$this->logger->debug(null, ['type' => 'START_CACHE_WARMUP']);
324+
$this->logger->debug('', ['type' => 'START_CACHE_WARMUP']);
325325
$startup = true;
326326
$decisionsDiff = $this->apiClient->getStreamedDecisions($startup);
327327
$newDecisions = $decisionsDiff['new'];
@@ -341,7 +341,7 @@ public function warmUp(): int
341341
$this->defferUpdateCacheConfig(['warmed_up' => true]);
342342

343343
$this->adapter->commit();
344-
$this->logger->info(null, ['type' => 'CACHE_WARMED_UP', 'added_decisions' => $nbNew]);
344+
$this->logger->info('', ['type' => 'CACHE_WARMED_UP', 'added_decisions' => $nbNew]);
345345

346346
return $nbNew;
347347
}
@@ -359,7 +359,7 @@ public function pullUpdates(): array
359359
return ['deleted' => 0, 'new' => $this->warmUp()];
360360
}
361361

362-
$this->logger->debug(null, ['type' => 'START_CACHE_UPDATE']);
362+
$this->logger->debug('', ['type' => 'START_CACHE_UPDATE']);
363363
$decisionsDiff = $this->apiClient->getStreamedDecisions();
364364
$newDecisions = $decisionsDiff['new'];
365365
$deletedDecisions = $decisionsDiff['deleted'];
@@ -376,7 +376,7 @@ public function pullUpdates(): array
376376
$nbNew = \count($newDecisions);
377377
}
378378

379-
$this->logger->debug(null, ['type' => 'CACHE_UPDATED', 'deleted' => $nbDeleted, 'new' => $nbNew]);
379+
$this->logger->debug('', ['type' => 'CACHE_UPDATED', 'deleted' => $nbDeleted, 'new' => $nbNew]);
380380

381381
return ['deleted' => $nbDeleted, 'new' => $nbNew];
382382
}
@@ -392,7 +392,7 @@ private function miss(string $ip): string
392392
$decisions = [];
393393

394394
if ($this->liveMode) {
395-
$this->logger->debug(null, ['type' => 'DIRECT_API_CALL', 'ip' => $ip]);
395+
$this->logger->debug('', ['type' => 'DIRECT_API_CALL', 'ip' => $ip]);
396396
$decisions = $this->apiClient->getFilteredDecisions(['ip' => $ip]);
397397
}
398398

@@ -422,7 +422,7 @@ private function hit(string $ip): string
422422
*/
423423
public function get(string $ip): string
424424
{
425-
$this->logger->debug(null, ['type' => 'START_IP_CHECK', 'ip' => $ip]);
425+
$this->logger->debug('', ['type' => 'START_IP_CHECK', 'ip' => $ip]);
426426
if (!$this->liveMode && !$this->warmedUp) {
427427
throw new BouncerException('CrowdSec Bouncer configured in "stream" mode. Please warm the cache up before trying to access it.');
428428
}
@@ -436,9 +436,9 @@ public function get(string $ip): string
436436
}
437437

438438
if (Constants::REMEDIATION_BYPASS === $remediation) {
439-
$this->logger->info(null, ['type' => 'CLEAN_IP', 'ip' => $ip, 'cache' => $cache]);
439+
$this->logger->info('', ['type' => 'CLEAN_IP', 'ip' => $ip, 'cache' => $cache]);
440440
} else {
441-
$this->logger->warning(null, [
441+
$this->logger->warning('', [
442442
'type' => 'BAD_IP',
443443
'ip' => $ip,
444444
'remediation' => $remediation,
@@ -453,7 +453,7 @@ public function prune(): bool
453453
{
454454
if ($this->adapter instanceof PruneableInterface) {
455455
$pruned = $this->adapter->prune();
456-
$this->logger->debug(null, ['type' => 'CACHE_PRUNED']);
456+
$this->logger->debug('', ['type' => 'CACHE_PRUNED']);
457457

458458
return $pruned;
459459
}

src/ApiClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
class ApiClient
2020
{
2121
/** @var LoggerInterface */
22-
private $logger;
22+
private $logger = null;
2323

2424
/**
2525
* @var RestClient
2626
*/
27-
private $restClient;
27+
private $restClient = null;
2828

2929
public function __construct(LoggerInterface $logger)
3030
{
@@ -42,7 +42,7 @@ public function configure(string $baseUri, int $timeout, string $userAgent, stri
4242
'X-Api-Key' => $apiKey,
4343
'Accept' => 'application/json',
4444
], $timeout);
45-
$this->logger->debug(null, [
45+
$this->logger->debug('', [
4646
'type' => 'API_CLIENT_INIT',
4747
'user_agent' => $userAgent,
4848
]);

src/Bouncer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
class Bouncer
2727
{
2828
/** @var LoggerInterface */
29-
private $logger;
29+
private $logger = null;
3030

3131
/** @var array */
32-
private $config;
32+
private $config = [];
3333

3434
/** @var ApiCache */
35-
private $apiCache;
35+
private $apiCache = null;
3636

3737
/** @var int */
38-
private $maxRemediationLevelIndex;
38+
private $maxRemediationLevelIndex = null;
3939

4040
public function __construct(AbstractAdapter $cacheAdapter = null, LoggerInterface $logger = null, ApiCache $apiCache = null)
4141
{
@@ -202,7 +202,7 @@ public static function buildCaptchaCouple()
202202
public function checkCaptcha(string $expected, string $try, string $ip)
203203
{
204204
$solved = PhraseBuilder::comparePhrases($expected, $try);
205-
$this->logger->warning(null, [
205+
$this->logger->warning('', [
206206
'type' => 'CAPTCHA_SOLVED',
207207
'ip' => $ip,
208208
'resolution' => $solved,

src/RestClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
class RestClient
2020
{
2121
/** @var string */
22-
private $headerString;
22+
private $headerString = null;
2323

2424
/** @var int */
25-
private $timeout;
25+
private $timeout = null;
2626

2727
/** @var string */
28-
private $baseUri;
28+
private $baseUri = null;
2929

3030
/** @var LoggerInterface */
31-
private $logger;
31+
private $logger = null;
3232

3333
public function __construct(LoggerInterface $logger)
3434
{
@@ -44,7 +44,7 @@ public function configure(string $baseUri, array $headers, int $timeout): void
4444
$this->headerString = $this->convertHeadersToString($headers);
4545
$this->timeout = $timeout;
4646

47-
$this->logger->debug(null, [
47+
$this->logger->debug('', [
4848
'type' => 'REST_CLIENT_INIT',
4949
'base_uri' => $this->baseUri,
5050
'timeout' => $this->timeout,
@@ -96,7 +96,7 @@ public function request(
9696
}
9797
$context = stream_context_create($config);
9898

99-
$this->logger->debug(null, [
99+
$this->logger->debug('', [
100100
'type' => 'HTTP CALL',
101101
'method' => $this->baseUri,
102102
'uri' => $this->baseUri.$endpoint,

src/templates/_base.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
function crowdSecBaseTemplatePart1()
2+
function crowdSecBaseTemplatePart1(): void
33
{ ?>
44
<!DOCTYPE html>
55
<html lang="en">
@@ -77,7 +77,7 @@ function crowdSecBaseTemplatePart1()
7777
</style>
7878
</head>
7979
<?php }
80-
function crowdSecBaseTemplatePart2()
80+
function crowdSecBaseTemplatePart2(): void
8181
{ ?>
8282
<script>
8383
function newImage() {
@@ -90,7 +90,7 @@ function newImage() {
9090
<div class="container">
9191
<div class="main">
9292
<?php }
93-
function crowdSecBaseTemplatePart3(bool $hideCrowdSecMentions)
93+
function crowdSecBaseTemplatePart3(bool $hideCrowdSecMentions): void
9494
{
9595
if ($hideCrowdSecMentions) { ?>
9696
<p class="powered">This security check has been powered by

src/templates/access-forbidden.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
require_once __DIR__.'/_base.php';
3-
function displayAccessForbiddenTemplate(bool $hideCrowdSecMentions)
3+
function displayAccessForbiddenTemplate(bool $hideCrowdSecMentions): void
44
{
55
crowdSecBaseTemplatePart1();
66
crowdSecBaseTemplatePart2(); ?>

src/templates/captcha.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
require_once __DIR__.'/_base.php';
3-
function displayCaptchaTemplate(bool $error, string $captchaImageSrc, string $captchaResolutionFormUrl, bool $hideCrowdSecMentions)
3+
function displayCaptchaTemplate(bool $error, string $captchaImageSrc, string $captchaResolutionFormUrl, bool $hideCrowdSecMentions): void
44
{
55
crowdSecBaseTemplatePart1(); ?><style>
66
input {

0 commit comments

Comments
 (0)