Completed
Pull Request — master (#9)
by
unknown
08:34
created

MyTwitterData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 4

7 Methods

Rating   Name   Duplication   Size   Complexity  
A forTemplate() 0 4 1
A Link() 0 4 1
A canView() 0 4 1
A canCreate() 0 4 1
A canEdit() 0 4 1
A canDelete() 0 4 1
A HideNice() 0 4 1
1
<?php
2
3
namespace SunnysideUp\ShareThis;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Security\Permission;
7
use SilverStripe\ORM\DataObject;
8
9
/**
10
 * MyTwitterData
11
 */
12
class MyTwitterData extends DataObject
13
{
14
    /**
15
     * @var string
16
     */
17
    private static $table_name = 'MyTwitterData';
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...
18
19
    /**
20
     * @var string
21
     */
22
    private static $username = "";
23
24
    /**
25
     * @var array
26
     */
27
    private static $db = [
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...
28
        "Date" => "Datetime",
29
        "TwitterID" => "Varchar(64)",
30
        "Title" => "HTMLText",
31
        "Hide" => "Boolean"
32
    ];
33
34
    /**
35
     * @var array
36
     */
37
    private static $summary_fields = [
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...
38
        "Date" => "Date",
39
        "Title" => "Title",
40
        "HideNice" => "Hide"
41
    ];
42
43
    /**
44
     * @var array
45
     */
46
    private static $indexes = [
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...
47
        "TwitterID" => true
48
    ];
49
50
    /**
51
     * @var array
52
     */
53
    private static $casting = [
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...
54
        "Link" => "Varchar",
55
        "HideNice" => "Varchar"
56
    ];
57
58
    /**
59
     * @var string
60
     */
61
    private static $default_sort = "\"Date\" DESC";
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...
62
63
    /**
64
     * @return string
65
     */
66
    public function forTemplate()
67
    {
68
        return $this->Title;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function Link()
75
    {
76
        return "https://twitter.com/".Config::inst()->get(MyTwitterData::class, "username")."/status/".$this->TwitterID;
0 ignored issues
show
Documentation introduced by
The property TwitterID does not exist on object<SunnysideUp\ShareThis\MyTwitterData>. 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...
77
    }
78
79
    /**
80
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
81
     */
82
    public function canView($member = null)
83
    {
84
        return Permission::checkMember($member, 'SOCIAL_MEDIA');
85
    }
86
87
    /**
88
     * @return boolean
89
     */
90
    public function canCreate($member = null, $context = [])
91
    {
92
        return false;
93
    }
94
95
    /**
96
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
97
     */
98
    public function canEdit($member = null)
99
    {
100
        return Permission::checkMember($member, 'SOCIAL_MEDIA');
101
    }
102
103
    /**
104
     * @return boolean
105
     */
106
    public function canDelete($member = null)
107
    {
108
        return false;
109
    }
110
111
    /**
112
     * @return boolean
113
     */
114
    public function HideNice()
115
    {
116
        return $this->dbObject('Hide')->Nice();
117
    }
118
}
119