FormBlock   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 36.67%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 4
dl 0
loc 88
ccs 11
cts 30
cp 0.3667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 18 2
A BlockForm() 0 12 4
A canCreate() 0 7 2
A canView() 0 7 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3 1
if (!class_exists('UserDefinedForm')) {
4 1
    return;
5
}
6
7
class FormBlock extends Block
8
{
9
    /**
10
     * @var string
11
     */
12
    private static $singular_name = 'Form Block';
13
14
    /**
15
     * @var string
16
     */
17
    private static $plural_name = 'Form Blocks';
18
19
    /**
20
     * @var array
21
     */
22
    private static $db = array(
23
        'Content' => 'HTMLText',
24
    );
25
26
    /**
27
     * @var array
28
     */
29
    private static $has_one = array(
30
        'Form' => 'UserDefinedForm',
31
    );
32
33
    /**
34
     * @return FieldList
35
     */
36 1
    public function getCMSFields()
37
    {
38 1
        $fields = singleton('Block')->getCMSFields();
39
40 1
        if (class_exists('UserDefinedForm')) {
41
            $fields->addFieldToTab('Root.Main', DropdownField::create(
42
                'FormID',
43
                'Form',
44
                UserDefinedForm::get()->map()
45
                )->setEmptyString('')
46
                ->setDescription('select an existing User Defined Form to display')
47
            );
48
        }
49
50 1
        $fields->addFieldToTab('Root.Main', HtmlEditorField::create('Content'));
51
52 1
        return $fields;
53
    }
54
55
    /**
56
     * @return Forms|HTMLText
57
     */
58
    public function BlockForm()
59
    {
60
        if ($this->Form()->exists()) {
0 ignored issues
show
Documentation Bug introduced by
The method Form does not exist on object<FormBlock>? 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...
61
            $controller = new UserDefinedForm_Controller($this->Form());
0 ignored issues
show
Documentation Bug introduced by
The method Form does not exist on object<FormBlock>? 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...
62
            $current = Controller::curr();
63
            if ($current && $current->getAction() == 'finished') {
64
                return $controller->renderWith('ReceivedFormSubmission');
65
            }
66
            $form = $controller->Form();
67
            return $form;
68
        }
69
    }
70
71
    /**
72
     * @param null $member
73
     * @return bool
74
     */
75 1
    public function canCreate($member = null)
76
    {
77 1
        if (!class_exists('UserDefinedForm')) {
78 1
            return false;
79
        }
80
        return parent::canCreate();
81
    }
82
83
    /**
84
     * @param null $member
85
     * @return bool
86
     */
87 1
    public function canView($member = null)
88
    {
89 1
        if (!class_exists('UserDefinedForm')) {
90 1
            return false;
91
        }
92
        return parent::canView();
93
    }
94
}