These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Twitter\Object; |
||
4 | |||
5 | use Assert\Assertion; |
||
6 | use Twitter\TwitterDatedObject; |
||
7 | use Twitter\TwitterEventTarget; |
||
8 | |||
9 | class TwitterEvent implements TwitterDatedObject |
||
10 | { |
||
11 | const ACCESS_REVOKED = 'access_revoked'; |
||
12 | const BLOCK = 'block'; |
||
13 | const UNBLOCK = 'unblock'; |
||
14 | const FAVORITE = 'favorite'; |
||
15 | const UNFAVORITE = 'unfavorite'; |
||
16 | const FOLLOW = 'follow'; |
||
17 | const UNFOLLOW = 'unfollow'; |
||
18 | const LIST_CREATED = 'list_created'; |
||
19 | const LIST_DESTROYED = 'list_destroyed'; |
||
20 | const LIST_UPDATED = 'list_updated'; |
||
21 | const LIST_MEMBER_ADDED = 'list_member_added'; |
||
22 | const LIST_MEMBER_REMOVED = 'list_member_removed'; |
||
23 | const LIST_USER_SUBSCRIBED = 'list_user_subscribed'; |
||
24 | const LIST_USER_UNSUBSCRIBED = 'list_user_unsubscribed'; |
||
25 | const USER_UPDATED = 'user_update'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $type; |
||
31 | |||
32 | /** |
||
33 | * @var TwitterUser |
||
34 | */ |
||
35 | private $source; |
||
36 | |||
37 | /** |
||
38 | * @var TwitterUser |
||
39 | */ |
||
40 | private $target; |
||
41 | |||
42 | /** |
||
43 | * @var TwitterEventTarget |
||
44 | */ |
||
45 | private $object; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTimeInterface |
||
49 | */ |
||
50 | private $date; |
||
51 | |||
52 | /** |
||
53 | * Constructor. |
||
54 | */ |
||
55 | 6 | public function __construct() |
|
56 | { |
||
57 | 6 | } |
|
58 | |||
59 | /** |
||
60 | * @return \DateTimeInterface |
||
61 | */ |
||
62 | 6 | public function getDate() |
|
63 | { |
||
64 | 6 | return $this->date; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return TwitterEventTarget |
||
69 | */ |
||
70 | 6 | public function getObject() |
|
71 | { |
||
72 | 6 | return $this->object; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return TwitterUser |
||
77 | */ |
||
78 | 6 | public function getSource() |
|
79 | { |
||
80 | 6 | return $this->source; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return TwitterUser |
||
85 | */ |
||
86 | 6 | public function getTarget() |
|
87 | { |
||
88 | 6 | return $this->target; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | 6 | public function getType() |
|
95 | { |
||
96 | 6 | return $this->type; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return string |
||
101 | */ |
||
102 | 3 | public function __toString() |
|
103 | { |
||
104 | 3 | return 'Event [' . $this->type . ']: ' . $this->object; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Static constructor. |
||
109 | * |
||
110 | * @param string $type |
||
111 | * @param TwitterUser $source |
||
112 | * @param TwitterUser $target |
||
113 | * @param TwitterEventTarget $object |
||
114 | * @param \DateTimeInterface $date |
||
115 | * |
||
116 | * @return TwitterEvent |
||
117 | */ |
||
118 | 6 | public static function create( |
|
119 | $type, |
||
120 | TwitterUser $source, |
||
121 | TwitterUser $target = null, |
||
122 | TwitterEventTarget $object = null, |
||
123 | \DateTimeInterface $date = null |
||
124 | ) { |
||
125 | 6 | $obj = new self(); |
|
126 | |||
127 | 6 | Assertion::notNull($date); |
|
128 | 6 | Assertion::eq(new \DateTimeZone('UTC'), $date->getTimezone()); |
|
1 ignored issue
–
show
|
|||
129 | |||
130 | 6 | $obj->type = $type; |
|
131 | |||
132 | 6 | $obj->source = $source; |
|
133 | 6 | $obj->target = $target; |
|
134 | 6 | $obj->object = $object; |
|
135 | |||
136 | 6 | $obj->date = $date; |
|
137 | |||
138 | 6 | return $obj; |
|
139 | } |
||
140 | } |
||
141 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: