| @@ -12,61 +12,67 @@ | ||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Logs class. |
| 15 | 15 | */ |
| 16 | -class MainWP_Module_Cost_Tracker { | |
| 17 | - /** | |
| 18 | - * Load required files and hooks to make the CLI work. | |
| 19 | - */ | |
| 20 | - public function __construct() { | |
| 21 | - $this->includes(); | |
| 22 | - add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); | |
| 23 | - add_filter( 'mainwp_init_load_all_options', array( $this, 'hook_load_options' ) ); | |
| 24 | - add_action( 'mainwp_system_init', array( $this, 'hook_mainwp_system_init' ) ); | |
| 25 | - } | |
| 16 | +class MainWP_Module_Cost_Tracker { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 17 | + /** | |
| 18 | + * Load required files and hooks to make the CLI work. | |
| 19 | + */ | |
| 20 | + public function __construct() { | |
| 21 | + $this->includes(); | |
| 22 | + add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); | |
| 23 | + add_filter( 'mainwp_init_load_all_options', array( $this, 'hook_load_options' ) ); | |
| 24 | + add_action( 'mainwp_system_init', array( $this, 'hook_mainwp_system_init' ) ); | |
| 25 | + } | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Init method. | |
| 29 | - */ | |
| 30 | - public function plugins_loaded() { | |
| 31 | - if ( class_exists( '\MainWP\Dashboard\Module\CostTracker\Cost_Tracker_DB' ) ) { | |
| 32 | - Cost_Tracker_DB::get_instance()->init(); | |
| 33 | - } | |
| 34 | - } | |
| 27 | + /** | |
| 28 | + * Method get_instance(). | |
| 29 | + */ | |
| 30 | + public static function get_instance() { | |
| 31 | + return new self(); | |
| 32 | + } | |
| 35 | 33 | |
| 36 | - /** | |
| 37 | - * Load files. | |
| 38 | - */ | |
| 39 | - private function includes() { | |
| 40 | - $dir = MAINWP_MODULES_DIR; | |
| 41 | - // need to load log db install. | |
| 42 | - if ( file_exists( $dir . 'cost-tracker/classes/class-cost-tracker-db.php' ) ) { | |
| 43 | - require_once $dir . 'cost-tracker/classes/class-cost-tracker-db.php'; | |
| 44 | - } | |
| 45 | - if ( mainwp_modules_is_enabled( 'cost-tracker' ) ) { | |
| 46 | - if ( file_exists( $dir . 'cost-tracker/classes/class-cost-tracker-manager.php' ) ) { | |
| 47 | - require_once $dir . 'cost-tracker/classes/class-cost-tracker-manager.php'; | |
| 48 | - } | |
| 49 | - } | |
| 50 | - } | |
| 51 | 34 | |
| 52 | - /** | |
| 53 | - * Handle mainwp system init load options. | |
| 54 | - * | |
| 55 | - * @param array $all_opts All loading mainwp options. | |
| 56 | - * @return array $all_opts All loading mainwp options. | |
| 57 | - */ | |
| 58 | - public function hook_load_options( $all_opts ) { | |
| 59 | - return $all_opts; | |
| 60 | - } | |
| 35 | + /** | |
| 36 | + * Init method. | |
| 37 | + */ | |
| 38 | + public function plugins_loaded() { | |
| 39 | + if ( class_exists( '\MainWP\Dashboard\Module\CostTracker\Cost_Tracker_DB' ) ) { | |
| 40 | + Cost_Tracker_DB::get_instance()->init(); | |
| 41 | + } | |
| 42 | + } | |
| 61 | 43 | |
| 62 | - /** | |
| 63 | - * Handle mainwp system init. | |
| 64 | - */ | |
| 65 | - public function hook_mainwp_system_init() { | |
| 66 | - if ( mainwp_modules_is_enabled( 'cost-tracker' ) && class_exists( '\MainWP\Dashboard\Module\CostTracker\Cost_Tracker_Manager' ) ) { | |
| 67 | - Cost_Tracker_Manager::get_instance(); | |
| 68 | - } | |
| 69 | - } | |
| 44 | + /** | |
| 45 | + * Load files. | |
| 46 | + */ | |
| 47 | + private function includes() { | |
| 48 | + $dir = MAINWP_MODULES_DIR; | |
| 49 | + // need to load log db install. | |
| 50 | + if ( file_exists( $dir . 'cost-tracker/classes/class-cost-tracker-db.php' ) ) { | |
| 51 | + require_once $dir . 'cost-tracker/classes/class-cost-tracker-db.php'; // NOSONAR - WP compatible. | |
| 52 | + } | |
| 53 | + if ( mainwp_modules_is_enabled( 'cost-tracker' ) && file_exists( $dir . 'cost-tracker/classes/class-cost-tracker-manager.php' ) ) { | |
| 54 | + require_once $dir . 'cost-tracker/classes/class-cost-tracker-manager.php'; // NOSONAR - WP compatible. | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Handle mainwp system init load options. | |
| 60 | + * | |
| 61 | + * @param array $all_opts All loading mainwp options. | |
| 62 | + * @return array $all_opts All loading mainwp options. | |
| 63 | + */ | |
| 64 | + public function hook_load_options( $all_opts ) { | |
| 65 | + return $all_opts; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Handle mainwp system init. | |
| 70 | + */ | |
| 71 | + public function hook_mainwp_system_init() { | |
| 72 | + if ( mainwp_modules_is_enabled( 'cost-tracker' ) && class_exists( '\MainWP\Dashboard\Module\CostTracker\Cost_Tracker_Manager' ) ) { | |
| 73 | + Cost_Tracker_Manager::get_instance(); | |
| 74 | + } | |
| 75 | + } | |
| 70 | 76 | } |
| 71 | 77 | |
| 72 | -new MainWP_Module_Cost_Tracker(); | |
| 78 | +MainWP_Module_Cost_Tracker::get_instance(); | |