UserNotificationIntegrate   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 17.39%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 8
ccs 4
cts 23
cp 0.1739

5 Methods

Rating   Name   Duplication   Size   Complexity  
A integrate_load_theme() 0 9 2
A register() 0 12 3
A integrate_modify_mention_settings() 0 6 1
A settingsRegister() 0 6 1
A integrate_save_modify_mention_settings() 0 6 1
1
<?php
2
3
/**
4
 * Integration hooks for user notifications.  Hooks are Dynamically registered.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * @version 2.0 dev
11
 *
12
 */
13
14
namespace ElkArte;
15
16
use ElkArte\Helper\HttpReq;
17
use ElkArte\Notifications\UserNotification;
18
19
/**
20
 * Class UserNotificationIntegrate
21
 *
22
 * @package ElkArte
23
 */
24
class UserNotificationIntegrate
25
{
26 1
	/**
27
	 * Dynamically registers the hooks for the feature.
28 1
	 */
29
	public static function register()
30 1
	{
31
		global $modSettings;
32 1
33
		if (empty($modSettings['usernotif_favicon_enable']) && empty($modSettings['usernotif_desktop_enable']))
34
		{
35
			return [];
36
		}
37
38
		// $hook, $function, $file
39
		return [
40
			['integrate_load_theme', '\\ElkArte\\UserNotificationIntegrate::integrate_load_theme'],];
41
	}
42
43
	/**
44
	 * Dynamically registers the admin panel hooks for the feature.
45
	 */
46
	public static function settingsRegister()
47
	{
48
		// $hook, $function, $file
49
		return [
50
			['integrate_modify_mention_settings', '\\ElkArte\\UserNotificationIntegrate::integrate_modify_mention_settings'],
51
			['integrate_save_modify_mention_settings', '\\ElkArte\\UserNotificationIntegrate::integrate_save_modify_mention_settings'],
52
		];
53
	}
54
55
	/**
56
	 * Adds the relevant javascript code when loading the page.
57
	 */
58
	public static function integrate_load_theme()
59
	{
60
		if (User::$info->is_guest)
0 ignored issues
show
Bug Best Practice introduced by
The property is_guest does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
		{
62
			return;
63
		}
64
65
		$notification = new UserNotification(database(), User::$info);
66
		$notification->present();
67
	}
68
69
	/**
70
	 * Adds the settings to the admin page.
71
	 *
72
	 * @param array $config_vars
73
	 */
74
	public static function integrate_modify_mention_settings(&$config_vars)
75
	{
76
		$notification = new UserNotification(database(), User::$info);
77
78
		$notification_cfg = $notification->addConfig();
79
		$config_vars = elk_array_insert($config_vars, $config_vars[1], $notification_cfg, 'after', false);
80
	}
81
82
	/**
83
	 * Does some magic when settings are saved.
84
	 */
85
	public static function integrate_save_modify_mention_settings()
86
	{
87
		$req = HttpReq::instance();
88
89
		$notification = new UserNotification(database(), User::$info);
90
		$req->post = $notification->validate($req->post);
0 ignored issues
show
Documentation Bug introduced by
It seems like $notification->validate($req->post) can also be of type array. However, the property $post is declared as type object. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
91
	}
92
}
93