Completed
Push — master ( f85faa...6214aa )
by Jason
10s
created

FormBlock::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.6492

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 5
cts 11
cp 0.4545
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 2.6492
1
<?php
2
3
class FormBlock extends Block
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Form Block';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Form Blocks';
14
15
    /**
16
     * @var array
17
     */
18
    private static $db = array(
19
        'Content' => 'HTMLText',
20
    );
21
22
    /**
23
     * @var array
24
     */
25
    private static $has_one = array(
26
        'Form' => 'UserDefinedForm',
27
    );
28
29
    /**
30
     * @return FieldList
31
     */
32 1 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34 1
        $fields = singleton('Block')->getCMSFields();
35
36 1
        if (class_exists('UserDefinedForm')) {
37
            $fields->addFieldToTab('Root.Main', DropdownField::create(
38
                'FormID',
39
                'Form',
40
                UserDefinedForm::get()->map()
41
            )->setEmptyString(''));
42
        }
43
44 1
        $fields->addFieldToTab('Root.Main', HtmlEditorField::create('Content'));
45
46 1
        return $fields;
47
    }
48
49
    /**
50
     * @return Forms|HTMLText
51
     */
52
    public function BlockForm()
53
    {
54
        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...
55
            $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...
56
            $current = Controller::curr();
57
            if ($current && $current->getAction() == 'finished') {
58
                return $controller->renderWith('ReceivedFormSubmission');
59
            }
60
            $form = $controller->Form();
61
            return $form;
62
        }
63
    }
64
65
    /**
66
     * @param null $member
67
     * @return bool
68
     */
69 View Code Duplication
    public function canCreate($member = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        if (!class_exists('UserDefinedForm')) {
72
            return false;
73
        }
74
75
        // Standard mechanism for accepting permission changes from extensions
76
        $extended = $this->extendedCan('canCreate', $member);
77
        if ($extended !== null) {
78
            return $extended;
79
        }
80
81
        return parent::canCreate();
82
    }
83
84
    /**
85
     * @param null $member
86
     * @return bool
87
     */
88 View Code Duplication
    public function canView($member = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        if (!class_exists('UserDefinedForm')) {
91
            return false;
92
        }
93
94
        // Standard mechanism for accepting permission changes from extensions
95
        $extended = $this->extendedCan('canView', $member);
96
        if ($extended !== null) {
97
            return $extended;
98
        }
99
100
        return parent::canView();
101
    }
102
}