diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 73d7925..fc79b46 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,7 +2,8 @@ $finder = PhpCsFixer\Finder::create() ->exclude([ - 'tests/data' + 'tests/data', + 'playground', ]) ->in(__DIR__); diff --git a/README.md b/README.md index 0f3669f..09d76c4 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,38 @@ You can customize in your `phpstan.neon`: ```neon parameters: friendly: - # default is 3 - lineBefore: 3 - lineAfter: 3 - # default is null + lineBefore: 3 # Number of lines to display before error line (default: 2) + lineAfter: 3 # Number of lines to display after error line (default: 2) + editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' # Editor URL (default: null) +``` + +### Editor URL Configuration + +The `editorUrl` option allows you to create clickable links in terminal output that open files directly in your editor. + +**Available placeholders:** +- `%%file%%` - Absolute file path +- `%%relFile%%` - Relative file path (useful for Docker/container environments) +- `%%line%%` - Line number + +**Editor examples:** +```neon +parameters: + friendly: + # PhpStorm / IntelliJ IDEA editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' + + # VSCode (with absolute path) + editorUrl: 'vscode://file/%%file%%:%%line%%' + + # VSCode (with relative path - for Docker environments, requires base path) + editorUrl: 'vscode://file//your/local/project/path/%%relFile%%:%%line%%' + + # Sublime Text + editorUrl: 'subl://open?url=file://%%file%%&line=%%line%%' ``` -- `lineBefore` ... Number of lines to display before error line -- `lineAfter` ... Number of lines to display after error line -- `editorUrl` ... URL with placeholders like [table formatter config](URL for editor like table formatter) +> **Note:** When running PHPStan in Docker or other virtualized environments, use `%%relFile%%` instead of `%%file%%` to get the relative path. For VSCode, you may need to prepend your local project path since VSCode requires absolute paths. ## 🖼️ Example diff --git a/composer.json b/composer.json index 68d617d..2a98806 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "analyze": "phpstan analyze -c phpstan.neon.dist --error-format friendly", "analyze-raw": "phpstan analyze -c phpstan.neon.dist --error-format raw", "analyze-table": "phpstan analyze -c phpstan.neon.dist --error-format table", + "playground": "phpstan analyze playground -c playground/phpstan.neon --error-format friendly", "cs-fix": "php-cs-fixer fix", "cs-fix-dry": "php-cs-fixer fix --dry-run" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 10339bd..8d4907b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -38,3 +38,7 @@ parameters: friendly: lineBefore: 2 lineAfter: 2 + # editorUrl examples: + # - PhpStorm: 'phpstorm://open?file=%%relFile%%&line=%%line%%' + # - VSCode (local): 'vscode://file//path/to/project/%%relFile%%:%%line%%' + editorUrl: null diff --git a/playground/dead_code.php b/playground/dead_code.php new file mode 100644 index 0000000..23cbb9c --- /dev/null +++ b/playground/dead_code.php @@ -0,0 +1,52 @@ + 'first', + 'key' => 'second', // Error: duplicate key + ]; +} diff --git a/playground/missing_types.php b/playground/missing_types.php new file mode 100644 index 0000000..8b65ba8 --- /dev/null +++ b/playground/missing_types.php @@ -0,0 +1,39 @@ +untyped = $input; + return $input; + } +} + +// 4. Mixed type usage +function usesMixed(mixed $value): mixed +{ + return $value->someMethod(); // Error: calling method on mixed +} diff --git a/playground/phpstan.neon b/playground/phpstan.neon new file mode 100644 index 0000000..36aa70d --- /dev/null +++ b/playground/phpstan.neon @@ -0,0 +1,16 @@ +# PHPStan configuration for playground +# Usage: cd playground && ../vendor/bin/phpstan analyze + +includes: + - ../extension.neon + +parameters: + level: 9 + paths: + - . + + # Friendly formatter settings + friendly: + lineBefore: 3 + lineAfter: 3 + editorUrl: 'vscode://file/%%relFile%%:%%line%%' diff --git a/playground/type_errors.php b/playground/type_errors.php new file mode 100644 index 0000000..5d4698d --- /dev/null +++ b/playground/type_errors.php @@ -0,0 +1,56 @@ + $items */ +function processStringArray(array $items): void +{ + foreach ($items as $item) { + echo $item; + } +} + +processStringArray([1, 2, 3]); // Error: array of int, not string + +// 5. Property type mismatch +class TypedClass +{ + public string $name; + + public function __construct() + { + $this->name = 42; // Error: wrong type + } +} diff --git a/playground/undefined_errors.php b/playground/undefined_errors.php new file mode 100644 index 0000000..2e9d2ec --- /dev/null +++ b/playground/undefined_errors.php @@ -0,0 +1,42 @@ +nonExistentMethod(); // Error: undefined method + +// 3. Undefined class +$instance = new NonExistentClass(); // Error: undefined class + +// 4. Undefined constant +echo UNDEFINED_CONSTANT; // Error: undefined constant + +// 5. Undefined property +class AnotherClass +{ + public string $definedProperty = 'hello'; +} + +$another = new AnotherClass(); +echo $another->undefinedProperty; // Error: undefined property + +// 6. Undefined function +undefinedFunction(); // Error: undefined function