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

Fix all problems from PHPStan #2

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"mnsami/composer-custom-directory-installer": "^1.1",
"squizlabs/php_codesniffer": "3.*",
"wp-coding-standards/wpcs": "^2.3",
"szepeviktor/phpstan-wordpress": "^0.6.5",
"szepeviktor/phpstan-wordpress": "^0.6.6",
"paulthewalton/acf-stubs": "^5.8.7",
"timber/timber": "2.x-dev"
"timber/timber": "2.x-dev",
"php-stubs/wp-cli-stubs": "^2.4.0"
},
"config": {
"platform": {
Expand Down
128 changes: 84 additions & 44 deletions composer.lock

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

17 changes: 8 additions & 9 deletions greg.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
define('GREG_PLUGIN_VIEW_PATH', __DIR__ . '/views');


add_action('init', function() {
add_action('init', function() : void {
register_post_type('greg_event', [
'public' => true,
'description' => 'Calendar Events, potentially with recurrences',
Expand Down Expand Up @@ -102,7 +102,7 @@
/*
* Add REST Routes
*/
add_action('rest_api_init', function() {
add_action('rest_api_init', function() : void {
$controller = new RestController();
$controller->register_routes();
});
Expand All @@ -112,8 +112,7 @@
* Add WP-CLI tooling
*/
if (defined('WP_CLI') && WP_CLI) {
$command = new GregCommand();
WP_CLI::add_command('greg', $command);
WP_CLI::add_command('greg', GregCommand::class);
}

/**
Expand All @@ -138,7 +137,7 @@
return $data;
});

add_filter('timber/locations', function(array $paths) {
add_filter('timber/locations', function(array $paths) : array {
$paths['greg'] = [
get_template_directory() . '/views/greg',
GREG_PLUGIN_VIEW_PATH . '/twig',
Expand All @@ -147,10 +146,10 @@
return $paths;
});

add_filter('timber/twig', function(Environment $twig) {
$twig->addFunction(new TwigFunction('greg_compile', Greg\compile::class));
$twig->addFunction(new TwigFunction('greg_render', Greg\render::class));
$twig->addFunction(new TwigFunction('greg_get_events', Greg\get_events::class));
add_filter('timber/twig', function(Environment $twig) : Environment {
$twig->addFunction(new TwigFunction('greg_compile', '\\Greg\\compile'));
$twig->addFunction(new TwigFunction('greg_render', '\\Greg\\render'));
$twig->addFunction(new TwigFunction('greg_get_events', '\\Greg\\get_events'));

return $twig;
});
15 changes: 9 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ parameters:
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
bootstrapFiles:
- phpstan/bootstrap.php
- tests/phpstan/bootstrap.php
scanFiles:
- vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php
paths:
- src
- greg.php
- src/
#- tests/unit/
#- tests/integration/
ignoreErrors:
# TODO Figure out how to discover the WP_CLI class
- '#^Call to static method success\(\) on an unknown class WP_CLI\.$#'
# We can't have strong typehints without union types :(
- '#has no return typehint specified\.#'
# WP-CLI accepts a class as callable
- '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/'
Loading