Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase PHPstan level 1 #1707

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: PHPStan

on:
push:
branches:
- 'master'
- 'release/**'
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
branches:
- 'master'

jobs:
phpstan:
name: 'WP latest on PHP 8.3'

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4

# TODO Use the composer action below
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: uopz

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies (other PHP versions)
run: |
composer install --prefer-dist --no-progress --ignore-platform-reqs

- name: Run static suite
run: |
composer dump-autoload -o

#- uses: actions/checkout@v4
#- uses: php-actions/composer@v6

- name: PHPStan Static Analysis
uses: php-actions/phpstan@v3
with:
configuration: phpstan.neon
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"platform-check": false,
"allow-plugins": {
"php-http/discovery": true,
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"autoload": {
Expand Down Expand Up @@ -55,6 +56,8 @@
"slope-it/clock-mock": "^0.4.0",
"phpunit/php-code-coverage": "^9.2.32",
"myclabs/deep-copy": "^1.12.0",
"phpstan/phpstan": "^1.12"
"phpstan/phpstan": "^1.12",
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.4"
}
}
161 changes: 160 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function commonsbooking_sanitizeArrayorString( $data, $sanitizeFunction = 'sanit
* @param mixed $log can be a string, array or object
* @param bool $backtrace if set true the file-path and line of the calling file will be added to the error message
*
* @return string logmessage
* @return void
*/
function commonsbooking_write_log( $log, $backtrace = true ) {

Expand All @@ -308,6 +308,5 @@ function commonsbooking_write_log( $log, $backtrace = true ) {
$logmessage = $file . ':' . $line . ' ' . $logmessage;
}

error_log( $logmessage ) ;

error_log( $logmessage );
}
1 change: 1 addition & 0 deletions includes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ function commonsbooking_get_template_part( $slug, $name = '', $include = true, $
} else if ( $template && $include === false ) {
return $before_html . $template . $after_html;
}
return '';
}
}
4 changes: 2 additions & 2 deletions includes/TemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ function commonsbooking_parse_template_callback( $match, array $objects = [], $s
/**
* Return Custom Post Type postType for template type string
*
* @param [type] $type type could be location, booking, item
* @param string $type type could be location, booking, item
*
* @return void
* @return string
*/
function commonsbooking_getCBType( $type ) {
if ( $type == 'location' ) {
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Action callback returns bool but should not return anything\\.$#"
count: 1
path: src/Wordpress/CustomPostType/CustomPostType.php
11 changes: 6 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
includes:
- phpstan-baseline.neon
parameters:
phpVersion: 70400
scanFiles:
- commonsbooking.php
- vendor/cmb2/cmb2/includes/helper-functions.php
scanDirectories:
- /tmp/wordpress
- /tmp/wordpress-tests-lib
- vendor/cmb2/cmb2/includes/CMB2_Utils.php
- vendor/cmb2/cmb2/includes/CMB2_Field.php
paths:
- commonsbooking.php
- src/
- tests/
- includes/
level: 1
ignoreErrors:
- identifier: missingType.iterableValue
- '#Constant (COMMONSBOOKING.*|WP_DEBUG_LOG) not found.#'
- '#Instantiated class (CommonsBooking.*CB_Data) not found.#'
- '#Function cb_object_to_array not found.#'

1 change: 1 addition & 0 deletions src/CB/CB1UserFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public function registration_add_meta( $user_id ) {
/**
* Sets a flat array of user field/value pairs
*
* @since 2.10 deprecated (cb_object_to_array is unspecified)
* @since 0.6
*
*/
Expand Down
7 changes: 4 additions & 3 deletions src/Service/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ public static function clearCache( array $tags = [] ) {
* Calls clearCache using WP Cron.
* Why? ClearCache can be resource intensive on larger instances and should be offloaded.
*
* @param array $tags
* @param array $tags to clear cache for
*
* @return void
*/
public static function scheduleClearCache( array $tags = [] ) {
$event = wp_schedule_single_event( time(), self::$clearCacheHook, [ $tags ] );
$event = wp_schedule_single_event( time(), self::$clearCacheHook, [ $tags ], true );
// TODO document why only on wp-error, why this can fail, why we don't re-try or do other things, instead of forcing the execution of this resource intensive task?
if ( is_wp_error( $event ) ) {
//run the event right away when scheduling fails
// runs the event right away, when scheduling fails
self::clearCache( $tags );
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Service/Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Holiday {
* @param $object_type
* @param $field_type
*
* @return void
* @return string
*/
public static function renderFields( $field, $value, $object_id, $object_type, $field_type ) {

Expand Down Expand Up @@ -61,6 +61,8 @@ public static function renderFields( $field, $value, $object_id, $object_type, $
<br class="clear">
<?php
echo $field_type->_desc( true );

return '';
}


Expand Down
2 changes: 1 addition & 1 deletion src/Wordpress/CustomPostType/CustomPostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static function getCMB2FieldsArrayFromCustomMetadata( $type ): ?array {
*
* @param mixed $actions
*
* @return void
* @return mixed
*/
public static function modifyRowActions( $actions, $post ) {

Expand Down
2 changes: 1 addition & 1 deletion src/Wordpress/CustomPostType/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function initHooks() {
add_shortcode( 'cb_map', array( MapShortcode::class, 'execute' ) );

// Add actions
add_action( 'save_post_' . self::$postType, array( MapAdmin::class, 'validate_options' ), 10, 3 );
add_action( 'save_post_' . self::$postType, array( MapAdmin::class, 'validate_options' ), 10, 1 );
add_action( 'add_meta_boxes_cb_map', array( MapAdmin::class, 'add_meta_boxes' ) );
}

Expand Down
2 changes: 2 additions & 0 deletions src/Wordpress/CustomPostType/Timeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,8 @@ public function setCustomColumnSortOrder( \WP_Query $query ) {

/**
* Initiates needed hooks.
*
* @return void
*/
public function initHooks() {
// Add custom cmb2 type for email booking codes by cron
Expand Down
Loading