From 5fc48bbb62a1e172fac6a0733f3cabae05a19bbc Mon Sep 17 00:00:00 2001 From: robchett Date: Sat, 17 Jun 2023 10:03:08 +0100 Subject: [PATCH 1/2] Add a stub file for Attributes defined by PHP --- src/Psalm/Config.php | 2 ++ stubs/CoreGenericAttributes.phpstub | 13 +++++++++++++ stubs/Php82.phpstub | 12 ------------ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 stubs/CoreGenericAttributes.phpstub diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index fc976649758..23df8dfde68 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -2236,6 +2236,8 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null): ]; if ($codebase->analysis_php_version_id >= 8_00_00) { + $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericAttributes.phpstub'; + $this->internal_stubs[] = $stringable_path; $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php80.phpstub'; $this->internal_stubs[] = $stringable_path; } diff --git a/stubs/CoreGenericAttributes.phpstub b/stubs/CoreGenericAttributes.phpstub new file mode 100644 index 00000000000..7aa6400df06 --- /dev/null +++ b/stubs/CoreGenericAttributes.phpstub @@ -0,0 +1,13 @@ + Date: Sat, 17 Jun 2023 14:13:04 +0100 Subject: [PATCH 2/2] Fix line lenght --- src/Psalm/Config.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 23df8dfde68..8d91b755be2 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -2226,30 +2226,27 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null): $codebase->register_stub_files = true; $dir_lvl_2 = dirname(__DIR__, 2); + $stubsDir = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR; $this->internal_stubs = [ - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericFunctions.phpstub', - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericClasses.phpstub', - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericIterators.phpstub', - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreImmutableClasses.phpstub', - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Reflection.phpstub', - $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'SPL.phpstub', + $stubsDir . 'CoreGenericFunctions.phpstub', + $stubsDir . 'CoreGenericClasses.phpstub', + $stubsDir . 'CoreGenericIterators.phpstub', + $stubsDir . 'CoreImmutableClasses.phpstub', + $stubsDir . 'Reflection.phpstub', + $stubsDir . 'SPL.phpstub', ]; if ($codebase->analysis_php_version_id >= 8_00_00) { - $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'CoreGenericAttributes.phpstub'; - $this->internal_stubs[] = $stringable_path; - $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php80.phpstub'; - $this->internal_stubs[] = $stringable_path; + $this->internal_stubs[] = $stubsDir . 'CoreGenericAttributes.phpstub'; + $this->internal_stubs[] = $stubsDir . 'Php80.phpstub'; } if ($codebase->analysis_php_version_id >= 8_01_00) { - $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php81.phpstub'; - $this->internal_stubs[] = $stringable_path; + $this->internal_stubs[] = $stubsDir . 'Php81.phpstub'; } if ($codebase->analysis_php_version_id >= 8_02_00) { - $stringable_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'Php82.phpstub'; - $this->internal_stubs[] = $stringable_path; + $this->internal_stubs[] = $stubsDir . 'Php82.phpstub'; $this->php_extensions['random'] = true; // random is a part of the PHP core starting from PHP 8.2 }