From d0b676f8ceb3666c2015bd835571bdda3d9affa5 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 21 Oct 2021 13:37:59 +0900 Subject: [PATCH] Add phan checks at max level --- .phan/config.php | 97 ++++++++++++++++++++++++++++++++++++ phpstan.neon | 7 --- src/AWS/AWS.php | 2 +- src/AmazonIncentives.php | 2 +- src/Client/Client.php | 2 +- src/Debug/AmazonDebug.php | 4 +- test/aws_gift_card_tests.php | 1 + 7 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 .phan/config.php diff --git a/.phan/config.php b/.phan/config.php new file mode 100644 index 0000000..4250d75 --- /dev/null +++ b/.phan/config.php @@ -0,0 +1,97 @@ + false, + + // Allow null to be cast as any type and for any + // type to be cast to null. + "null_casts_as_any_type" => false, + + // Backwards Compatibility Checking + 'backward_compatibility_checks' => true, + + // Run a quick version of checks that takes less + // time + "quick_mode" => false, + + // Only emit critical issues to start with + // (0 is low severity, 5 is normal severity, 10 is critical) + "minimum_severity" => 10, + + // default false for include path check + "enable_include_path_checks" => true, + "include_paths" => [ + ], + 'ignore_undeclared_variables_in_global_scope' => true, + + "file_list" => [ + ], + + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in exclude_analysis_directory_list, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => [ + // Change this to include the folders you wish to analyze + // (and the folders of their dependencies) + '.' + // 'www', + // To speed up analysis, we recommend going back later and + // limiting this to only the vendor/ subdirectories your + // project depends on. + // `phan --init` will generate a list of folders for you + //'www/vendor', + ], + + + // A list of directories holding code that we want + // to parse, but not analyze + "exclude_analysis_directory_list" => [ + 'vendor', + ], + 'exclude_file_list' => [ + ], + + // what not to show as problem + 'suppress_issue_types' => [ + // 'PhanUndeclaredMethod', + 'PhanEmptyFile', + ], + + // Override to hardcode existence and types of (non-builtin) globals in the global scope. + // Class names should be prefixed with `\`. + // + // (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`) + 'globals_type_map' => [], +]; diff --git a/phpstan.neon b/phpstan.neon index fe0a316..279478d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,10 +13,3 @@ parameters: - message: '#Strict comparison using === between false and true will always evaluate to false.#' path: %currentWorkingDirectory%/test/aws_gift_card_tests.php - #- 'error regex' - #- - # message: 'error regex' - # path: %currentWorkingDirectory%/www/some/* - # paths: - # - ... - # - ... diff --git a/src/AWS/AWS.php b/src/AWS/AWS.php index 427c026..1ab9411 100644 --- a/src/AWS/AWS.php +++ b/src/AWS/AWS.php @@ -321,7 +321,7 @@ class AWS /** * @param float $amount - * @param string $creation_id + * @param string|null $creation_id * @return string */ public function getGiftCardPayload(float $amount, ?string $creation_id = null): string diff --git a/src/AmazonIncentives.php b/src/AmazonIncentives.php index 3e5d44e..4cf19f1 100644 --- a/src/AmazonIncentives.php +++ b/src/AmazonIncentives.php @@ -54,7 +54,7 @@ final class AmazonIncentives /** * @param float $value - * @param string $creation_request_id AWS creationRequestId + * @param string|null $creation_request_id AWS creationRequestId * @return Response\CreateResponse * * @throws AmazonErrors diff --git a/src/Client/Client.php b/src/Client/Client.php index c82463e..6002075 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -55,7 +55,7 @@ class Client implements ClientInterface $error_status = 'RESEND'; $error_code = 'T001'; $error_type = 'RateExceeded'; - $message = $result_ar['message']; + $message = $result_ar['message'] ?? 'Rate exceeded'; } else { // for all other error messages $error_status = $result_ar['agcodResponse']['status'] ?? 'FAILURE'; diff --git a/src/Debug/AmazonDebug.php b/src/Debug/AmazonDebug.php index 2d767bc..cdc5914 100644 --- a/src/Debug/AmazonDebug.php +++ b/src/Debug/AmazonDebug.php @@ -16,7 +16,7 @@ class AmazonDebug */ private static $debug = false; /** - * @var string|null; + * @var string|null */ private static $id = null; @@ -91,7 +91,7 @@ class AmazonDebug if (self::$debug === false) { return; } - self::$log[self::getId()][] = $data; + self::$log[self::getId() ?? ''][] = $data; } /** diff --git a/test/aws_gift_card_tests.php b/test/aws_gift_card_tests.php index c51eaeb..936b973 100644 --- a/test/aws_gift_card_tests.php +++ b/test/aws_gift_card_tests.php @@ -249,6 +249,7 @@ if ($run_mocks === true) { $mock_ok = 'MOCK OK'; $mock_failure = 'MOCK FAILURE'; $mock_value = 500; + $mock = []; $mock['F0000'] = [ 'ret' => '', 'st' => 'SUCCESS']; // success mock $mock['F1000'] = [ 'ret' => 'F100', 'st' => 'FAILURE']; // SimpleAmountIsNull, etc