Passed
Pull Request — master (#312)
by Jason
04:31
created

FoxyStripeSetting::getCMSFields()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 194
Code Lines 146

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 134
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 194
ccs 134
cts 134
cp 1
rs 8.2857
c 0
b 0
f 0
cc 2
eloc 146
nc 2
nop 0
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 1
    public function getCMSFields()
98
    {
99 1
        $fields = FieldList::create(
100 1
            TabSet::create(
101 1
                'Root',
102 1
                $tabMain = Tab::create(
103 1
                    '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 1
            HiddenField::create('ID')
107
        );
108 1
        $tabMain->setTitle('Settings');
109
110
        // settings tab
111 1
        $fields->addFieldsToTab('Root.Main', array(
112
            // Store Details
113 1
            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 1
            LiteralField::create('DetailsIntro', _t(
115 1
                'FoxyStripeSiteConfig.DetailsIntro',
116 1
                '<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 1
            TextField::create('StoreTitle')
122 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name'))
123 1
                ->setDescription(_t(
124 1
                    'FoxyStripeSiteConfig.StoreTitleDescription',
125 1
                    'The name of your store as you\'d like it displayed to your customers'
126
                )),
127 1
            TextField::create('StoreName')
128 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain'))
129 1
                ->setDescription(_t(
130 1
                    'FoxyStripeSiteConfig.StoreNameDescription',
131 1
                    'This is a unique FoxyCart subdomain for your cart, checkout, and receipt'
132
                )),
133 1
            TextField::create('StoreURL')
134 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL'))
135 1
                ->setDescription(_t(
136 1
                    'FoxyStripeSiteConfig.StoreURLDescription',
137 1
                    'The URL of your online store'
138
                )),
139 1
            TextField::create('ReceiptURL')
140 1
                ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL'))
141 1
                ->setDescription(_t(
142 1
                    'FoxyStripeSiteConfig.ReceiptURLDescription',
143 1
                    '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 1
            TextField::create('StoreEmail')
147 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email'))
148 1
                ->setDescription(_t(
149 1
                    'FoxyStripeSiteConfig.StoreEmailDescription',
150 1
                    'This is the email address of your store. By default, this will be the from address for your 
151
                            store receipts. '
152
                )),
153 1
            TextField::create('FromEmail')
154 1
                ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email'))
155 1
                ->setDescription(_t(
156 1
                    'FoxyStripeSiteConfig.FromEmailDescription',
157 1
                    'Used for when you want to specify a different from email than your store\'s email address'
158
                )),
159 1
            TextField::create('StorePostalCode', 'Postal Code'),
160 1
            CountryDropdownField::create('StoreCountry', 'Country'),
161 1
            TextField::create('StoreRegion', 'State/Region'),
162 1
            TextField::create('StoreLocaleCode', 'Locale Code')
163 1
                ->setDescription('example: en_US'),
164 1
            TextField::create('StoreTimezone', 'Store timezone'),
165 1
            TextField::create('StoreLogoURL', 'Logo URL')
166 1
                ->setAttribute('placeholder', 'http://'),
167
        ));
168
169 1
        $fields->addFieldsToTab('Root.Advanced', [
170 1
            HeaderField::create('AdvanceHeader', _t(
171 1
                'FoxyStripeSiteConfig.AdvancedHeader',
172 1
                'Advanced Settings'
173 1
            ), 3),
174 1
            LiteralField::create('AdvancedIntro', _t(
175 1
                'FoxyStripeSiteConfig.AdvancedIntro',
176 1
                '<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 1
            DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()),
182 1
            CheckboxField::create('BccEmail', 'BCC Admin Email')
183 1
                ->setDescription('bcc all receipts to store\'s email address'),
184 1
            CheckboxField::create('UseWebhook', 'Use Webhook')
185 1
                ->setDescription('record order history in CMS, allows customers to view their order history'),
186 1
            ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()),
187 1
            ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()),
188 1
            CheckboxField::create('CartValidation', 'Use cart validation'),
189 1
            CheckboxField::create('UseSingleSignOn', 'Use single sign on')
190 1
                ->setDescription('Sync user accounts between FoxyCart and your website'),
191 1
            ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()),
192 1
            CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'),
193
        ]);
194
195
        // configuration warning
196 1
        if (FoxyCart::store_name_warning() !== null) {
197 1
            $fields->insertBefore(LiteralField::create(
198 1
                'StoreSubDomainHeaderWarning',
199 1
                _t(
200 1
                    'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning',
201 1
                    '<p class="message error">Store Domain must be entered below
202
                        </a></p>'
203
                )
204 1
            ), 'StoreDetails');
205
        }
206
207
        // products tab
208 1
        $fields->addFieldsToTab('Root.Products', array(
209 1
            HeaderField::create('ProductHeader', _t(
210 1
                'FoxyStripeSiteConfig.ProductHeader',
211 1
                'Products'
212 1
            ), 3),
213 1
            CheckboxField::create('MultiGroup')
214 1
                ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups'))
215 1
                ->setDescription(_t(
216 1
                    'FoxyStripeSiteConfig.MultiGroupDescription',
217 1
                    'Allows products to be shown in multiple Product Groups'
218
                )),
219 1
            HeaderField::create('ProductGroupHD', _t(
220 1
                'FoxyStripeSiteConfig.ProductGroupHD',
221 1
                'Product Groups'
222 1
            ), 3),
223 1
            NumericField::create('ProductLimit')
224 1
                ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page'))
225 1
                ->setDescription(_t(
226 1
                    'FoxyStripeSiteConfig.ProductLimitDescription',
227 1
                    'Number of Products to show per page on a Product Group'
228
                )),
229 1
            HeaderField::create('ProductQuantityHD', _t(
230 1
                'FoxyStripeSiteConfig.ProductQuantityHD',
231 1
                'Product Form Max Quantity'
232 1
            ), 3),
233 1
            NumericField::create('MaxQuantity')
234 1
                ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity'))
235 1
                ->setDescription(_t(
236 1
                    'FoxyStripeSiteConfig.MaxQuantityDescription',
237 1
                    'Sets max quantity for product form dropdown (add to cart form - default 10)'
238
                )),
239
        ));
240
241
        // categories tab
242 1
        $fields->addFieldsToTab('Root.Categories', array(
243 1
            HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3),
244 1
            LiteralField::create('CategoryDescrip', _t(
245 1
                'FoxyStripeSiteConfig.CategoryDescrip',
246 1
                '<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 1
            GridField::create(
257 1
                'ProductCategory',
258 1
                _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'),
259 1
                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 1
                GridFieldConfig_RecordEditor::create()
261
            ),
262
        ));
263
264
        // option groups tab
265 1
        $fields->addFieldsToTab('Root.Groups', array(
266 1
            HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3),
267 1
            LiteralField::create('OptionGroupsDescrip', _t(
268 1
                'FoxyStripeSiteConfig.OptionGroupsDescrip',
269 1
                '<p>Product Option Groups allow you to name a set of product options.</p>'
270
            )),
271 1
            GridField::create(
272 1
                'OptionGroup',
273 1
                _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'),
274 1
                OptionGroup::get(),
275 1
                GridFieldConfig_RecordEditor::create()
276
            ),
277
        ));
278
279
        // api tab
280 1
        $fields->addFieldsToTab('Root.API', [
281 1
            HeaderField::create('APIHD', 'FoxyCart API Settings', 3),
282 1
            TextField::create('client_id', 'FoxyCart Client ID'),
283 1
            TextField::create('client_secret', 'FoxyCart Client Secret'),
284 1
            TextField::create('access_token', 'FoxyCart Access Token'),
285 1
            TextField::create('refresh_token', 'FoxyCart Refresh Token'),
286
        ]);
287
288 1
        $this->extend('updateCMSFields', $fields);
289
290 1
        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 3
    public function requireDefaultRecords()
315
    {
316 3
        parent::requireDefaultRecords();
317 3
        $config = self::current_foxystripe_setting();
318
319 3
        if (!$config) {
320
            self::make_foxystripe_setting();
321
            DB::alteration_message('Added default FoxyStripe Setting', 'created');
322
        }
323
324 3
        if (!$config->StoreKey) {
325 3
            $key = FoxyCart::setStoreKey();
326 3
            while (!ctype_alnum($key)) {
327
                $key = FoxyCart::setStoreKey();
328
            }
329 3
            $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 3
            $config->write();
331 3
            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 49
    public static function current_foxystripe_setting()
394
    {
395 49
        if ($config = self::get()->first()) {
396 49
            return $config;
397
        }
398
399 49
        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 49
    public static function make_foxystripe_setting()
409
    {
410 49
        $config = self::create();
411 49
        $config->write();
412
413 49
        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 2
    private static function getSSOLink()
430
    {
431 2
        return Director::absoluteBaseURL().'foxystripe/sso/';
432
    }
433
434
    /**
435
     * @return string
436
     */
437 2
    private static function getDataFeedLink()
438
    {
439 2
        return Director::absoluteBaseURL().'foxystripe/';
440
    }
441
442
    /**
443
     * @return array
444
     */
445 1
    public function getCheckoutTypes()
446
    {
447
        return [
448 1
            '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 1
    public function getDataMap()
459
    {
460
        return [
461 1
            '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 1
            'store_domain' => $this->owner->StoreName,
463 1
            'store_url' => $this->owner->StoreURL,
464 1
            'receipt_continue_url' => $this->owner->ReceiptURL,
465 1
            'store_email' => $this->owner->StoreEmail,
466 1
            'from_email' => $this->owner->FromEmail,
467 1
            'postal_code' => $this->owner->StorePostalCode,
468 1
            'country' => $this->owner->StoreCountry,
469 1
            'region' => $this->owner->StoreRegion,
470 1
            'locale_code' => $this->owner->StoreLocaleCode,
471 1
            'logo_url' => $this->owner->StoreLogoURL,
472 1
            'checkout_type' => $this->owner->CheckoutType,
473 1
            'bcc_on_receipt_email' => $this->owner->BccEmail,
474 1
            'use_webhook' => $this->owner->UseWebhook,
475 1
            'webhook_url' => $this->getDataFeedLink(),
476 1
            'webhook_key' => $this->owner->StoreKey,
477 1
            'use_cart_validation' => $this->owner->CartValidation,
478 1
            'use_single_sign_on' => $this->owner->UseSingleSignOn,
479 1
            'single_sign_on_url' => $this->getSSOLink(),
480 1
            'customer_password_hash_type' => 'sha1_salted_suffix',
481 1
            'customer_password_hash_config' => 40,
482 1
            '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 49
    public function onBeforeWrite()
495
    {
496 49
        parent::onBeforeWrite();
497
498 49
        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 49
    public function onAfterWrite()
521
    {
522 49
        parent::onAfterWrite();
523
524 49
        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
}
531