Completed
Pull Request — master (#312)
by Jason
12:12
created

FoxyStripeSetting   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 498
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 30
dl 0
loc 498
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getSSOLink() 0 3 1
A onAfterWrite() 0 7 4
A providePermissions() 0 17 1
A canEdit() 0 12 3
A getDataFeedLink() 0 3 1
B getDataMap() 0 25 1
A requireDefaultRecords() 0 18 4
A getCheckoutTypes() 0 7 1
A current_foxystripe_setting() 0 7 2
A getCMSActions() 0 13 3
B getCMSFields() 0 194 2
A CMSEditLink() 0 3 1
A make_foxystripe_setting() 0 6 1
A get_template_global_variables() 0 4 1
A onBeforeWrite() 0 5 4
1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use Dynamic\CountryDropdownField\Fields\CountryDropdownField;
6
use Dynamic\FoxyStripe\Admin\FoxyStripeAdmin;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Forms\CheckboxField;
9
use SilverStripe\Forms\DropdownField;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\Forms\FormAction;
12
use SilverStripe\Forms\GridField\GridField;
13
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
14
use SilverStripe\Forms\HeaderField;
15
use SilverStripe\Forms\HiddenField;
16
use SilverStripe\Forms\LiteralField;
17
use SilverStripe\Forms\NumericField;
18
use SilverStripe\Forms\ReadonlyField;
19
use SilverStripe\Forms\Tab;
20
use SilverStripe\Forms\TabSet;
21
use SilverStripe\Forms\TextField;
22
use SilverStripe\ORM\DataObject;
23
use SilverStripe\ORM\DB;
24
use SilverStripe\Security\Permission;
25
use SilverStripe\Security\PermissionProvider;
26
use SilverStripe\Security\Security;
27
use SilverStripe\View\TemplateGlobalProvider;
28
29
class FoxyStripeSetting extends DataObject implements PermissionProvider, TemplateGlobalProvider
30
{
31
    /**
32
     * @var string
33
     */
34
    private static $singular_name = 'FoxyStripe Setting';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
35
    /**
36
     * @var string
37
     */
38
    private static $plural_name = 'FoxyStripe Settings';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
39
    /**
40
     * @var string
41
     */
42
    private static $description = 'Update the settings for your store';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
43
44
    /**
45
     * @var array
46
     */
47
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
48
        'StoreTitle' => 'Varchar(255)',
49
        'StoreName' => 'Varchar(255)',
50
        'StoreURL' => 'Varchar(255)',
51
        'ReceiptURL' => 'Varchar(255)',
52
        'StoreEmail' => 'Varchar(255)',
53
        'FromEmail' => 'Varchar(255)',
54
        'StorePostalCode' => 'Varchar(10)',
55
        'StoreCountry' => 'Varchar(100)',
56
        'StoreRegion' => 'Varchar(100)',
57
        'StoreLocaleCode' => 'Varchar(10)',
58
        'StoreLogoURL' => 'Varchar(255)',
59
        'CheckoutType' => 'Varchar(50)',
60
        'BccEmail' => 'Boolean',
61
        'UseWebhook' => 'Boolean',
62
        'StoreKey' => 'Varchar(60)',
63
        'CartValidation' => 'Boolean',
64
        'UseSingleSignOn' => 'Boolean',
65
        'AllowMultiship' => 'Boolean',
66
        'StoreTimezone' => 'Varchar(100)',
67
        'MultiGroup' => 'Boolean',
68
        'ProductLimit' => 'Int',
69
        'MaxQuantity' => 'Int',
70
        'client_id' => 'Varchar(255)',
71
        'client_secret' => 'Varchar(255)',
72
        'access_token' => 'Varchar(255)',
73
        'refresh_token' => 'Varchar(255)',
74
    );
75
76
    // Set Default values
77
    private static $defaults = array(
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
78
        'ProductLimit' => 10,
79
    );
80
81
    /**
82
     * @var string
83
     */
84
    private static $table_name = 'FS_FoxyStripeSetting';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
85
86
    /**
87
     * Default permission to check for 'LoggedInUsers' to create or edit pages.
88
     *
89
     * @var array
90
     * @config
91
     */
92
    private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
0 ignored issues
show
introduced by
The private property $required_permission is not used, and could be removed.
Loading history...
93
94
    /**
95
     * @return FieldList
96
     */
97
    public function getCMSFields()
98
    {
99
        $fields = FieldList::create(
100
            TabSet::create(
101
                'Root',
102
                $tabMain = Tab::create(
103
                    'Main'
0 ignored issues
show
Bug introduced by
'Main' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

103
                    /** @scrutinizer ignore-type */ 'Main'
Loading history...
104
                )
105
            ),
106
            HiddenField::create('ID')
107
        );
108
        $tabMain->setTitle('Settings');
109
110
        // settings tab
111
        $fields->addFieldsToTab('Root.Main', array(
112
            // Store Details
113
            HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3),
0 ignored issues
show
Bug introduced by
3 of type integer is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
            HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), /** @scrutinizer ignore-type */ 3),
Loading history...
114
            LiteralField::create('DetailsIntro', _t(
115
                'FoxyStripeSiteConfig.DetailsIntro',
116
                '<p>Maps to data in your 
117
                        <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">
118
                            FoxyCart store settings
119
                        </a>.'
120
            )),
121
            TextField::create('StoreTitle')
122
                ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name'))
123
                ->setDescription(_t(
124
                    'FoxyStripeSiteConfig.StoreTitleDescription',
125
                    'The name of your store as you\'d like it displayed to your customers'
126
                )),
127
            TextField::create('StoreName')
128
                ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain'))
129
                ->setDescription(_t(
130
                    'FoxyStripeSiteConfig.StoreNameDescription',
131
                    'This is a unique FoxyCart subdomain for your cart, checkout, and receipt'
132
                )),
133
            TextField::create('StoreURL')
134
                ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL'))
135
                ->setDescription(_t(
136
                    'FoxyStripeSiteConfig.StoreURLDescription',
137
                    'The URL of your online store'
138
                )),
139
            TextField::create('ReceiptURL')
140
                ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL'))
141
                ->setDescription(_t(
142
                    'FoxyStripeSiteConfig.ReceiptURLDescription',
143
                    'By default, FoxyCart sends customers back to the page referrer after completing a purchase. 
144
                            Instead, you can set a specific URL here.'
145
                )),
146
            TextField::create('StoreEmail')
147
                ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email'))
148
                ->setDescription(_t(
149
                    'FoxyStripeSiteConfig.StoreEmailDescription',
150
                    'This is the email address of your store. By default, this will be the from address for your 
151
                            store receipts. '
152
                )),
153
            TextField::create('FromEmail')
154
                ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email'))
155
                ->setDescription(_t(
156
                    'FoxyStripeSiteConfig.FromEmailDescription',
157
                    'Used for when you want to specify a different from email than your store\'s email address'
158
                )),
159
            TextField::create('StorePostalCode', 'Postal Code'),
160
            CountryDropdownField::create('StoreCountry', 'Country'),
161
            TextField::create('StoreRegion', 'State/Region'),
162
            TextField::create('StoreLocaleCode', 'Locale Code')
163
                ->setDescription('example: en_US'),
164
            TextField::create('StoreTimezone', 'Store timezone'),
165
            TextField::create('StoreLogoURL', 'Logo URL')
166
                ->setAttribute('placeholder', 'http://'),
167
        ));
168
169
        $fields->addFieldsToTab('Root.Advanced', [
170
            HeaderField::create('AdvanceHeader', _t(
171
                'FoxyStripeSiteConfig.AdvancedHeader',
172
                'Advanced Settings'
173
            ), 3),
174
            LiteralField::create('AdvancedIntro', _t(
175
                'FoxyStripeSiteConfig.AdvancedIntro',
176
                '<p>Maps to data in your 
177
                    <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">
178
                        FoxyCart advanced store settings
179
                    </a>.</p>'
180
            )),
181
            DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()),
182
            CheckboxField::create('BccEmail', 'BCC Admin Email')
183
                ->setDescription('bcc all receipts to store\'s email address'),
184
            CheckboxField::create('UseWebhook', 'Use Webhook')
185
                ->setDescription('record order history in CMS, allows customers to view their order history'),
186
            ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()),
187
            ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()),
188
            CheckboxField::create('CartValidation', 'Use cart validation'),
189
            CheckboxField::create('UseSingleSignOn', 'Use single sign on')
190
                ->setDescription('Sync user accounts between FoxyCart and your website'),
191
            ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()),
192
            CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'),
193
        ]);
194
195
        // configuration warning
196
        if (FoxyCart::store_name_warning() !== null) {
197
            $fields->insertBefore(LiteralField::create(
198
                'StoreSubDomainHeaderWarning',
199
                _t(
200
                    'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning',
201
                    '<p class="message error">Store Domain must be entered below
202
                        </a></p>'
203
                )
204
            ), 'StoreDetails');
205
        }
206
207
        // products tab
208
        $fields->addFieldsToTab('Root.Products', array(
209
            HeaderField::create('ProductHeader', _t(
210
                'FoxyStripeSiteConfig.ProductHeader',
211
                'Products'
212
            ), 3),
213
            CheckboxField::create('MultiGroup')
214
                ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups'))
215
                ->setDescription(_t(
216
                    'FoxyStripeSiteConfig.MultiGroupDescription',
217
                    'Allows products to be shown in multiple Product Groups'
218
                )),
219
            HeaderField::create('ProductGroupHD', _t(
220
                'FoxyStripeSiteConfig.ProductGroupHD',
221
                'Product Groups'
222
            ), 3),
223
            NumericField::create('ProductLimit')
224
                ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page'))
225
                ->setDescription(_t(
226
                    'FoxyStripeSiteConfig.ProductLimitDescription',
227
                    'Number of Products to show per page on a Product Group'
228
                )),
229
            HeaderField::create('ProductQuantityHD', _t(
230
                'FoxyStripeSiteConfig.ProductQuantityHD',
231
                'Product Form Max Quantity'
232
            ), 3),
233
            NumericField::create('MaxQuantity')
234
                ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity'))
235
                ->setDescription(_t(
236
                    'FoxyStripeSiteConfig.MaxQuantityDescription',
237
                    'Sets max quantity for product form dropdown (add to cart form - default 10)'
238
                )),
239
        ));
240
241
        // categories tab
242
        $fields->addFieldsToTab('Root.Categories', array(
243
            HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3),
244
            LiteralField::create('CategoryDescrip', _t(
245
                'FoxyStripeSiteConfig.CategoryDescrip',
246
                '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be 
247
                        accomplished by product options alone, including category specific coupon codes, 
248
                        shipping and handling fees, and email receipts. 
249
                        <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">
250
                            Learn More
251
                        </a></p>
252
                        <p>Categories you\'ve created in FoxyStripe must also be created in your 
253
                            <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" 
254
                                target="_blank">FoxyCart Categories</a> admin panel.</p>'
255
            )),
256
            GridField::create(
257
                'ProductCategory',
258
                _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'),
259
                ProductCategory::get(),
0 ignored issues
show
Bug introduced by
Dynamic\FoxyStripe\Model\ProductCategory::get() of type SilverStripe\ORM\DataList is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

259
                /** @scrutinizer ignore-type */ ProductCategory::get(),
Loading history...
260
                GridFieldConfig_RecordEditor::create()
261
            ),
262
        ));
263
264
        // option groups tab
265
        $fields->addFieldsToTab('Root.Groups', array(
266
            HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3),
267
            LiteralField::create('OptionGroupsDescrip', _t(
268
                'FoxyStripeSiteConfig.OptionGroupsDescrip',
269
                '<p>Product Option Groups allow you to name a set of product options.</p>'
270
            )),
271
            GridField::create(
272
                'OptionGroup',
273
                _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'),
274
                OptionGroup::get(),
275
                GridFieldConfig_RecordEditor::create()
276
            ),
277
        ));
278
279
        // api tab
280
        $fields->addFieldsToTab('Root.API', [
281
            HeaderField::create('APIHD', 'FoxyCart API Settings', 3),
282
            TextField::create('client_id', 'FoxyCart Client ID'),
283
            TextField::create('client_secret', 'FoxyCart Client Secret'),
284
            TextField::create('access_token', 'FoxyCart Access Token'),
285
            TextField::create('refresh_token', 'FoxyCart Refresh Token'),
286
        ]);
287
288
        $this->extend('updateCMSFields', $fields);
289
290
        return $fields;
291
    }
292
293
    /**
294
     * @return FieldList
295
     */
296
    public function getCMSActions()
297
    {
298
        if (Permission::check('ADMIN') || Permission::check('EDIT_FOXYSTRIPE_SETTING')) {
299
            $actions = new FieldList(
300
                FormAction::create('save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save'))
0 ignored issues
show
Bug introduced by
'save_foxystripe_setting' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

300
                FormAction::create(/** @scrutinizer ignore-type */ 'save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save'))
Loading history...
301
                    ->addExtraClass('btn-primary font-icon-save')
302
            );
303
        } else {
304
            $actions = FieldList::create();
305
        }
306
        $this->extend('updateCMSActions', $actions);
307
308
        return $actions;
309
    }
310
311
    /**
312
     * @throws \SilverStripe\ORM\ValidationException
313
     */
314
    public function requireDefaultRecords()
315
    {
316
        parent::requireDefaultRecords();
317
        $config = self::current_foxystripe_setting();
318
319
        if (!$config) {
320
            self::make_foxystripe_setting();
321
            DB::alteration_message('Added default FoxyStripe Setting', 'created');
322
        }
323
324
        if (!$config->StoreKey) {
325
            $key = FoxyCart::setStoreKey();
326
            while (!ctype_alnum($key)) {
327
                $key = FoxyCart::setStoreKey();
328
            }
329
            $config->StoreKey = $key;
0 ignored issues
show
Bug Best Practice introduced by
The property StoreKey does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
330
            $config->write();
331
            DB::alteration_message('Created FoxyCart Store Key '.$key, 'created');
332
        }
333
    }
334
335
    /**
336
     * @return string
337
     */
338
    public function CMSEditLink()
339
    {
340
        return FoxyStripeAdmin::singleton()->Link();
341
    }
342
343
    /**
344
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
345
     *
346
     * @return bool|int|null
347
     */
348
    public function canEdit($member = null)
349
    {
350
        if (!$member) {
351
            $member = Security::getCurrentUser();
352
        }
353
354
        $extended = $this->extendedCan('canEdit', $member);
355
        if ($extended !== null) {
356
            return $extended;
357
        }
358
359
        return Permission::checkMember($member, 'EDIT_FOXYSTRIPE_SETTING');
360
    }
361
362
    /**
363
     * @return array
364
     */
365
    public function providePermissions()
366
    {
367
        return array(
368
            'EDIT_FOXYSTRIPE_SETTING' => array(
369
                'name' => _t(
370
                    'FoxyStripeSetting.EDIT_FOXYSTRIPE_SETTING',
371
                    'Manage FoxyStripe settings'
372
                ),
373
                'category' => _t(
374
                    'Permissions.PERMISSIONS_FOXYSTRIPE_SETTING',
375
                    'FoxyStripe'
376
                ),
377
                'help' => _t(
378
                    'FoxyStripeSetting.EDIT_PERMISSION_FOXYSTRIPE_SETTING',
379
                    'Ability to edit the settings of a FoxyStripe Store.'
380
                ),
381
                'sort' => 400,
382
            ),
383
        );
384
    }
385
386
    /**
387
     * Get the current sites {@link GlobalSiteSetting}, and creates a new one
388
     * through {@link make_global_config()} if none is found.
389
     *
390
     * @return FoxyStripeSetting|DataObject
391
     * @throws \SilverStripe\ORM\ValidationException
392
     */
393
    public static function current_foxystripe_setting()
394
    {
395
        if ($config = self::get()->first()) {
396
            return $config;
397
        }
398
399
        return self::make_foxystripe_setting();
400
    }
401
402
    /**
403
     * Create {@link GlobalSiteSetting} with defaults from language file.
404
     *
405
     * @return static
406
     * @throws \SilverStripe\ORM\ValidationException
407
     */
408
    public static function make_foxystripe_setting()
409
    {
410
        $config = self::create();
411
        $config->write();
412
413
        return $config;
414
    }
415
416
    /**
417
     * Add $GlobalConfig to all SSViewers.
418
     */
419
    public static function get_template_global_variables()
420
    {
421
        return array(
422
            'FoxyStripe' => 'current_foxystripe_config',
423
        );
424
    }
425
426
    /**
427
     * @return string
428
     */
429
    private static function getSSOLink()
430
    {
431
        return Director::absoluteBaseURL().'foxystripe/sso/';
432
    }
433
434
    /**
435
     * @return string
436
     */
437
    private static function getDataFeedLink()
438
    {
439
        return Director::absoluteBaseURL().'foxystripe/';
440
    }
441
442
    /**
443
     * @return array
444
     */
445
    public function getCheckoutTypes()
446
    {
447
        return [
448
            'default_account' => 'Allow guest and customer accounts, default to account',
449
            'default_guest' => 'Allow guest and customer accounts, default to guest',
450
            'account_only' => 'Allow customer accounts only',
451
            'guest_only' => 'Allow guests only',
452
        ];
453
    }
454
455
    /**
456
     * @return array
457
     */
458
    public function getDataMap()
459
    {
460
        return [
461
            'store_name' => $this->owner->StoreTitle,
0 ignored issues
show
Bug Best Practice introduced by
The property owner does not exist on Dynamic\FoxyStripe\Model\FoxyStripeSetting. Since you implemented __get, consider adding a @property annotation.
Loading history...
462
            'store_domain' => $this->owner->StoreName,
463
            'store_url' => $this->owner->StoreURL,
464
            'receipt_continue_url' => $this->owner->ReceiptURL,
465
            'store_email' => $this->owner->StoreEmail,
466
            'from_email' => $this->owner->FromEmail,
467
            'postal_code' => $this->owner->StorePostalCode,
468
            'country' => $this->owner->StoreCountry,
469
            'region' => $this->owner->StoreRegion,
470
            'locale_code' => $this->owner->StoreLocaleCode,
471
            'logo_url' => $this->owner->StoreLogoURL,
472
            'checkout_type' => $this->owner->CheckoutType,
473
            'bcc_on_receipt_email' => $this->owner->BccEmail,
474
            'use_webhook' => $this->owner->UseWebhook,
475
            'webhook_url' => $this->getDataFeedLink(),
476
            'webhook_key' => $this->owner->StoreKey,
477
            'use_cart_validation' => $this->owner->CartValidation,
478
            'use_single_sign_on' => $this->owner->UseSingleSignOn,
479
            'single_sign_on_url' => $this->getSSOLink(),
480
            'customer_password_hash_type' => 'sha1_salted_suffix',
481
            'customer_password_hash_config' => 40,
482
            'features_multiship' => $this->owner->AllowMultiship,
483
            //'timezone' => $this->StoreTimezone,
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
484
        ];
485
    }
486
487
    /**
488
     * if StoreTitle is empty, grab values from FoxyCart.
489
     *
490
     * example of 2 way sync for future reference
491
     *
492
     * @throws \Psr\Container\NotFoundExceptionInterface
493
     */
494
    public function onBeforeWrite()
495
    {
496
        parent::onBeforeWrite();
497
498
        if ($this->owner->ID && !$this->owner->StoreTitle && $this->owner->access_token) {
0 ignored issues
show
Bug Best Practice introduced by
The property owner does not exist on Dynamic\FoxyStripe\Model\FoxyStripeSetting. Since you implemented __get, consider adding a @property annotation.
Loading history...
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
499
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
500
            if ($fc = new FoxyStripeClient()) {
501
                $client = $fc->getClient();
502
                $errors = [];
503
504
                $result = $client->get($fc->getCurrentStore());
505
                $this->owner->StoreTitle = $result['store_name'];
506
507
                $errors = array_merge($errors, $client->getErrors($result));
508
                if (count($errors)) {
509
                    Injector::inst()->get(LoggerInterface::class)
510
                        ->error('FoxyStripeSiteConfig::onBeforeWrite errors - ' . json_encode($errors));
511
                }
512
            }
513
            */
514
        }
515
    }
516
517
    /**
518
     * @throws \Psr\Container\NotFoundExceptionInterface
519
     */
520
    public function onAfterWrite()
521
    {
522
        parent::onAfterWrite();
523
524
        if ($this->owner->isChanged() && $this->owner->access_token) {
0 ignored issues
show
Bug Best Practice introduced by
The property owner does not exist on Dynamic\FoxyStripe\Model\FoxyStripeSetting. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method isChanged() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

524
        if ($this->owner->/** @scrutinizer ignore-call */ isChanged() && $this->owner->access_token) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
525
            if ($fc = new FoxyStripeClient()) {
526
                $fc->updateStore($this->getDataMap());
527
            }
528
        }
529
    }
530
}