Skip to content

Commit

Permalink
move classes to Statify namespace and configure PSR-4 autoloader
Browse files Browse the repository at this point in the history
Remove the "Statify_" prefix from classnames, so Statify_Frontend is now
located at Statify\Frontend.
Disable the corresponding PHPCS rule as it conflicts with PSR-4 standard.
Remove the custom autoloader function.
  • Loading branch information
stklcode committed Mar 31, 2023
1 parent c49ff94 commit 7d6a6d1
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 167 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"vendor/npm-asset/chartist-plugin-tooltips-updated/dist/chartist-plugin-tooltip.min.js": "js/"
}
},
"autoload": {
"psr-4": {
"Statify\\": "inc/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
Expand Down
13 changes: 9 additions & 4 deletions inc/class-statify-api.php → inc/Api.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<?php
/**
* Statify: Statify_API class
* Statify: API class
*
* This file contains methods for REST API integration.
*
* @package Statify
* @since 1.9
*/

namespace Statify;

use WP_REST_Response;
use WP_REST_Server;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify REST API integration.
*
* @since 1.9
* @since 2.0.0
*/
class Statify_Api extends Statify {
class Api extends Statify {
/**
* REST endpoints
*
Expand Down Expand Up @@ -122,7 +127,7 @@ public static function track_visit( $request ) {
public static function get_stats( $request ) {
$refresh = '1' === $request->get_param( 'refresh' );

$stats = Statify_Dashboard::get_stats( $refresh );
$stats = Dashboard::get_stats( $refresh );

$visits = $stats['visits'];
$stats['visits'] = array();
Expand Down
9 changes: 6 additions & 3 deletions inc/class-statify-backend.php → inc/Backend.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Backend class
* Statify: Backend class
*
* This file contains the derived class for the plugin's backend features.
*
* @package Statify
* @since 1.4.0
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Backend
* Statify Backend
*
* @since 1.4.0
* @since 2.0.0 renamed to Statify\Backend
*/
class Statify_Backend {
class Backend {

/**
* Add plugin meta links
Expand Down
9 changes: 6 additions & 3 deletions inc/class-statify-cron.php → inc/Cron.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Cron class
* Statify: Cron class
*
* This file contains the derived class for the plugin's cron features.
*
* @package Statify
* @since 1.4.0
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Cron
* Statify Cron
*
* @since 1.4.0
* @since 2.0.0 renamed to Statify\Cron
*/
class Statify_Cron extends Statify {
class Cron extends Statify {

/**
* Cleanup obsolete DB values
Expand Down
9 changes: 6 additions & 3 deletions inc/class-statify-dashboard.php → inc/Dashboard.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Dashboard class
* Statify: Dashboard class
*
* This file contains the derived class for the plugin's dashboard features.
*
* @package Statify
* @since 1.1
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Dashboard
* Statify Dashboard
*
* @since 1.1
* @since 2.0.0 renamed to Statify\Dashboard
*/
class Statify_Dashboard extends Statify {
class Dashboard extends Statify {

/**
* Plugin version.
Expand Down
9 changes: 6 additions & 3 deletions inc/class-statify-deactivate.php → inc/Deactivate.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Deactivate class
* Statify: Deactivate class
*
* This file contains the derived class for the plugin's deactivation actions.
*
* @package Statify
* @since 1.4.0
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Deactivate
* Statify Deactivate
*
* @since 1.4.0
* @since 2.0.0 renamed to Statify\Deactivate
*/
class Statify_Deactivate {
class Deactivate {

/**
* Plugin deactivation actions
Expand Down
13 changes: 8 additions & 5 deletions inc/class-statify-frontend.php → inc/Frontend.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Frontend class
* Statify: Frontend class
*
* This file contains the derived class for the plugin's frontend features.
*
* @package Statify
* @since 1.4.0
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Frontend
* Statify Frontend
*
* @since 1.4.0
* @since 2.0.0 renamed to Statify\Frontend
*/
class Statify_Frontend extends Statify {
class Frontend extends Statify {

/**
* Track the page view
Expand Down Expand Up @@ -96,7 +99,7 @@ public static function wp_footer() {

// Add endpoint to script.
$script_data = array(
'url' => esc_url_raw( rest_url( Statify_Api::REST_NAMESPACE . '/' . Statify_Api::REST_ROUTE_TRACK ) ),
'url' => esc_url_raw( rest_url( Api::REST_NAMESPACE . '/' . Api::REST_ROUTE_TRACK ) ),
);
if ( Statify::TRACKING_METHOD_JAVASCRIPT_WITH_NONCE_CHECK === self::$_options['snippet'] ) {
$script_data['nonce'] = wp_create_nonce( 'statify_track' );
Expand Down Expand Up @@ -159,7 +162,7 @@ public static function amp_post_template_analytics( $analytics ) {
private static function make_amp_config() {
$cfg = array(
'requests' => array(
'pageview' => rest_url( Statify_Api::REST_NAMESPACE . '/' . Statify_Api::REST_ROUTE_TRACK ),
'pageview' => rest_url( Api::REST_NAMESPACE . '/' . Api::REST_ROUTE_TRACK ),
),
'extraUrlParams' => array(
'referrer' => '${documentReferrer}',
Expand Down
16 changes: 9 additions & 7 deletions inc/class-statify-install.php → inc/Install.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?php
/**
* Statify: Statify_Install class
* Statify: Install class
*
* This file contains the derived class for the plugin's installation features.
*
* @package Statify
* @since 0.1
*/

namespace Statify;

// Quit if accessed outside WP context.
defined( 'ABSPATH' ) || exit;

/**
* Statify_Install
* Statify Install
*
* @since 0.1
* @version 2016-12-20
* @since 0.1
* @since 2.0.0 renamed to Statify\Install
*/
class Statify_Install {
class Install {

/**
* Plugin activation handler.
Expand Down Expand Up @@ -83,7 +85,7 @@ private static function _apply() {
}

// Create the actual tables.
Statify_Table::init();
Statify_Table::create();
Table::init();
Table::create();
}
}
9 changes: 6 additions & 3 deletions inc/class-statify-settings.php → inc/Settings.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
/**
* Statify: Statify_Settings class
* Statify: Settings class
*
* This file contains the plugin's settings capabilities.
*
* @package Statify
* @since 1.7
*/

namespace Statify;

// Quit if accessed directly..
defined( 'ABSPATH' ) || exit;

/**
* Class Statify_Settings
* Statify Settings
*
* @since 1.7
* @since 2.0.0 renamed to Statify\Settings
*/
class Statify_Settings {
class Settings {

/**
* Registers all options using the WP Settings API.
Expand Down
Loading

0 comments on commit 7d6a6d1

Please sign in to comment.