Skip to content

Commit 773ab23

Browse files
style(*): Pass through coding standards
1 parent e438df5 commit 773ab23

File tree

6 files changed

+85
-78
lines changed

6 files changed

+85
-78
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ the `src` folder.
1313

1414
---
1515

16-
## [1.0.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.0.0) - 2023-??-??
16+
## [1.0.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.0.0) - 2023-02-03
1717
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.36.0...v1.0.0)
1818

1919
### Changed
2020
- Change version to `1.0.0`: first stable release
21-
- Use `crowdsec/common` package
21+
- Update `crowdsec/remediation-engine` to a new major version [2.0.0](https://github.com/crowdsecurity/php-remediation-engine/releases/tag/v2.0.0)
22+
- Use `crowdsec/common` [package](https://github.com/crowdsecurity/php-common) as a dependency for code factoring
2223

2324
### Added
2425

2526
- Add public API declaration
2627

2728

28-
2929
---
3030

3131

scripts/auto-prepend/bounce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
} catch (\Throwable $e) {
2020
$displayErrors = $crowdSecStandaloneBouncerConfig['display_errors'] ?? false;
2121
if (true === $displayErrors) {
22-
throw new BouncerException($e->getMessage(), (int)$e->getCode(), $e);
22+
throw new BouncerException($e->getMessage(), (int) $e->getCode(), $e);
2323
}
24-
}
24+
}

src/AbstractBouncer.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace CrowdSecBouncer;
66

7-
use CrowdSec\LapiClient\Bouncer as BouncerClient;
87
use CrowdSec\Common\Client\RequestHandler\Curl;
98
use CrowdSec\Common\Client\RequestHandler\FileGetContents;
9+
use CrowdSec\LapiClient\Bouncer as BouncerClient;
1010
use CrowdSec\RemediationEngine\AbstractRemediation;
1111
use CrowdSec\RemediationEngine\CacheStorage\AbstractCache;
1212
use CrowdSec\RemediationEngine\CacheStorage\CacheStorageException;
@@ -167,7 +167,7 @@ public function getRemediationForIp(string $ip): string
167167
try {
168168
return $this->capRemediationLevel($this->getRemediationEngine()->getIpRemediation($ip));
169169
} catch (\Exception $e) {
170-
throw new BouncerException($e->getMessage(), $e->getCode(), $e);
170+
throw new BouncerException($e->getMessage(), (int)$e->getCode(), $e);
171171
}
172172
}
173173

@@ -197,23 +197,6 @@ public function pruneCache(): bool
197197
}
198198
}
199199

200-
/**
201-
* Process a simple cache test
202-
*
203-
* @return void
204-
* @throws BouncerException
205-
* @throws InvalidArgumentException
206-
*/
207-
public function testCacheConnection(): void
208-
{
209-
try {
210-
$cache = $this->getRemediationEngine()->getCacheStorage();
211-
$cache->getItem(AbstractCache::CONFIG);
212-
} catch (\Exception $e) {
213-
throw new BouncerException($e->getMessage(), (int)$e->getCode(), $e);
214-
}
215-
}
216-
217200
/**
218201
* Used in stream mode only.
219202
* This method should be called periodically (ex: crontab) in an asynchronous way to update the bouncer cache.
@@ -292,6 +275,23 @@ public function shouldBounceCurrentIp(): bool
292275
return true;
293276
}
294277

278+
/**
279+
* Process a simple cache test
280+
*
281+
* @return void
282+
* @throws BouncerException
283+
* @throws InvalidArgumentException
284+
*/
285+
public function testCacheConnection(): void
286+
{
287+
try {
288+
$cache = $this->getRemediationEngine()->getCacheStorage();
289+
$cache->getItem(AbstractCache::CONFIG);
290+
} catch (\Exception $e) {
291+
throw new BouncerException($e->getMessage(), (int)$e->getCode(), $e);
292+
}
293+
}
294+
295295
/**
296296
* @throws BouncerException
297297
* @throws CacheStorageException

src/Configuration.php

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -62,59 +62,6 @@ public function getConfigTreeBuilder(): TreeBuilder
6262
return $treeBuilder;
6363
}
6464

65-
private function addTemplateNodes($rootNode)
66-
{
67-
$defaultSubtitle = 'This page is protected against cyber attacks and your IP has been banned by our system.';
68-
$rootNode->children()
69-
->arrayNode('color')->addDefaultsIfNotSet()
70-
->children()
71-
->arrayNode('text')->addDefaultsIfNotSet()
72-
->children()
73-
->scalarNode('primary')->defaultValue('black')->end()
74-
->scalarNode('secondary')->defaultValue('#AAA')->end()
75-
->scalarNode('button')->defaultValue('white')->end()
76-
->scalarNode('error_message')->defaultValue('#b90000')->end()
77-
->end()
78-
->end()
79-
->arrayNode('background')->addDefaultsIfNotSet()
80-
->children()
81-
->scalarNode('page')->defaultValue('#eee')->end()
82-
->scalarNode('container')->defaultValue('white')->end()
83-
->scalarNode('button')->defaultValue('#626365')->end()
84-
->scalarNode('button_hover')->defaultValue('#333')->end()
85-
->end()
86-
->end()
87-
->end()
88-
->end()
89-
->arrayNode('text')->addDefaultsIfNotSet()
90-
->children()
91-
->arrayNode('captcha_wall')->addDefaultsIfNotSet()
92-
->children()
93-
->scalarNode('tab_title')->defaultValue('Oops..')->end()
94-
->scalarNode('title')->defaultValue('Hmm, sorry but...')->end()
95-
->scalarNode('subtitle')->defaultValue('Please complete the security check.')->end()
96-
->scalarNode('refresh_image_link')->defaultValue('refresh image')->end()
97-
->scalarNode('captcha_placeholder')->defaultValue('Type here...')->end()
98-
->scalarNode('send_button')->defaultValue('CONTINUE')->end()
99-
->scalarNode('error_message')->defaultValue('Please try again.')->end()
100-
->scalarNode('footer')->defaultValue('')->end()
101-
->end()
102-
->end()
103-
->arrayNode('ban_wall')->addDefaultsIfNotSet()
104-
->children()
105-
->scalarNode('tab_title')->defaultValue('Oops..')->end()
106-
->scalarNode('title')->defaultValue('🤭 Oh!')->end()
107-
->scalarNode('subtitle')->defaultValue($defaultSubtitle)->end()
108-
->scalarNode('footer')->defaultValue('')->end()
109-
->end()
110-
->end()
111-
->end()
112-
->end()
113-
->booleanNode('hide_mentions')->defaultValue(false)->end()
114-
->scalarNode('custom_css')->defaultValue('')->end()
115-
->end();
116-
}
117-
11865
/**
11966
* Bouncer settings
12067
*
@@ -202,4 +149,57 @@ private function addDebugNodes($rootNode)
202149
->booleanNode('display_errors')->defaultValue(false)->end()
203150
->end();
204151
}
152+
153+
private function addTemplateNodes($rootNode)
154+
{
155+
$defaultSubtitle = 'This page is protected against cyber attacks and your IP has been banned by our system.';
156+
$rootNode->children()
157+
->arrayNode('color')->addDefaultsIfNotSet()
158+
->children()
159+
->arrayNode('text')->addDefaultsIfNotSet()
160+
->children()
161+
->scalarNode('primary')->defaultValue('black')->end()
162+
->scalarNode('secondary')->defaultValue('#AAA')->end()
163+
->scalarNode('button')->defaultValue('white')->end()
164+
->scalarNode('error_message')->defaultValue('#b90000')->end()
165+
->end()
166+
->end()
167+
->arrayNode('background')->addDefaultsIfNotSet()
168+
->children()
169+
->scalarNode('page')->defaultValue('#eee')->end()
170+
->scalarNode('container')->defaultValue('white')->end()
171+
->scalarNode('button')->defaultValue('#626365')->end()
172+
->scalarNode('button_hover')->defaultValue('#333')->end()
173+
->end()
174+
->end()
175+
->end()
176+
->end()
177+
->arrayNode('text')->addDefaultsIfNotSet()
178+
->children()
179+
->arrayNode('captcha_wall')->addDefaultsIfNotSet()
180+
->children()
181+
->scalarNode('tab_title')->defaultValue('Oops..')->end()
182+
->scalarNode('title')->defaultValue('Hmm, sorry but...')->end()
183+
->scalarNode('subtitle')->defaultValue('Please complete the security check.')->end()
184+
->scalarNode('refresh_image_link')->defaultValue('refresh image')->end()
185+
->scalarNode('captcha_placeholder')->defaultValue('Type here...')->end()
186+
->scalarNode('send_button')->defaultValue('CONTINUE')->end()
187+
->scalarNode('error_message')->defaultValue('Please try again.')->end()
188+
->scalarNode('footer')->defaultValue('')->end()
189+
->end()
190+
->end()
191+
->arrayNode('ban_wall')->addDefaultsIfNotSet()
192+
->children()
193+
->scalarNode('tab_title')->defaultValue('Oops..')->end()
194+
->scalarNode('title')->defaultValue('🤭 Oh!')->end()
195+
->scalarNode('subtitle')->defaultValue($defaultSubtitle)->end()
196+
->scalarNode('footer')->defaultValue('')->end()
197+
->end()
198+
->end()
199+
->end()
200+
->end()
201+
->booleanNode('hide_mentions')->defaultValue(false)->end()
202+
->scalarNode('custom_css')->defaultValue('')->end()
203+
->end();
204+
}
205205
}

src/StandaloneBouncer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace CrowdSecBouncer;
66

7+
use CrowdSec\Common\Logger\FileLog;
78
use CrowdSec\RemediationEngine\CacheStorage\CacheStorageException;
89
use CrowdSec\RemediationEngine\LapiRemediation;
9-
use CrowdSec\Common\Logger\FileLog;
1010
use IPLib\Factory;
1111
use Psr\Log\LoggerInterface;
1212

tools/coding-standards/phpmd/rulesets.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<rule ref="rulesets/codesize.xml" >
1414
<exclude name="ExcessiveClassComplexity"/>
15+
<exclude name="TooManyMethods"/>
1516
</rule>
1617
<rule ref="rulesets/cleancode.xml">
1718
<exclude name="StaticAccess"/>
@@ -24,6 +25,12 @@
2425
<property name="allow-unused-foreach-variables" value="true" />
2526
</properties>
2627
</rule>
28+
<!-- Allow more methods -->
29+
<rule ref="rulesets/codesize.xml/TooManyMethods">
30+
<properties>
31+
<property name="ignorepattern" value="(^(set|get|is|has|with|unset|test))i" />
32+
</properties>
33+
</rule>
2734
<!--The only case when static access is acceptable is when used for factory methods.-->
2835
<rule ref="rulesets/cleancode.xml/StaticAccess">
2936
<properties>

0 commit comments

Comments
 (0)