friend_request::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 11

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace florinp\messenger\notification\type;
4
5
class friend_request extends \phpbb\notification\type\base
6
{
7
8
  public function get_type()
9
  {
10
	return 'florinp.messenger.notification.type.friend_request';
11
  }
12
13
  public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
14
  {
15
	$this->user_loader = $user_loader;
16
	$this->db = $db;
17
	$this->cache = $cache;
18
	$this->user = $user;
19
	$this->auth = $auth;
20
	$this->config = $config;
21
	$this->phpbb_root_path = $phpbb_root_path;
22
	$this->php_ext = $php_ext;
23
	$this->notification_types_table = $notification_types_table;
24
	$this->notifications_table = $notifications_table;
25
	$this->user_notifications_table = $user_notifications_table;
26
  }
27
28
  public static $notification_option = array(
29
	'group'   => 'NOTIFICATION_GROUP_MISCELLANEOUS',
30
  );
31
32
  public function is_available()
33
  {
34
	return true;
35
  }
36
37
  public static function get_item_id($data)
38
  {
39
	return (int)$data['request_id'];
40
  }
41
42
  public static function get_item_parent_id($data)
43
  {
44
	return 0;
45
  }
46
47
  public function users_to_query()
48
  {
49
	return array();
50
  }
51
52
  public function find_users_for_notification($data, $options = array())
53
  {
54
	$options = array_merge(array(
55
	   'ignore_users'      => array(),
56
	), $options);
57
58
	$users = array($data['user_id']);
59
60
	return $this->check_user_notification_options($users, $options);
61
  }
62
63
  public function get_title()
64
  {
65
	$user_id = $this->user_loader->load_user_by_username($this->get_data('sender_username'));
66
	return $this->user->lang('FRIEND_REQUEST_FROM').$this->user_loader->get_username($user_id, 'no_profile');
67
  }
68
69
  public function get_url()
70
  {
71
	return append_sid($this->phpbb_root_path.'ucp.'.$this->php_ext, "i=-florinp-messenger-ucp-ucp_friends_module&amp;mode=requests");
72
  }
73
74
  public function get_avatar()
75
  {
76
	$user_id = $this->user_loader->load_user_by_username($this->get_data('sender_username'));
77
	return $this->user_loader->get_avatar($user_id);
78
  }
79
80
  public function get_redirect_url()
81
  {
82
	return $this->get_url();
83
  }
84
85
  public function get_email_template()
86
  {
87
	return false;
88
  }
89
90
  public function get_email_template_variables()
91
  {
92
	return array();
93
  }
94
95
  public function create_insert_array($data, $pre_create_data = array())
96
  {
97
	$this->set_data('request_id', $data['request_id']);
98
	$this->set_data('sender_id', $data['sender_id']);
99
	$this->set_data('sender_username', $data['sender_username']);
100
	$this->set_data('user_id', $data['user_id']);
101
102
	return parent::create_insert_array($data, $pre_create_data);
103
  }
104
105
106
}
107