EvernoteAdminController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 87
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getEditForm() 0 33 3
A save_evernotesettings() 0 16 2
1
<?php
2
3
/**
4
 * @package EvernoteSettings
5
 */
6
class EvernoteAdminController extends LeftAndMain
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    /**
10
     * @var string
11
     */
12
    private static $url_segment = 'evernote-settings';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
    /**
14
     * @var string
15
     */
16
    private static $url_rule = '/$Action/$ID/$OtherID';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_rule is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    /**
19
     * @var string
20
     */
21
    private static $menu_title = 'Evernote';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
    /**
23
     * @var string
24
     */
25
    private static $menu_icon = '/silverstripe-evernote/images/evernote.png';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
27
28
    /**
29
     * @param null $id Not used.
30
     * @param null $fields Not used.
31
     *
32
     * @return Form
33
     */
34
    public function getEditForm($id = null, $fields = null)
35
    {
36
37
        $evernoteSettings = EvernoteSettings::current_Evernote_settings();
38
        $fields = $evernoteSettings->getCMSFields();
39
40
        // Retrieve validator, if one has been setup
41
        if ($evernoteSettings->hasMethod("getCMSValidator")) {
42
            $validator = $evernoteSettings->getCMSValidator();
0 ignored issues
show
Documentation Bug introduced by
The method getCMSValidator does not exist on object<EvernoteSettings>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
43
        } else {
44
            $validator = null;
45
        }
46
47
        $actions = $evernoteSettings->getCMSActions();
48
49
        $form = CMSForm::create(
50
            $this, 'EditForm', $fields, $actions, $validator
51
        )->setHTMLID('Form_EditForm');
52
53
        $form->setResponseNegotiator($this->getResponseNegotiator());
0 ignored issues
show
Documentation introduced by
$this->getResponseNegotiator() is of type object<PjaxResponseNegotiator>, but the function expects a object<ResponseNegotiator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
        $form->addExtraClass('cms-content center cms-edit-form');
55
        $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
0 ignored issues
show
Documentation introduced by
$this->getTemplatesWithSuffix('_EditForm') is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
57
        if ($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
58
59
        $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
60
        $form->setAttribute('data-pjax-fragment', 'CurrentForm');
61
62
        $this->extend('updateEditForm', $form);
63
64
        return $form;
65
66
    }
67
68
    /**
69
     * Save the current sites {@link SiteConfig} into the database.
70
     *
71
     * @param array $data
72
     * @param Form $form
73
     * @return String
74
     */
75
    public function save_evernotesettings($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        $evernoteSettings = EvernoteSettings::current_Evernote_settings();
78
        $form->saveInto($evernoteSettings);
79
80
        try {
81
            $evernoteSettings->write();
82
        } catch (ValidationException $ex) {
83
            $form->sessionMessage($ex->getResult()->message(), 'bad');
84
            return $this->getResponseNegotiator()->respond($this->request);
85
        }
86
87
        $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
88
89
        return $form->forTemplate();
90
    }
91
92
}
93