Skip to content

Commit 033737f

Browse files
authored
Merge pull request #30 from BeAPI/feature/psalm
Feature/psalm
2 parents c899da6 + 469e6a5 commit 033737f

File tree

19 files changed

+1527
-295
lines changed

19 files changed

+1527
-295
lines changed

bea-plugin-boilerplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
/**
6666
* Init the plugin
6767
*/
68-
function init_bea_pb_plugin() {
68+
function init_bea_pb_plugin(): void {
6969
// Client
7070
\BEA\PB\Main::get_instance();
7171

classes/Admin/Main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class Main {
1616
*/
1717
use Singleton;
1818

19-
public function __construct() {
19+
public function init(): void {
2020
}
2121
}

classes/Blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Blocks {
1616

1717
use Singleton;
1818

19-
public function init() {
19+
public function init(): void {
2020
add_action( 'init', [ $this, 'register_blocks' ], 1 );
2121
add_action( 'beapi_helpers_locate_template_templates', [ $this, 'block_templates' ], 10, 2 );
2222
}

classes/Compatibility.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Compatibility {
88
*
99
* @since 0.1
1010
*/
11-
public static function admin_init() {
11+
public static function admin_init() : void {
1212
// Not on ajax
1313
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1414
return;
@@ -37,7 +37,7 @@ public static function admin_init() {
3737
/**
3838
* Notify the user about the incompatibility issue.
3939
*/
40-
public static function admin_notices() {
40+
public static function admin_notices(): void {
4141
echo '<div class="notice error is-dismissible">';
4242
/* translators: %1$s: PHP min version %2$s: Current PHP version */
4343
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>';

classes/Controllers/Controller.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected function is_page() {
5757
* @return false|string
5858
* @author Nicolas Juen
5959
*/
60-
public function get_form_url( $args = array() ) {
61-
return Router::get_url_complex( array( $this->page_slug ), $args );
60+
public function get_form_url( $args = [] ) {
61+
return Router::get_url_complex( [ $this->page_slug ], $args );
6262
}
6363

6464
/**
@@ -68,7 +68,7 @@ public function get_form_url( $args = array() ) {
6868
*
6969
* @author Nicolas Juen
7070
*/
71-
protected function redirect( $args = array() ) {
71+
protected function redirect( $args = [] ): void {
7272
wp_safe_redirect( $this->get_form_url( $args ) );
7373
exit;
7474
}
@@ -80,7 +80,7 @@ protected function redirect( $args = array() ) {
8080
* @return \WP_Error|self
8181
*/
8282
public static function get_current_controller() {
83-
$classes = array_filter( get_declared_classes(), array( __CLASS__, 'filter_classes' ) );
83+
$classes = array_filter( get_declared_classes(), [ __CLASS__, 'filter_classes' ] );
8484

8585
// Check there is classes
8686
if ( empty( $classes ) ) {
@@ -97,12 +97,12 @@ public static function get_current_controller() {
9797
/**
9898
* Get among all classes the right one
9999
*
100-
* @param $class
100+
* @param string $class
101101
*
102102
* @return bool
103103
* @author Nicolas Juen
104104
*/
105-
public static function filter_classes( $class ) {
105+
public static function filter_classes( string $class ): bool {
106106
if ( false === is_subclass_of( $class, '\BEA\PB\Controller', true ) ) {
107107
return false;
108108
}
@@ -118,6 +118,6 @@ public static function filter_classes( $class ) {
118118
* @author Nicolas Juen
119119
*/
120120
public function get_default_data() {
121-
return array();
121+
return [];
122122
}
123123
}

classes/Cron/Cron.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ abstract class Cron {
2323
protected $type = '';
2424

2525
/**
26-
* @var $log \Bea_Log
26+
* @var \Bea_Log $log
2727
*/
2828
private $log;
2929

3030
/**
31-
* @var $filesystem \WP_Filesystem_Direct
31+
* @var \WP_Filesystem_Direct $filesystem
3232
*/
3333
protected $filesystem;
3434

@@ -130,10 +130,10 @@ private function get_log_file_path( $extension = true ) {
130130
/**
131131
* Log a message for the current type
132132
*
133-
* @param $message : message to write on the log file
134-
* @param $type : log level message
133+
* @param string $message : message to write on the log file
134+
* @param string $type : log level message
135135
*/
136-
protected function add_log( $message, $type = \Bea_Log::gravity_7 ) {
136+
protected function add_log( string $message, string $type = \Bea_Log::gravity_7 ): void {
137137
// Log if bea log or not
138138
if ( ! is_a( $this->log, '\Bea_Log' ) ) {
139139
$this->log = new \Bea_Log( $this->get_log_file_path( false ), '.log' );

classes/Helpers.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Helpers {
3030
*
3131
* @return bool|string
3232
*/
33-
public static function locate_template( $tpl ) {
33+
public static function locate_template( string $tpl ) {
3434
if ( empty( $tpl ) ) {
3535
return false;
3636
}
@@ -58,7 +58,7 @@ public static function locate_template( $tpl ) {
5858
*
5959
* @return bool
6060
*/
61-
public static function include_template( $tpl ) {
61+
public static function include_template( string $tpl ): bool {
6262
if ( empty( $tpl ) ) {
6363
return false;
6464
}
@@ -80,7 +80,7 @@ public static function include_template( $tpl ) {
8080
*
8181
* @return \Closure|false
8282
*/
83-
public static function load_template( $tpl ) {
83+
public static function load_template( string $tpl ) {
8484
if ( empty( $tpl ) ) {
8585
return false;
8686
}
@@ -90,11 +90,12 @@ public static function load_template( $tpl ) {
9090
return false;
9191
}
9292

93-
return function ( $data ) use ( $tpl_path ) {
93+
return static function ( $data ) use ( $tpl_path ) {
9494
if ( ! is_array( $data ) ) {
9595
$data = array( 'data' => $data );
9696
}
9797

98+
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
9899
extract( $data, EXTR_OVERWRITE );
99100
include $tpl_path;
100101
};
@@ -106,7 +107,7 @@ public static function load_template( $tpl ) {
106107
* @param string $tpl : the template's name
107108
* @param array $data : the template's data
108109
*/
109-
public static function render( $tpl, $data = array() ) {
110+
public static function render( string $tpl, $data = array() ): void {
110111
$view = self::load_template( $tpl );
111112
if ( false !== $view ) {
112113
$view( $data );
@@ -116,13 +117,13 @@ public static function render( $tpl, $data = array() ) {
116117
/**
117118
* Transform a date to a given format if possible
118119
*
119-
* @param string $date : date to transform
120-
* @param $from_format : the from date format
121-
* @param $to_format : the format to transform in
120+
* @param string $date : date to transform
121+
* @param string $from_format : the from date format
122+
* @param string $to_format : the format to transform in
122123
*
123124
* @return string the date formatted
124125
*/
125-
public static function format_date( $date, $from_format, $to_format ) {
126+
public static function format_date( string $date, string $from_format, string $to_format ): string {
126127
$date = \DateTime::createFromFormat( $from_format, $date );
127128
if ( false === $date ) {
128129
return '';
@@ -139,7 +140,7 @@ public static function format_date( $date, $from_format, $to_format ) {
139140
*
140141
* @return string
141142
*/
142-
public static function datetime_i18n( $format, \DateTime $date ) {
143+
public static function datetime_i18n( string $format, \DateTime $date ): string {
143144
return date_i18n( $format, $date->format( 'U' ) );
144145
}
145146

classes/Main.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class Main {
1919
*/
2020
use Singleton;
2121

22-
protected function init() {
23-
add_action( 'init', array( $this, 'init_translations' ) );
22+
protected function init(): void {
23+
add_action( 'init', [ $this, 'init_translations' ] );
2424
}
2525

2626
/**
2727
* Load the plugin translation
2828
*/
29-
public function init_translations() {
29+
public function init_translations(): void {
3030
// Load translations
3131
load_plugin_textdomain( 'bea-plugin-boilerplate', false, BEA_PB_PLUGIN_DIRNAME . '/languages' );
3232
}

0 commit comments

Comments
 (0)