diff --git a/composer.json b/composer.json index 13d1072..dc2a08f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "autoload": { "psr-4": { - "SilverStripe\\SpamProtection\\": "code/", + "SilverStripe\\SpamProtection\\": "src/", "SilverStripe\\SpamProtection\\Tests\\": "tests/" } }, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d76bc90..f3047d8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,7 +2,7 @@ CodeSniffer ruleset for SilverStripe coding conventions. - code + src tests diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 794aa0f..57c7cdd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ - code/ + src/ tests/ diff --git a/code/EditableSpamProtectionField.php b/src/EditableSpamProtectionField.php similarity index 97% rename from code/EditableSpamProtectionField.php rename to src/EditableSpamProtectionField.php index dfbdf41..0331f1c 100644 --- a/code/EditableSpamProtectionField.php +++ b/src/EditableSpamProtectionField.php @@ -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; @@ -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 @@ -69,7 +68,7 @@ class EditableSpamProtectionField extends EditableFormField } // Extract saved field mappings and update this field. - $fieldMapping = array(); + $fieldMapping = []; foreach ($this->getCandidateFields() as $otherField) { $mapSetting = "Map-{$otherField->Name}"; $spamField = $this->spamMapValue($mapSetting); @@ -106,7 +105,7 @@ class EditableSpamProtectionField extends EditableFormField // 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); @@ -132,7 +131,7 @@ class EditableSpamProtectionField extends EditableFormField { $fieldMap = json_decode($this->SpamFieldSettings ?? '', true); if (empty($fieldMap)) { - $fieldMap = array(); + $fieldMap = []; } foreach ($this->record as $key => $value) { @@ -202,7 +201,7 @@ class EditableSpamProtectionField extends EditableFormField { $map = json_decode($this->SpamFieldSettings ?? '', true); if (empty($map)) { - $map = array(); + $map = []; } if (array_key_exists($mapSetting, $map ?? [])) { diff --git a/code/Extension/CommentSpamProtection.php b/src/Extension/CommentSpamProtection.php similarity index 80% rename from code/Extension/CommentSpamProtection.php rename to src/Extension/CommentSpamProtection.php index f01e44c..fc5f8c9 100644 --- a/code/Extension/CommentSpamProtection.php +++ b/src/Extension/CommentSpamProtection.php @@ -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' - ) - )); + ] + ]); } } diff --git a/code/Extension/FormSpamProtectionExtension.php b/src/Extension/FormSpamProtectionExtension.php similarity index 96% rename from code/Extension/FormSpamProtectionExtension.php rename to src/Extension/FormSpamProtectionExtension.php index 3ff2422..07de263 100644 --- a/code/Extension/FormSpamProtectionExtension.php +++ b/src/Extension/FormSpamProtectionExtension.php @@ -37,7 +37,7 @@ class FormSpamProtectionExtension extends Extension * * @var array $mappable_fields */ - private static $mappable_fields = array( + private static $mappable_fields = [ 'id', 'title', 'body', @@ -48,7 +48,7 @@ class FormSpamProtectionExtension extends Extension 'authorUrl', 'authorIp', 'authorId' - ); + ]; /** * @config @@ -88,7 +88,7 @@ class FormSpamProtectionExtension extends Extension * @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) diff --git a/code/SpamProtector.php b/src/SpamProtector.php similarity index 100% rename from code/SpamProtector.php rename to src/SpamProtector.php