Skip to content

Commit c34a3c2

Browse files
authored
Merge pull request #17 from BeAPI/feature/coding-standards
various fix and optimisations vs coding standards
2 parents 1800cc2 + d8f0dad commit c34a3c2

File tree

19 files changed

+139
-698
lines changed

19 files changed

+139
-698
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ The autoload is based on psr-4 and handled by composer.
3636

3737
## Changelog ##
3838

39+
### 3.1.1
40+
* Fev 2021
41+
* Rename hook : `BEA/Helpers/locate_template/templates` in `beapi_helpers_locate_template_templates` for PHPCS
42+
* Improve PHPCS
43+
3944
### 3.1.0
4045
* Jan 2021
4146
* Update Singleton to be compatible with PHP8.0
42-
*
4347

4448
### 3.0.0
4549
* May 2020

bea-plugin-boilerplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
Plugin Name: BEA Plugin Name
44
Version: 1.0.0
5-
Version Boilerplate: 3.1.0
5+
Version Boilerplate: 3.1.1
66
Plugin URI: https://beapi.fr
77
Description: Your plugin description
88
Author: Be API Technical team

classes/Admin/Main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BEA\PB\Admin;
34

45
use BEA\PB\Singleton;

classes/Compatibility.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ public static function admin_init() {
2222
// Load the textdomain
2323
load_plugin_textdomain( 'bea-plugin-boilerplate', false, BEA_PB_PLUGIN_DIRNAME . '/languages' );
2424

25+
//phpcs:ignore
2526
trigger_error( sprintf( __( 'Plugin Boilerplate requires PHP version %s or greater to be activated.', 'bea-plugin-boilerplate' ), BEA_PB_MIN_PHP_VERSION ) );
2627

2728
// Deactive self
2829
deactivate_plugins( BEA_PB_DIR . 'bea-plugin-boilerplate.php' );
2930

31+
//phpcs:ignore
3032
unset( $_GET['activate'] );
3133

3234
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
@@ -37,7 +39,8 @@ public static function admin_init() {
3739
*/
3840
public static function admin_notices() {
3941
echo '<div class="notice error is-dismissible">';
40-
echo '<p>' . esc_html( sprintf( __( 'Plugin Boilerplate require PHP version %s or greater to be activated. Your server is currently running PHP version %s.', 'bea-plugin-boilerplate' ), BEA_PB_MIN_PHP_VERSION, PHP_VERSION ) ) . '</p>';
42+
/* translators: %1$s: PHP min version %2$s: Current PHP version */
43+
echo '<p>' . esc_html( sprintf( __( 'Plugin Boilerplate require PHP version %1$s or greater to be activated. Your server is currently running PHP version %2$s.', 'bea-plugin-boilerplate' ), BEA_PB_MIN_PHP_VERSION, PHP_VERSION ) ) . '</p>';
4144
echo '</div>';
4245
}
4346
}

classes/Controllers/Controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BEA\PB\Controllers;
34

45
use BEA\PB\Routes\Router;

classes/Cron/Cron.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2-
use \Bea_Log;
32

43
namespace BEA\PB;
54

5+
use \Bea_Log;
6+
67
/**
78
* This class needs Bea_Log to work
89
* This class purpose is to handle cron process by :
@@ -94,8 +95,8 @@ private function get_lock_file_path() {
9495
* @author Nicolas Juen
9596
*/
9697
private static function get_filesystem() {
97-
require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php' );
98-
require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php' );
98+
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
99+
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
99100
$filesystem = new \WP_Filesystem_Direct( new \StdClass() );
100101

101102
return $filesystem;
@@ -139,6 +140,7 @@ protected function add_log( $message, $type = \Bea_Log::gravity_7 ) {
139140
}
140141
$this->log->log_this( $message, $type );
141142

142-
echo date( '[d-m-Y H:i:s]' ) . $message . "\n";
143+
//phpcs:ignore
144+
printf( '%s %s \n', date( '[d-m-Y H:i:s]' ), esc_html( $message ) );
143145
}
144146
}

classes/Helpers.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
namespace BEA\PB;
4+
35
/**
46
* The purpose of the API class is to have the basic reusable methods like :
57
* - Template include
@@ -33,7 +35,7 @@ public static function locate_template( $tpl ) {
3335
return false;
3436
}
3537

36-
$path = apply_filters( 'BEA/Helpers/locate_template/templates', array( 'views/' . BEA_PB_VIEWS_FOLDER_NAME . '/' . $tpl . '.php' ), $tpl, __NAMESPACE__ );
38+
$path = apply_filters( 'beapi_helpers_locate_template_templates', [ 'views/' . BEA_PB_VIEWS_FOLDER_NAME . '/' . $tpl . '.php' ], $tpl, __NAMESPACE__ );
3739

3840
// Locate from the theme
3941
$located = locate_template( $path, false, false );
@@ -66,7 +68,7 @@ public static function include_template( $tpl ) {
6668
return false;
6769
}
6870

69-
include( $tpl_path );
71+
include $tpl_path;
7072

7173
return true;
7274
}
@@ -88,24 +90,27 @@ public static function load_template( $tpl ) {
8890
return false;
8991
}
9092

91-
return function( $data ) use ( $tpl_path ) {
93+
return function ( $data ) use ( $tpl_path ) {
9294
if ( ! is_array( $data ) ) {
9395
$data = array( 'data' => $data );
9496
}
95-
extract( $data, EXTR_OVERWRITE );
96-
include( $tpl_path );
97+
98+
extract( $data, EXTR_OVERWRITE );
99+
include $tpl_path;
97100
};
98101
}
99102

100103
/**
101104
* Render a view
102105
*
103106
* @param string $tpl : the template's name
104-
* @param array $data : the template's data
107+
* @param array $data : the template's data
105108
*/
106109
public static function render( $tpl, $data = array() ) {
107110
$view = self::load_template( $tpl );
108-
false !== $view ? $view( $data ) : '';
111+
if ( false !== $view ) {
112+
$view( $data );
113+
}
109114
}
110115

111116
/**
@@ -119,7 +124,7 @@ public static function render( $tpl, $data = array() ) {
119124
*/
120125
public static function format_date( $date, $from_format, $to_format ) {
121126
$date = \DateTime::createFromFormat( $from_format, $date );
122-
if ( false == $date ) {
127+
if ( false === $date ) {
123128
return '';
124129
}
125130

classes/Main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BEA\PB;
34

45
/**

classes/Models/Model.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BEA\PB\Models;
34

45
/**
@@ -137,12 +138,12 @@ public function get_meta( $key, $format = true ) {
137138
$fields = $this->get_fields();
138139

139140
// Check ACF
140-
if ( ! in_array( $key, $fields ) && ! isset( $fields[ $key ] ) || ! function_exists( 'get_field' ) ) {
141+
if ( ! in_array( $key, $fields, true ) && ! isset( $fields[ $key ] ) || ! function_exists( 'get_field' ) ) {
141142
return $this->wp_object->{$key};
142143
}
143-
144+
144145
// On ACF given key
145-
$key = in_array( $key, $fields ) ? $key : $fields[ $key ];
146+
$key = in_array( $key, $fields, true ) ? $key : $fields[ $key ];
146147

147148
return get_field( $key, $this->get_ID(), $format );
148149
}
@@ -468,10 +469,18 @@ public function get_all_data() {
468469
* @return array
469470
*/
470471
public static function filter_post_array( $data ) {
471-
return array_intersect_key( $data, array_flip( array_filter( array_keys( $data ), array(
472-
__CLASS__,
473-
'filter_post_keys',
474-
) ) ) );
472+
return array_intersect_key(
473+
$data,
474+
array_flip(
475+
array_filter(
476+
array_keys( $data ),
477+
array(
478+
__CLASS__,
479+
'filter_post_keys',
480+
)
481+
)
482+
)
483+
);
475484
}
476485

477486
/**
@@ -491,7 +500,7 @@ public static function filter_post_keys( $key ) {
491500
$keys[] = 'tax_input';
492501
$keys[] = 'post_category';
493502

494-
return in_array( $key, $keys );
503+
return in_array( $key, $keys, true );
495504
}
496505

497506
/**

classes/Models/User.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace BEA\PB\Models;
34

45
/**
@@ -39,7 +40,8 @@ public function __construct( \WP_User $object ) {
3940
/**
4041
* Create user
4142
*
42-
* @param array $args
43+
* @param array $args
44+
*
4345
* @deprecated 2.1.3 $user_email Use first argument as array.
4446
*
4547
* @return false or user model
@@ -54,13 +56,14 @@ public static function create( $args, $user_email = null ) {
5456
'user_email' => $user_email,
5557
];
5658
}
59+
5760
return self::_create( $args );
5861
}
5962

6063
/**
6164
* User creation method
6265
*
63-
* @param array $args
66+
* @param array $args
6467
*
6568
* @return User|bool
6669
*

0 commit comments

Comments
 (0)