SmartChimpSignupWidget   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 68
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Title() 0 4 1
B getCMSFields() 0 43 2
1
<?php
2
/**
3
 * Shows a widget encouraging users to sign up
4
 * by months or years.
5
 *
6
 * @package blog
7
 */
8
class SmartChimpSignupWidget extends Widget
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...
9
{
10
    public static $db = array(
11
        'BetterTitle' => 'Varchar',
12
        'Introduction' => 'Text',
13
        'TextOnButton' => 'Varchar'
14
    );
15
    
16
    public static $has_one = array(
17
        "NewsletterSignUpPage" => "SiteTree"
18
    );
19
    
20
    public static $title = 'Sign Up for Newsletter';
21
22
    public static $cmsTitle = 'Sign Up for Newsletter';
23
    
24
    public static $description = 'Links to newsletter signup';
25
26
    public function Title()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
27
    {
28
        return $this->BetterTitle;
0 ignored issues
show
Documentation introduced by
The property BetterTitle does not exist on object<SmartChimpSignupWidget>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
29
    }
30
    
31
    
32
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
33
    {
34
        $objects = DataObject::get("SmartChimpSignupPage");
35
        $fields = new FieldSet();
36
        if ($objects) {
37
            $fields->push(
38
                new TextField(
39
                    'BetterTitle',
40
                    'Title'
41
                )
42
            );
43
            $fields->push(
44
                new TextAreaField(
45
                    'Introduction',
46
                    'Introduction',
47
                    $row = 5,
48
                    $cols = 5
49
                )
50
            );
51
            $fields->push(
52
                new TextField(
53
                    'TextOnButton',
54
                    'Text On Button'
55
                )
56
            );
57
            $fields->push(
58
                new DropdownField(
59
                    'NewsletterSignUpPageID',
60
                    'Signup Page',
61
                    $objects->toDropdownMap()
62
                )
63
            );
64
        } else {
65
            $fields->push(
66
                new LiteralField(
67
                    'NoSmartChimpSignupPage',
68
                    '<p>Please first create a sign-up page.</p>'
69
                )
70
            );
71
        }
72
        $this->extend('updateCMSFields', $fields);
73
        return $fields;
74
    }
75
}
76