Skip to content

Commit

Permalink
add type hints to PHP methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Mar 24, 2024
1 parent 24e4580 commit 5e05422
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 70 deletions.
6 changes: 3 additions & 3 deletions inc/class-statify-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Statify_Api extends Statify {
*
* @return void
*/
public static function init() {
public static function init(): void {
if ( Statify::is_javascript_tracking_enabled() ) {
register_rest_route(
self::REST_NAMESPACE,
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function check_authentication( $errors ) {
*
* @return WP_REST_Response The response.
*/
public static function track_visit( $request ) {
public static function track_visit( WP_REST_Request $request ): WP_REST_Response {
// Only do something if snippet use is actually configured.
if ( Statify::is_javascript_tracking_enabled() ) {
// Nonce verification, if necessary. We do not rely on the WP REST default mechanisms.
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function track_visit( $request ) {
*
* @return WP_REST_Response The response.
*/
public static function get_stats( $request ) {
public static function get_stats( WP_REST_Request $request ): WP_REST_Response {
$refresh = '1' === $request->get_param( 'refresh' );

$stats = Statify_Dashboard::get_stats( $refresh );
Expand Down
4 changes: 2 additions & 2 deletions inc/class-statify-backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Statify_Backend {
*
* @return array Merged links
*/
public static function add_meta_link( $input, $file ) {
public static function add_meta_link( array $input, string $file ): array {

// Other plugins?
if ( STATIFY_BASE !== $file ) {
Expand All @@ -55,7 +55,7 @@ public static function add_meta_link( $input, $file ) {
*
* @return array Merged links
*/
public static function add_action_link( $input ) {
public static function add_action_link( array $input ): array {

// Rights?
if ( ! current_user_can( 'manage_options' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/class-statify-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Statify_Cron extends Statify {
* @since 0.3.0
* @version 1.4.0
*/
public static function cleanup_data() {
public static function cleanup_data(): void {

// Global.
global $wpdb;
Expand Down
18 changes: 9 additions & 9 deletions inc/class-statify-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Statify_Dashboard extends Statify {
*
* @since 0.1.0
*/
public static function init() {
public static function init(): void {

// Filter user_can_see_stats.
if ( ! self::user_can_see_stats() ) {
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function init() {
* @since 0.1.0
* @version 1.4.0
*/
public static function add_style() {
public static function add_style(): void {

// Register CSS.
wp_register_style(
Expand Down Expand Up @@ -106,7 +106,7 @@ public static function add_style() {
* @since 0.1.0
* @version 1.4.0
*/
public static function add_js() {
public static function add_js(): void {

// Register JS.
wp_register_script(
Expand Down Expand Up @@ -155,7 +155,7 @@ public static function add_js() {
* @since 0.1.0
* @version 1.4.0
*/
public static function print_frontview() {
public static function print_frontview(): void {

// Load JS.
wp_enqueue_script( 'chartist_js' );
Expand All @@ -174,7 +174,7 @@ public static function print_frontview() {
* @since 0.4.0
* @version 1.4.0
*/
public static function print_backview() {
public static function print_backview(): void {

// Capability check.
if ( ! current_user_can( 'edit_dashboard' ) ) {
Expand Down Expand Up @@ -203,7 +203,7 @@ public static function print_backview() {
*
* @return void
*/
private static function _save_widget_options() {
private static function _save_widget_options(): void {
// Check the nonce field from the dashboard form.
if ( ! check_admin_referer( 'statify-dashboard' ) ) {
return;
Expand Down Expand Up @@ -248,7 +248,7 @@ private static function _save_widget_options() {
* @since 1.4.0
* @version 1.4.0
*/
private static function _get_version() {
private static function _get_version(): void {

// Get plugin meta.
$meta = get_plugin_data( STATIFY_FILE );
Expand All @@ -267,7 +267,7 @@ private static function _get_version() {
*
* @return array $data stats data from cache or database
*/
public static function get_stats( $force_refresh = false ) {
public static function get_stats( bool $force_refresh = false ): array {

// Get from cache if enabled.
if ( ! $force_refresh ) {
Expand Down Expand Up @@ -304,7 +304,7 @@ public static function get_stats( $force_refresh = false ) {
*
* @return array DB results
*/
private static function _select_data() {
private static function _select_data(): array {

// Global.
global $wpdb;
Expand Down
2 changes: 1 addition & 1 deletion inc/class-statify-deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Statify_Deactivate {
* @since 1.4.0
* @version 1.4.0
*/
public static function init() {
public static function init(): void {

// Delete transients.
delete_transient( 'statify_data' );
Expand Down
20 changes: 6 additions & 14 deletions inc/class-statify-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Statify_Frontend extends Statify {
*
* @return void
*/
public static function track_visit() {
public static function track_visit(): void {
if ( self::is_javascript_tracking_enabled() ) {
return;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ public static function track_visit() {
*
* @return array $vars Output with plugin variables
*/
public static function query_vars( $vars ) {
public static function query_vars( array $vars ): array {
$vars[] = 'statify_referrer';
$vars[] = 'statify_target';

Expand All @@ -69,7 +69,7 @@ public static function query_vars( $vars ) {
* @since 1.1.0
* @version 1.4.1
*/
public static function wp_footer() {
public static function wp_footer(): void {
// JS tracking disabled or AMP is used for the current request.
if (
! self::is_javascript_tracking_enabled() ||
Expand Down Expand Up @@ -109,11 +109,7 @@ public static function wp_footer() {
*
* @param array $analytics_entries Analytics entries.
*/
public static function amp_analytics_entries( $analytics_entries ) {
if ( ! is_array( $analytics_entries ) ) {
$analytics_entries = array();
}

public static function amp_analytics_entries( array $analytics_entries ): array {
// Analytics script is only relevant, if "JS" tracking is enabled, to prevent double tracking.
if ( self::is_javascript_tracking_enabled() ) {
$analytics_entries['statify'] = array(
Expand All @@ -132,11 +128,7 @@ public static function amp_analytics_entries( $analytics_entries ) {
*
* @param array $analytics Analytics.
*/
public static function amp_post_template_analytics( $analytics ) {
if ( ! is_array( $analytics ) ) {
$analytics = array();
}

public static function amp_post_template_analytics( array $analytics ): array {
// Analytics script is only relevant, if "JS" tracking is enabled, to prevent double tracking.
if ( self::is_javascript_tracking_enabled() ) {
$analytics['statify'] = array(
Expand All @@ -154,7 +146,7 @@ public static function amp_post_template_analytics( $analytics ) {
*
* @return array Configuration array.
*/
private static function make_amp_config() {
private static function make_amp_config(): array {
$cfg = array(
'requests' => array(
'pageview' => rest_url( Statify_Api::REST_NAMESPACE . '/' . Statify_Api::REST_ROUTE_TRACK ),
Expand Down
8 changes: 4 additions & 4 deletions inc/class-statify-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Statify_Install {
*
* @param bool $network_wide Whether the plugin was activated network-wide or not.
*/
public static function init( $network_wide = false ) {
public static function init( bool $network_wide = false ): void {

if ( $network_wide && is_multisite() ) {
$sites = get_sites();
Expand All @@ -53,9 +53,9 @@ public static function init( $network_wide = false ) {
*
* @param int $site_id Site ID.
*/
public static function init_site( $site_id ) {
public static function init_site( int $site_id ): void {

switch_to_blog( (int) $site_id );
switch_to_blog( $site_id );

self::_apply();

Expand All @@ -68,7 +68,7 @@ public static function init_site( $site_id ) {
* @since 0.1.0
* @version 1.4.0
*/
private static function _apply() {
private static function _apply(): void {

// Cleanup any leftover transients.
delete_transient( 'statify_data' );
Expand Down
Loading

0 comments on commit 5e05422

Please sign in to comment.