Completed
Push — issues/611 ( e1f393...0587e7 )
by Ravinder
21:03
created

is_email_notification_active()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Email Notification Util
4
 *
5
 * This class contains helper functions for  email notification.
6
 *
7
 * @package     Give
8
 * @subpackage  Classes/Emails
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       2.0
12
 */
13
14
// Exit if access directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
20
class Give_Email_Notification_Util {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
21
	/**
22
	 * Instance.
23
	 *
24
	 * @since  1.0
25
	 * @access static
26
	 * @var
27
	 */
28
	static private $instance;
29
30
	/**
31
	 * Singleton pattern.
32
	 *
33
	 * @since  1.0
34
	 * @access private
35
	 * Give_Email_Notification_Util constructor.
36
	 */
37
	private function __construct() {
38
	}
39
40
41
	/**
42
	 * Get instance.
43
	 *
44
	 * @since  1.0
45
	 * @access static
46
	 * @return static
47
	 */
48
	static function get_instance() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
		if ( null === static::$instance ) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
50
			self::$instance = new static();
51
		}
52
53
		return self::$instance;
54
	}
55
56
57
	/**
58
	 * Check if notification has preview field or not.
59
	 *
60
	 * @since  2.0
61
	 * @access public
62
	 *
63
	 * @param Give_Email_Notification $email
64
	 *
65
	 * @return bool
66
	 */
67
	public static function has_preview( Give_Email_Notification $email ) {
68
		return $email->has_preview;
69
	}
70
71
	/**
72
	 * Check if notification has recipient field or not.
73
	 *
74
	 * @since  2.0
75
	 * @access public
76
	 *
77
	 * @param Give_Email_Notification $email
78
	 *
79
	 * @return bool
80
	 */
81
	public static function has_recipient_field( Give_Email_Notification $email ) {
82
		return $email->has_recipient_field;
83
	}
84
85
	/**
86
	 * Check if admin can edit notification status or not.
87
	 *
88
	 * @since  2.0
89
	 * @access public
90
	 *
91
	 * @param Give_Email_Notification $email
92
	 *
93
	 * @return bool
94
	 */
95
	public static function is_notification_status_editable( Give_Email_Notification $email ) {
96
		return $email->is_notification_status_editable;
97
	}
98
99
	/**
100
	 * Check email preview header active or not.
101
	 *
102
	 * @since  2.0
103
	 * @access public
104
	 *
105
	 * @param Give_Email_Notification $email
106
	 *
107
	 * @return bool
108
	 */
109
	public static function is_email_preview_has_header( Give_Email_Notification $email ) {
110
		return $email->has_preview_header;
111
	}
112
113
	/**
114
	 * Check email preview header active or not.
115
	 *
116
	 * @since  2.0
117
	 * @access public
118
	 *
119
	 * @param Give_Email_Notification $email
120
	 *
121
	 * @return bool
122
	 */
123
	public static function is_email_preview( Give_Email_Notification $email ) {
124
		return $email->has_preview;
125
	}
126
127
128
	/**
129
	 * Check email active or not.
130
	 *
131
	 * @since  2.0
132
	 * @access public
133
	 *
134
	 * @param Give_Email_Notification $email
135
	 *
136
	 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

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...
137
	 */
138
	public static function is_email_notification_active( Give_Email_Notification $email ) {
139
		return give_is_setting_enabled( $email->get_notification_status() );
140
	}
141
}
142