Completed
Push — master ( 82acc4...deba42 )
by Will
13s
created

UserForm   C

Complexity

Total Complexity 15

Size/Duplication

Total Lines 359
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 31

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 31
dl 0
loc 359
rs 5
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
D getCMSFields() 0 168 9
A FilteredEmailRecipients() 0 14 1
A getFormOptions() 0 19 3
A getErrorContainerID() 0 4 1
A getCMSValidator() 0 4 1
1
<?php
2
3
namespace SilverStripe\UserForms;
4
5
use Colymba\BulkManager\BulkManager;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Core\Manifest\ModuleLoader;
8
use SilverStripe\Forms\CheckboxField;
9
use SilverStripe\Forms\CompositeField;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\Forms\GridField\GridField;
12
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
13
use SilverStripe\Forms\GridField\GridFieldButtonRow;
14
use SilverStripe\Forms\GridField\GridFieldConfig;
15
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
16
use SilverStripe\Forms\GridField\GridFieldDataColumns;
17
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
18
use SilverStripe\Forms\GridField\GridFieldDetailForm;
19
use SilverStripe\Forms\GridField\GridFieldEditButton;
20
use SilverStripe\Forms\GridField\GridFieldExportButton;
21
use SilverStripe\Forms\GridField\GridFieldPageCount;
22
use SilverStripe\Forms\GridField\GridFieldPaginator;
23
use SilverStripe\Forms\GridField\GridFieldPrintButton;
24
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
25
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
26
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
27
use SilverStripe\Forms\LabelField;
28
use SilverStripe\Forms\LiteralField;
29
use SilverStripe\Forms\TextField;
30
use SilverStripe\ORM\ArrayList;
31
use SilverStripe\ORM\DB;
32
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
33
use SilverStripe\UserForms\Extension\UserFormValidator;
34
use SilverStripe\UserForms\Form\UserFormsGridFieldFilterHeader;
35
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
36
use SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest;
37
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
38
use SilverStripe\UserForms\Model\EditableFormField;
39
use SilverStripe\View\Requirements;
40
41
/**
42
 * Defines the user defined functionality to be applied to any {@link DataObject}
43
 *
44
 */
45
trait UserForm
46
{
47
    /**
48
     * Built in extensions required by this page.
49
     *
50
     * @config
51
     * @var array
52
     */
53
    private static $extensions = [
54
        UserFormFieldEditorExtension::class
55
    ];
56
57
    /**
58
     * @var string Required Identifier
59
     */
60
    private static $required_identifier = null;
61
62
    /**
63
     * @var string
64
     */
65
    private static $email_template_directory = 'userforms/templates/email/';
66
67
    /**
68
     * Should this module automatically upgrade on dev/build?
69
     *
70
     * @config
71
     * @var bool
72
     */
73
    private static $upgrade_on_build = true;
74
75
    /**
76
     * Set this to true to disable automatic inclusion of CSS files
77
     * @config
78
     * @var bool
79
     */
80
    private static $block_default_userforms_css = false;
81
82
    /**
83
     * Set this to true to disable automatic inclusion of JavaScript files
84
     * @config
85
     * @var bool
86
     */
87
    private static $block_default_userforms_js = false;
88
89
    /**
90
     * @var array Fields on the user defined form page.
91
     */
92
    private static $db = [
93
        'SubmitButtonText' => 'Varchar',
94
        'ClearButtonText' => 'Varchar',
95
        'OnCompleteMessage' => 'HTMLText',
96
        'ShowClearButton' => 'Boolean',
97
        'DisableSaveSubmissions' => 'Boolean',
98
        'EnableLiveValidation' => 'Boolean',
99
        'DisplayErrorMessagesAtTop' => 'Boolean',
100
        'DisableAuthenicatedFinishAction' => 'Boolean',
101
        'DisableCsrfSecurityToken' => 'Boolean'
102
    ];
103
104
    /**
105
     * @var array Default values of variables when this page is created
106
     */
107
    private static $defaults = [
108
        'Content' => '$UserDefinedForm',
109
        'DisableSaveSubmissions' => 0,
110
        'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
111
    ];
112
113
    /**
114
     * @var array
115
     */
116
    private static $has_many = [
117
        'Submissions' => SubmittedForm::class,
118
        'EmailRecipients' => EmailRecipient::class
119
    ];
120
121
    private static $cascade_deletes = [
122
        'EmailRecipients',
123
    ];
124
125
    /**
126
     * @var array
127
     * @config
128
     */
129
    private static $casting = [
130
        'ErrorContainerID' => 'Text'
131
    ];
132
133
    /**
134
     * Error container selector which matches the element for grouped messages
135
     *
136
     * @var string
137
     * @config
138
     */
139
    private static $error_container_id = 'error-container';
140
141
    /**
142
     * The configuration used to determine whether a confirmation message is to
143
     * appear when navigating away from a partially completed form.
144
     *
145
     * @var boolean
146
     * @config
147
     */
148
    private static $enable_are_you_sure = true;
149
150
    /**
151
     * @var bool
152
     * @config
153
     */
154
    private static $recipients_warning_enabled = false;
155
156
    private static $non_live_permissions = ['SITETREE_VIEW_ALL'];
157
158
    /**
159
     * Temporary storage of field ids when the form is duplicated.
160
     * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
161
     * @var array
162
     */
163
    protected $fieldsFromTo = [];
164
165
    /**
166
     * @return FieldList
167
     */
168
    public function getCMSFields()
169
    {
170
        Requirements::css(
171
            ModuleLoader::getModule('silverstripe/userforms')
172
                ->getRelativeResourcePath('client/dist/styles/userforms-cms.css')
173
        );
174
175
        $this->beforeUpdateCMSFields(function ($fields) {
0 ignored issues
show
Bug introduced by
It seems like beforeUpdateCMSFields() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
176
177
            // remove
178
            $fields->removeByName('OnCompleteMessageLabel');
179
            $fields->removeByName('OnCompleteMessage');
180
            $fields->removeByName('Fields');
181
            $fields->removeByName('EmailRecipients');
182
183
            // define tabs
184
            $fields->findOrMakeTab('Root.FormOptions', _t(__CLASS__.'.CONFIGURATION', 'Configuration'));
185
            $fields->findOrMakeTab('Root.Recipients', _t(__CLASS__.'.RECIPIENTS', 'Recipients'));
186
            $fields->findOrMakeTab('Root.Submissions', _t(__CLASS__.'.SUBMISSIONS', 'Submissions'));
187
188
189
            // text to show on complete
190
            $onCompleteFieldSet = CompositeField::create(
191
                $label = LabelField::create(
192
                    'OnCompleteMessageLabel',
193
                    _t(__CLASS__.'.ONCOMPLETELABEL', 'Show on completion')
194
                ),
195
                $editor = HTMLEditorField::create(
196
                    'OnCompleteMessage',
197
                    '',
198
                    _t(__CLASS__.'.ONCOMPLETEMESSAGE', $this->OnCompleteMessage)
0 ignored issues
show
Bug introduced by
The property OnCompleteMessage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
199
                )
200
            );
201
202
            $onCompleteFieldSet->addExtraClass('field');
203
204
            $editor->setRows(3);
205
            $label->addExtraClass('left');
206
207
            // Define config for email recipients
208
            $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
209
            $emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class)
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SilverStripe\Forms\GridField\GridFieldComponent as the method setButtonName() does only exist in the following implementations of said interface: SilverStripe\Forms\GridField\GridFieldAddNewButton, SilverStripe\UserForms\F...idFieldAddClassesButton.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
210
                ->setButtonName(
211
                    _t(__CLASS__.'.ADDEMAILRECIPIENT', 'Add Email Recipient')
212
                );
213
214
            // who do we email on submission
215
            $emailRecipients = GridField::create(
216
                'EmailRecipients',
217
                '',
218
                $this->EmailRecipients(),
0 ignored issues
show
Bug introduced by
The method EmailRecipients() does not exist on SilverStripe\UserForms\UserForm. Did you maybe mean FilteredEmailRecipients()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
219
                $emailRecipientsConfig
220
            );
221
            $emailRecipients
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SilverStripe\Forms\GridField\GridFieldComponent as the method setItemRequestClass() does only exist in the following implementations of said interface: SilverStripe\Forms\GridField\GridFieldDetailForm.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
222
                ->getConfig()
223
                ->getComponentByType(GridFieldDetailForm::class)
224
                ->setItemRequestClass(UserFormRecipientItemRequest::class);
225
226
            $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
227
            $fields->addFieldToTab('Root.Recipients', $emailRecipients);
228
            $fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions());
229
230
231
            // view the submissions
232
            // make sure a numeric not a empty string is checked against this int column for SQL server
233
            $parentID = (!empty($this->ID)) ? (int) $this->ID : 0;
0 ignored issues
show
Bug introduced by
The property ID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
234
235
            // get a list of all field names and values used for print and export CSV views of the GridField below.
236
            $columnSQL = <<<SQL
237
SELECT "SubmittedFormField"."Name" as "Name", COALESCE("EditableFormField"."Title", "SubmittedFormField"."Title") as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort"
238
FROM "SubmittedFormField"
239
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
240
LEFT JOIN "EditableFormField" ON "EditableFormField"."Name" = "SubmittedFormField"."Name" AND "EditableFormField"."ParentID" = '$parentID'
241
WHERE "SubmittedForm"."ParentID" = '$parentID'
242
ORDER BY "Sort", "Title"
243
SQL;
244
            // Sanitise periods in title
245
            $columns = array();
246
247
            foreach (DB::query($columnSQL)->map() as $name => $title) {
248
                $columns[$name] = trim(strtr($title, '.', ' '));
249
            }
250
251
            $config = GridFieldConfig::create();
252
            $config->addComponent(new GridFieldToolbarHeader());
253
            $config->addComponent($sort = new GridFieldSortableHeader());
254
            $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
255
            $config->addComponent(new GridFieldDataColumns());
256
            $config->addComponent(new GridFieldEditButton());
257
            $config->addComponent(new GridFieldDeleteAction());
258
            $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
259
            $config->addComponent($pagination = new GridFieldPaginator(25));
260
            $config->addComponent(new GridFieldDetailForm());
261
            $config->addComponent(new GridFieldButtonRow('after'));
262
            $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
263
            $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
264
265
            // show user form items in the summary tab
266
            $summaryarray = array(
267
                'ID' => 'ID',
268
                'Created' => 'Created',
269
                'LastEdited' => 'Last Edited'
270
            );
271
272
            foreach (EditableFormField::get()->filter(array('ParentID' => $parentID)) as $eff) {
273
                if ($eff->ShowInSummary) {
274
                    $summaryarray[$eff->Name] = $eff->Title ?: $eff->Name;
275
                }
276
            }
277
278
            $config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields($summaryarray);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SilverStripe\Forms\GridField\GridFieldComponent as the method setDisplayFields() does only exist in the following implementations of said interface: SilverStripe\Forms\GridField\GridFieldDataColumns.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
279
280
            /**
281
             * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
282
             */
283
            if (class_exists(BulkManager::class)) {
284
                $config->addComponent(new BulkManager);
285
            }
286
287
            $sort->setThrowExceptionOnBadDataType(false);
288
            $filter->setThrowExceptionOnBadDataType(false);
289
            $pagination->setThrowExceptionOnBadDataType(false);
290
291
            // attach every column to the print view form
292
            $columns['Created'] = 'Created';
293
            $columns['SubmittedBy.Email'] = 'Submitter';
294
            $filter->setColumns($columns);
295
296
            // print configuration
297
298
            $print->setPrintHasHeader(true);
299
            $print->setPrintColumns($columns);
300
301
            // export configuration
302
            $export->setCsvHasHeader(true);
303
            $export->setExportColumns($columns);
304
305
            $submissions = GridField::create(
306
                'Submissions',
307
                '',
308
                $this->Submissions()->sort('Created', 'DESC'),
0 ignored issues
show
Bug introduced by
It seems like Submissions() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
309
                $config
310
            );
311
            $fields->addFieldToTab('Root.Submissions', $submissions);
312
            $fields->addFieldToTab(
313
                'Root.FormOptions',
314
                CheckboxField::create(
315
                    'DisableSaveSubmissions',
316
                    _t(__CLASS__.'.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')
317
                )
318
            );
319
        });
320
321
        $fields = parent::getCMSFields();
322
323
        if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
0 ignored issues
show
Bug introduced by
The method EmailRecipients() does not exist on SilverStripe\UserForms\UserForm. Did you maybe mean FilteredEmailRecipients()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
324
            $fields->addFieldToTab('Root.Main', LiteralField::create(
325
                'EmailRecipientsWarning',
326
                '<p class="message warning">' . _t(
327
                    __CLASS__.'.NORECIPIENTS',
328
                    'Warning: You have not configured any recipients. Form submissions may be missed.'
329
                )
330
                . '</p>'
331
            ), 'Title');
332
        }
333
334
        return $fields;
335
    }
336
337
    /**
338
     * Allow overriding the EmailRecipients on a {@link DataExtension}
339
     * so you can customise who receives an email.
340
     * Converts the RelationList to an ArrayList so that manipulation
341
     * of the original source data isn't possible.
342
     *
343
     * @return ArrayList
344
     */
345
    public function FilteredEmailRecipients($data = null, $form = null)
346
    {
347
        $recipients = ArrayList::create($this->EmailRecipients()->toArray());
0 ignored issues
show
Bug introduced by
The method EmailRecipients() does not exist on SilverStripe\UserForms\UserForm. Did you maybe mean FilteredEmailRecipients()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
348
349
        // Filter by rules
350
        $recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
351
            /** @var EmailRecipient $recipient */
352
            return $recipient->canSend($data, $form);
353
        });
354
355
        $this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
0 ignored issues
show
Bug introduced by
It seems like extend() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
356
357
        return $recipients;
358
    }
359
360
    /**
361
     * Custom options for the form. You can extend the built in options by
362
     * using {@link updateFormOptions()}
363
     *
364
     * @return FieldList
365
     */
366
    public function getFormOptions()
367
    {
368
        $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t(__CLASS__.'.SUBMITBUTTON', 'Submit');
0 ignored issues
show
Bug introduced by
The property SubmitButtonText does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
369
        $clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t(__CLASS__.'.CLEARBUTTON', 'Clear');
0 ignored issues
show
Bug introduced by
The property ClearButtonText does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
370
371
        $options = FieldList::create(
372
            TextField::create('SubmitButtonText', _t(__CLASS__.'.TEXTONSUBMIT', 'Text on submit button:'), $submit),
373
            TextField::create('ClearButtonText', _t(__CLASS__.'.TEXTONCLEAR', 'Text on clear button:'), $clear),
374
            CheckboxField::create('ShowClearButton', _t(__CLASS__.'.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
0 ignored issues
show
Bug introduced by
The property ShowClearButton does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
375
            CheckboxField::create('EnableLiveValidation', _t(__CLASS__.'.ENABLELIVEVALIDATION', 'Enable live validation')),
376
            CheckboxField::create('DisplayErrorMessagesAtTop', _t(__CLASS__.'.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
377
            CheckboxField::create('DisableCsrfSecurityToken', _t(__CLASS__.'.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
378
            CheckboxField::create('DisableAuthenicatedFinishAction', _t(__CLASS__.'.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
379
        );
380
381
        $this->extend('updateFormOptions', $options);
0 ignored issues
show
Bug introduced by
It seems like extend() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
382
383
        return $options;
384
    }
385
386
    /**
387
     * Get the HTML id of the error container displayed above the form.
388
     *
389
     * @return string
390
     */
391
    public function getErrorContainerID()
392
    {
393
        return $this->config()->get('error_container_id');
0 ignored issues
show
Bug introduced by
It seems like config() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
394
    }
395
396
    /**
397
     * Validate formfields
398
     */
399
    public function getCMSValidator()
400
    {
401
        return UserFormValidator::create();
402
    }
403
}
404