Skip to content

Commit

Permalink
Merge pull request #106 from wilr/pr/mnt
Browse files Browse the repository at this point in the history
feat: code clean up
  • Loading branch information
GuySartorelli authored Sep 14, 2023
2 parents d10b6a1 + 6f85c7e commit 3079188
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\SpamProtection\\": "code/",
"SilverStripe\\SpamProtection\\": "src/",
"SilverStripe\\SpamProtection\\Tests\\": "tests/"
}
},
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<file>code</file>
<file>src</file>
<file>tests</file>

<rule ref="PSR2" >
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">code/</directory>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\SpamProtection;

use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldGroup;
Expand Down Expand Up @@ -41,15 +40,15 @@ class EditableSpamProtectionField extends EditableFormField
* @var array
* @config
*/
private static $check_fields = array(
private static $check_fields = [
EditableEmailField::class,
EditableTextField::class,
EditableNumericField::class
);
];

private static $db = array(
private static $db = [
'SpamFieldSettings' => 'Text'
);
];

/**
* @var FormField
Expand All @@ -69,7 +68,7 @@ public function getFormField()
}

// Extract saved field mappings and update this field.
$fieldMapping = array();
$fieldMapping = [];
foreach ($this->getCandidateFields() as $otherField) {
$mapSetting = "Map-{$otherField->Name}";
$spamField = $this->spamMapValue($mapSetting);
Expand Down Expand Up @@ -106,7 +105,7 @@ protected function getCandidateFields()

// Get list of all configured classes available for spam detection
$types = $this->config()->get('check_fields');
$typesInherit = array();
$typesInherit = [];
foreach ($types as $type) {
$subTypes = ClassInfo::subclassesFor($type);
$typesInherit = array_merge($typesInherit, $subTypes);
Expand All @@ -132,7 +131,7 @@ public function onBeforeWrite()
{
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
if (empty($fieldMap)) {
$fieldMap = array();
$fieldMap = [];
}

foreach ($this->record as $key => $value) {
Expand Down Expand Up @@ -202,7 +201,7 @@ public function spamMapValue($mapSetting)
{
$map = json_decode($this->SpamFieldSettings ?? '', true);
if (empty($map)) {
$map = array();
$map = [];
}

if (array_key_exists($mapSetting, $map ?? [])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class CommentSpamProtection extends Extension
{
public function alterCommentForm(&$form)
{
$form->enableSpamProtection(array(
$form->enableSpamProtection([
'name' => 'IsSpam',
'mapping' => array(
'mapping' => [
'Name' => 'authorName',
'Email' => 'authorEmail',
'URL' => 'authorUrl',
'Comment' => 'body',
'ReturnURL' => 'contextUrl'
),
'checks' => array(
],
'checks' => [
'spam',
'profanity'
)
));
]
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FormSpamProtectionExtension extends Extension
*
* @var array $mappable_fields
*/
private static $mappable_fields = array(
private static $mappable_fields = [
'id',
'title',
'body',
Expand All @@ -48,7 +48,7 @@ class FormSpamProtectionExtension extends Extension
'authorUrl',
'authorIp',
'authorId'
);
];

/**
* @config
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function get_protector($options = null)
* @throws LogicException when get_protector method returns NULL.
* @return Object
*/
public function enableSpamProtection($options = array())
public function enableSpamProtection($options = [])
{

// captcha form field name (must be unique)
Expand Down
File renamed without changes.

0 comments on commit 3079188

Please sign in to comment.