BD_Addon::setup_license_handler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base class for all BD Addons.
4
 *
5
 * @since   5.5
6
 * @deprecated 6.0.0 Use \BulkWP\BulkDelete\Core\Addon\BaseAddon instead.
7
 *
8
 * @author  Sudar
9
 *
10
 * @package BulkDelete\Addons\Base
11
 */
12
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
13
14
/**
15
 * Base class for BD Addons.
16
 *
17
 * @abstract
18
 *
19
 * @since 5.5
20
 */
21
abstract class BD_Addon {
22
	/**
23
	 * @var string Addon Name.
24
	 */
25
	protected $addon_name;
26
27
	/**
28
	 * @var string Addon Code.
29
	 */
30
	protected $addon_code;
31
32
	/**
33
	 * @var string Addon File.
34
	 */
35
	protected $addon_file;
36
37
	/**
38
	 * @var string Addon Version.
39
	 */
40
	protected $addon_version;
41
42
	/**
43
	 * @var string Addon Author.
44
	 */
45
	protected $addon_author = 'Sudar Muthu';
46
47
	/**
48
	 * @var Module Name.
0 ignored issues
show
Bug introduced by
The type Module was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
	 */
50
	protected $module;
51
52
	/**
53
	 * @var object License Handler.
54
	 */
55
	protected $license_handler;
56
57
	/**
58
	 * Initialize and setup variables.
59
	 *
60
	 * @since 5.5
61
	 * @abstract
62
	 *
63
	 * @return void
64
	 */
65
	abstract protected function initialize();
66
67
	/**
68
	 * Use `factory()` method to create instance of this class.
69
	 * Don't create instances directly.
70
	 *
71
	 * @since 5.5
72
	 * @see factory()
73
	 */
74
	public function __construct() {
75
		$this->setup();
76
	}
77
78
	/**
79
	 * Setup the module.
80
	 *
81
	 * @access protected
82
	 *
83
	 * @since 5.5
84
	 */
85
	protected function setup() {
86
		$this->initialize();
87
		$this->setup_translation();
88
		if ( $this->dependencies_met() ) {
89
			$this->setup_hooks();
0 ignored issues
show
Bug introduced by
The method setup_hooks() does not exist on BD_Addon. Did you maybe mean setup()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
			$this->/** @scrutinizer ignore-call */ 
90
          setup_hooks();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
		}
91
	}
92
93
	/**
94
	 * Check if all dependencies are met.
95
	 * To check for dependencies overload this method in the child class.
96
	 *
97
	 * @return bool True if dependencies met, False otherwise.
98
	 */
99
	protected function dependencies_met() {
100
		return true;
101
	}
102
103
	/**
104
	 * Setup translation.
105
	 *
106
	 * @access protected
107
	 *
108
	 * @since 5.5
109
	 */
110
	protected function setup_translation() {
111
		$bd = BULK_DELETE();
112
113
		// Load translation files from Bulk Delete language folder
114
		load_plugin_textdomain( 'bulk-delete', false, $bd->translations );
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $deprecated of load_plugin_textdomain(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
		load_plugin_textdomain( 'bulk-delete', /** @scrutinizer ignore-type */ false, $bd->translations );
Loading history...
115
	}
116
117
	/**
118
	 * Setup license handler.
119
	 *
120
	 * @since 5.5
121
	 *
122
	 * @param string $plugin_file Addon file name relative to plugin directory.
123
	 */
124
	public function setup_license_handler( $plugin_file ) {
125
		$this->addon_file      = $plugin_file;
126
		$this->license_handler = new BD_License_Handler(
127
			$this->addon_name,
128
			$this->addon_code,
129
			$this->addon_version,
130
			$this->addon_file,
131
			$this->addon_author
132
		);
133
	}
134
135
	/**
136
	 * Get addon class name.
137
	 *
138
	 * @since 5.5
139
	 *
140
	 * @return string Addon class name
141
	 */
142
	protected function get_addon_class_name() {
143
		return bd_get_addon_class_name( $this->addon_name );
144
	}
145
}
146