Skip to content

Commit

Permalink
fix: code refactoring and namespace/use statements. (#11)
Browse files Browse the repository at this point in the history
* fix: added namespace and use statements

* fix: plugin-admin code decoupled

* fix: code-sniffer errors correction
  • Loading branch information
julianramirez2 authored Jun 28, 2023
1 parent 6bd562c commit 7e280e4
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 40 deletions.
90 changes: 65 additions & 25 deletions admin/Openedx_Woocommerce_Plugin_Admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

namespace App\admin;
use App\model\Openedx_Woocommerce_Plugin_Enrollment;
use App\model\Openedx_Woocommerce_Plugin_Post_Type;
use App\admin\views\Openedx_Woocommerce_Plugin_Enrollment_Info_Form;

/**
* The admin-specific functionality of the plugin.
*
Expand Down Expand Up @@ -53,13 +58,27 @@ class Openedx_Woocommerce_Plugin_Admin {
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
* @param string $test Flag variable to know if it is a test.
*/
public function __construct( $plugin_name, $version ) {
public function __construct( $plugin_name, $version, $test = null) {

$this->plugin_name = $plugin_name;
$this->version = $version;
if(!$test){
$this->createEnrollmentClass();
}

}

/**
* Create an instance of the Openedx_Woocommerce_Plugin_Enrollment class.
*
* @since 1.0.0
*/
public function createEnrollmentClass() {

$this->openedx_enrollment = new Openedx_Woocommerce_Plugin_Enrollment( $this );

}
Expand Down Expand Up @@ -87,44 +106,49 @@ public function enqueue_styles() {

}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {

/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Openedx_Woocommerce_Plugin_Loader as all of the hooks are defined
* in that particular class.
*
* The Openedx_Woocommerce_Plugin_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Openedx_Woocommerce_Plugin_Loader as all of the hooks are defined
* in that particular class.
*
* The Openedx_Woocommerce_Plugin_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/

//wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/openedx-woocommerce-plugin-admin.js', array( 'jquery' ), $this->version, false );

//wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/openedx-woocommerce-plugin-admin.js', array( 'jquery' ), $this->version, false );
}

/**
* Register Enrollment Request custom post type
*
* @since 1.0.0
*/
public function register_enrollment_custom_post_type(){
public function register_enrollment_custom_post_type() {

$this->openedx_enrollment->register_enrollment_custom_post_type();

}

/**
* Render Enrollment Request info form
*
* @since 1.0.0
*/
public function render_enrollment_info_form(){
public function render_enrollment_info_form() {

$this->openedx_enrollment_info_form = new Openedx_Woocommerce_Plugin_Enrollment_Info_Form($this->openedx_enrollment);

}

/**
Expand All @@ -136,16 +160,32 @@ public function render_enrollment_info_form(){
* @param string $description Description of post type.
* @return object Post type class object
*/

public function register_post_type( $post_type = '', $plural = '', $single = '', $description = '', $options = array() ) {

if ( ! $post_type || ! $plural || ! $single ) {
return;
}

$post_type = new Openedx_Woocommerce_Plugin_Post_Type( $post_type, $plural, $single, $description, $options );

$post_type = $this->createPostType( $post_type, $plural, $single, $description, $options );
return $post_type;

}

/**
* Create a new instance of the Openedx_Woocommerce_Plugin_Post_Type class and register a new post type.
*
* @param string $post_type Post type name.
* @param string $plural Post type item plural name.
* @param string $single Post type item single name.
* @param string $description Description of the post type.
* @param array $options Additional options for the post type.
* @return object Post type class object.
*/
public function createPostType($post_type = '', $plural = '', $single = '', $description = '', $options = array()) {

return new Openedx_Woocommerce_Plugin_Post_Type( $post_type, $plural, $single, $description, $options );

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App\admin\views;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
},
"autoload": {
"psr-4": {
"App\\": ""
"App\\": "includes/",
"App\\model\\": "includes/model/",
"App\\admin\\": "admin/",
"App\\admin\\views\\": "admin/views/",
"App\\public\\": "public/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "test/"
}
}
}
}
20 changes: 12 additions & 8 deletions includes/Openedx_Woocommerce_Plugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace App;
use App\admin\Openedx_Woocommerce_Plugin_Admin;
use App\public\Openedx_Woocommerce_Plugin_Public;

/**
* The file that defines the core plugin class
*
Expand Down Expand Up @@ -103,42 +107,42 @@ private function load_dependencies() {
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/Openedx_Woocommerce_Plugin_Loader.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'includes/Openedx_Woocommerce_Plugin_Loader.php';

/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/Openedx_Woocommerce_Plugin_i18n.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'includes/Openedx_Woocommerce_Plugin_i18n.php';

/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/Openedx_Woocommerce_Plugin_Admin.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'admin/Openedx_Woocommerce_Plugin_Admin.php';

/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/Openedx_Woocommerce_Plugin_Public.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'public/Openedx_Woocommerce_Plugin_Public.php';

$this->loader = new Openedx_Woocommerce_Plugin_Loader();

/**
* The class responsible for defining the enrollment object
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/model/Openedx_Woocommerce_Plugin_Enrollment.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'includes/model/Openedx_Woocommerce_Plugin_Enrollment.php';

/**
* The class responsible for defining the custom-post-type object
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/model/Openedx_Woocommerce_Plugin_Post_Type.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'includes/model/Openedx_Woocommerce_Plugin_Post_Type.php';

/**
* The class responsible for rendering the enrollment info form
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php';
include_once plugin_dir_path( dirname( __FILE__ )) . 'admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php';
}

/**
Expand Down
2 changes: 2 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_Activator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App;

/**
* Fired during plugin activation
*
Expand Down
2 changes: 2 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_Deactivator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App;

/**
* Fired during plugin deactivation
*
Expand Down
2 changes: 2 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_Loader.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App;

/**
* Register all actions and filters for the plugin
*
Expand Down
2 changes: 2 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_i18n.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App;

/**
* Define the internationalization functionality
*
Expand Down
2 changes: 2 additions & 0 deletions includes/model/Openedx_Woocommerce_Plugin_Enrollment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App\model;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down
2 changes: 2 additions & 0 deletions includes/model/Openedx_Woocommerce_Plugin_Post_Type.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App\model;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down
14 changes: 9 additions & 5 deletions openedx-woocommerce-plugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use App\Openedx_Woocommerce_Plugin_Activator;
use App\Openedx_Woocommerce_Plugin_Deactivator;
use App\Openedx_Woocommerce_Plugin;

/**
* The plugin bootstrap file
*
Expand Down Expand Up @@ -42,17 +46,17 @@
* This action is documented in includes/class-openedx-woocommerce-plugin-activator.php
*/
function activate_openedx_woocommerce_plugin() {
require_once plugin_dir_path( __FILE__ ) . 'includes/Openedx_Woocommerce_Plugin_Activator.php';
Openedx_Woocommerce_Plugin_Activator::activate();
include_once plugin_dir_path( __FILE__ ) . 'includes/Openedx_Woocommerce_Plugin_Activator.php';
Openedx_Woocommerce_Plugin_Activator::activate();
}

/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-openedx-woocommerce-plugin-deactivator.php
*/
function deactivate_openedx_woocommerce_plugin() {
require_once plugin_dir_path( __FILE__ ) . 'includes/Openedx_Woocommerce_Plugin_Deactivator.php';
Openedx_Woocommerce_Plugin_Deactivator::deactivate();
include_once plugin_dir_path( __FILE__) . 'includes/Openedx_Woocommerce_Plugin_Deactivator.php';
Openedx_Woocommerce_Plugin_Deactivator::deactivate();
}

register_activation_hook( __FILE__, 'activate_openedx_woocommerce_plugin' );
Expand All @@ -62,7 +66,7 @@ function deactivate_openedx_woocommerce_plugin() {
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/Openedx_Woocommerce_Plugin.php';
require plugin_dir_path( __FILE__) . 'includes/Openedx_Woocommerce_Plugin.php';

/**
* Begins execution of the plugin.
Expand Down
2 changes: 2 additions & 0 deletions public/Openedx_Woocommerce_Plugin_Public.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace App\public;

/**
* The public-facing functionality of the plugin.
*
Expand Down

0 comments on commit 7e280e4

Please sign in to comment.