Skip to content

Commit 936bf7c

Browse files
committed
Refactor to follow interface more closely
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent a66fd1c commit 936bf7c

3 files changed

Lines changed: 49 additions & 122 deletions

File tree

config/services.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ services:
130130
parent: notification.type.base
131131
shared: false
132132
calls:
133-
- [set_controller_helper, ['@controller.helper']]
134-
- [set_idea_factory, ['@phpbb.ideas.idea']]
135-
- [set_ideas_forum_id, ['@config']]
136-
- [set_user_loader, ['@user_loader']]
133+
- [set_additional_services, ['@config', '@controller.helper', '@phpbb.ideas.idea', '@user_loader']]
137134
tags:
138135
- { name: notification.type }

notification/type/status.php

Lines changed: 47 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,56 @@
1010

1111
namespace phpbb\ideas\notification\type;
1212

13+
use phpbb\config\config;
14+
use phpbb\controller\helper;
1315
use phpbb\ideas\ext;
16+
use phpbb\ideas\factory\idea;
17+
use phpbb\user_loader;
1418
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1519

1620
/**
1721
* Ideas status change notification class.
1822
*/
1923
class status extends \phpbb\notification\type\base
2024
{
21-
/** @var \phpbb\config\config */
25+
/** @var config */
2226
protected $config;
2327

24-
/** @var \phpbb\controller\helper */
28+
/** @var helper */
2529
protected $helper;
2630

27-
/** @var \phpbb\ideas\factory\idea */
31+
/** @var idea */
2832
protected $idea;
2933

30-
/** @var \phpbb\user_loader */
34+
/** @var user_loader */
3135
protected $user_loader;
3236

3337
/** @var int */
3438
protected $ideas_forum_id;
3539

3640
/**
37-
* Set the controller helper
38-
*
39-
* @param \phpbb\controller\helper $helper
41+
* Set additional services and properties
4042
*
43+
* @param config $config
44+
* @param helper $helper
45+
* @param idea $idea
46+
* @param user_loader $user_loader
4147
* @return void
4248
*/
43-
public function set_controller_helper(\phpbb\controller\helper $helper)
49+
public function set_additional_services(config $config, helper $helper, idea $idea, user_loader $user_loader)
4450
{
4551
$this->helper = $helper;
46-
}
47-
48-
/**
49-
* Set the Idea object
50-
*
51-
* @param \phpbb\ideas\factory\idea $idea
52-
*
53-
* @return void
54-
*/
55-
public function set_idea_factory(\phpbb\ideas\factory\idea $idea)
56-
{
5752
$this->idea = $idea;
58-
}
59-
60-
/**
61-
* Set the config object
62-
*
63-
* @param \phpbb\config\config $config
64-
*
65-
* @return void
66-
*/
67-
public function set_ideas_forum_id(\phpbb\config\config $config)
68-
{
69-
$this->ideas_forum_id = (int) $config['ideas_forum_id'];
70-
}
71-
72-
public function set_user_loader(\phpbb\user_loader $user_loader)
73-
{
7453
$this->user_loader = $user_loader;
75-
}
76-
77-
/**
78-
* Get notification type name
79-
*
80-
* @return string
81-
*/
82-
public function get_type()
83-
{
84-
return 'phpbb.ideas.notification.type.status';
54+
$this->ideas_forum_id = (int) $config['ideas_forum_id'];
8555
}
8656

8757
/**
8858
* Email template to use to send notifications
8959
*
9060
* @var string
9161
*/
92-
public $email_template = '@phpbb_ideas/status_notification';
62+
protected $email_template = '@phpbb_ideas/status_notification';
9363

9464
/**
9565
* Language key used to output the text
@@ -99,59 +69,47 @@ public function get_type()
9969
protected $language_key = 'IDEA_STATUS_CHANGE';
10070

10171
/**
102-
* Notification option data (for outputting to the user)
103-
*
104-
* @var bool|array False if the service should use its default data
105-
* Array of data (including keys 'id', 'lang', and 'group')
72+
* {@inheritDoc}
10673
*/
10774
public static $notification_option = [
10875
'lang' => 'NOTIFICATION_TYPE_IDEAS',
10976
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
11077
];
11178

11279
/**
113-
* Is this type available to the current user (defines whether it will be shown in the UCP Edit notification options)
114-
*
115-
* @return bool True/False whether this is available to the user
80+
* {@inheritDoc}
11681
*/
117-
public function is_available()
82+
public function get_type()
11883
{
119-
return (bool) $this->auth->acl_get('f_read', $this->ideas_forum_id);
84+
return 'phpbb.ideas.notification.type.status';
12085
}
12186

12287
/**
123-
* Get the id of the notification
124-
*
125-
* @param array $type_data The type-specific data
126-
*
127-
* @return int ID of the notification
88+
* {@inheritDoc}
12889
*/
12990
public static function get_item_id($type_data)
13091
{
13192
return (int) $type_data['item_id'];
13293
}
13394

13495
/**
135-
* Get the id of the parent
136-
*
137-
* @param array $type_data The type-specific data
138-
*
139-
* @return int ID of the parent
96+
* {@inheritDoc}
14097
*/
14198
public static function get_item_parent_id($type_data)
14299
{
143100
return 0;
144101
}
145102

146103
/**
147-
* Find the users who want to receive notifications
148-
*
149-
* @param array $type_data The type-specific data
150-
* @param array $options Options for finding users for notification
151-
* ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified
152-
* e.g.: [2 => [''], 3 => ['', 'email'], ...]
153-
*
154-
* @return array
104+
* {@inheritDoc}
105+
*/
106+
public function is_available()
107+
{
108+
return (bool) $this->auth->acl_get('f_read', $this->ideas_forum_id);
109+
}
110+
111+
/**
112+
* {@inheritDoc}
155113
*/
156114
public function find_users_for_notification($type_data, $options = [])
157115
{
@@ -167,27 +125,15 @@ public function find_users_for_notification($type_data, $options = [])
167125
}
168126

169127
/**
170-
* Get the user's avatar
171-
*/
172-
public function get_avatar()
173-
{
174-
return $this->user_loader->get_avatar($this->get_data('idea_author'), false, true);
175-
}
176-
177-
/**
178-
* Users needed to query before this notification can be displayed
179-
*
180-
* @return array Array of user_ids
128+
* {@inheritDoc}
181129
*/
182130
public function users_to_query()
183131
{
184132
return [$this->get_data('idea_author')];
185133
}
186134

187135
/**
188-
* Get the HTML-formatted title of this notification
189-
*
190-
* @return string
136+
* {@inheritDoc}
191137
*/
192138
public function get_title()
193139
{
@@ -199,20 +145,15 @@ public function get_title()
199145
}
200146

201147
/**
202-
* Get the HTML-formatted reference of the notification
203-
*
204-
* @return string
148+
* {@inheritDoc}
205149
*/
206150
public function get_reference()
207151
{
208152
return $this->language->lang(ext::status_name($this->get_data('status')));
209153
}
210154

211155
/**
212-
* Get the url to this item
213-
*
214-
* @param int $reference_type The type of reference to be generated (one of the constants)
215-
* @return string URL
156+
* {@inheritDoc}
216157
*/
217158
public function get_url($reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
218159
{
@@ -222,19 +163,23 @@ public function get_url($reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
222163
}
223164

224165
/**
225-
* Get email template
226-
*
227-
* @return string|bool
166+
* {@inheritDoc}
167+
*/
168+
public function get_avatar()
169+
{
170+
return $this->user_loader->get_avatar($this->get_data('idea_author'), false, true);
171+
}
172+
173+
/**
174+
* {@inheritDoc}
228175
*/
229176
public function get_email_template()
230177
{
231178
return $this->email_template;
232179
}
233180

234181
/**
235-
* Get email template variables
236-
*
237-
* @return array
182+
* {@inheritDoc}
238183
*/
239184
public function get_email_template_variables()
240185
{
@@ -246,15 +191,7 @@ public function get_email_template_variables()
246191
}
247192

248193
/**
249-
* Pre create insert array function
250-
* This allows you to perform certain actions, like run a query
251-
* and load data, before create_insert_array() is run. The data
252-
* returned from this function will be sent to create_insert_array().
253-
*
254-
* @param array $type_data The type-specific data
255-
* @param array $notify_users Notify users list
256-
* Formatted from find_users_for_notification()
257-
* @return array Whatever you want to send to create_insert_array().
194+
* {@inheritDoc}
258195
*/
259196
public function pre_create_insert_array($type_data, $notify_users)
260197
{
@@ -271,11 +208,7 @@ public function pre_create_insert_array($type_data, $notify_users)
271208
}
272209

273210
/**
274-
* Function for preparing the data for insertion in an SQL query
275-
* (The service handles insertion)
276-
*
277-
* @param array $type_data The type-specific data
278-
* @param array $pre_create_data Data from pre_create_insert_array()
211+
* {@inheritDoc}
279212
*/
280213
public function create_insert_array($type_data, $pre_create_data = [])
281214
{

tests/notification/status_test.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ protected function setUp(): void
6363
->willReturn($this->forum_id);
6464

6565
$this->notification_type = new status($db, $this->language, $user, $this->auth, $phpbb_root_path, $phpEx, 'phpbb_user_notifications');
66-
$this->notification_type->set_ideas_forum_id($this->config);
67-
$this->notification_type->set_controller_helper($this->helper);
68-
$this->notification_type->set_idea_factory($this->idea_factory);
69-
$this->notification_type->set_user_loader($this->user_loader);
66+
$this->notification_type->set_additional_services($this->config, $this->helper, $this->idea_factory, $this->user_loader);
7067

7168
// Set protected properties using reflection
7269
$reflection = new \ReflectionClass($this->notification_type);

0 commit comments

Comments
 (0)