canvural / phpstan-blade-rule Goto Github PK
View Code? Open in Web Editor NEWPHPStan rule for static analysis of Blade templates
License: MIT License
PHPStan rule for static analysis of Blade templates
License: MIT License
I thought I'd just add an issue so that this doesn't get lost, however I'm currently looking into it a bit. ๐๐ป
See owenvoke#3 for a fixture that demonstrates this issue.
When using the @include()
directive with a file that contains use statements, in standard Blade it compiles to separate files, whereas (AFAICT) this package compiles to a single file which is checked (correct me if I'm wrong). But this causes the use statements to fail as they are in the global scope. Resulting in a PHP syntax error.
The error that will be output is:
PhpParser\Error: Syntax error, unexpected T_USE on line 5
Looks like it's because the use
statement is embedded inside a function
block when it's compiled. ๐ค e.g.
<?php
(function () {
use Illuminate\Support\Facades\URL;
URL::current();
});
Greetings.
Having PHPStan 1.8.4 installed beforehand, I gave this extension a try. It threw the following internal error:
Internal error: Internal error: PHPStan\Analyser\FileAnalyser::analyseFile(): Argument #4 ($collectorRegistry) must be of type PHPStan\Collectors\Registry, null given, called in /var/www/project/vendor/canvural/phpstan-blade-rule/src/Rules/ViewRuleHelper.php on line 94 in file
/var/www/project/app/Http/Controllers/NegocioController.php
Run PHPStan with -v option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Child process error (exit code 1):
It turns out PHPStan 1.8.0 introduced a breaking change in its signature for method analyseFile , which now reads:
public function analyseFile(
string $file,
array $analysedFiles,
RuleRegistry $ruleRegistry,
CollectorRegistry $collectorRegistry,
?callable $outerNodeCallback,
): FileAnalyserResult
whereas, up to version 1.7.15, the same method used to have the signature:
public function analyseFile(
string $file,
array $analysedFiles,
Registry $registry,
?callable $outerNodeCallback,
): FileAnalyserResult
For the time being I have resorted to downgrading and pinning PHPStan, but since I didn't see the issue reported elsewhere, I thought you might want to be given the heads up.
Thanks!
Could be kinda related to #4
When I put your rules non commented phpstan outputs some PHP parse errors on files that have nothing to do with the extension
diff --git a/phpstan.neon b/phpstan.neon
index c8892207e..2ecac5269 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,6 +1,9 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./phpstan-baseline.neon
+ - ./vendor/canvural/phpstan-blade-rule/config/extension.neon
+ - ./vendor/symplify/template-phpstan-compiler/config/services.neon
+ - ./vendor/symplify/astral/config/services.neon
parameters:
level: max
paths:
@@ -9,3 +12,5 @@ parameters:
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- xxxxxxxxxxxxxxxxxxxxxxxxxxx
+ templatePaths:
+ - resources/views
Using this container that runs PHP 8.1.3: https://hub.docker.com/r/lcde/laravel
This projects allows one to exercise total control over blade templates.
@canvural What are your plans wit it?
I think it cannot be installed with L10, PHPStan 1.10
I've added includes and templatePaths as described in README.
v0.4
I'm analyzing a package with testbench. Could it be the cause?
Hi, first of all thank you. I've been waiting to be able to run static analysis on my blade templates since a long time.
Unfortunately on my first try I get only a bunch of syntax errors such as:
------ ---------------------------------------------------------------
Line Domain/Schedulers/Http/Controllers/SchedulePlanController.php
------ ---------------------------------------------------------------
217 Syntax error, unexpected T_ENDIF on line 217
------ ---------------------------------------------------------------
or
------ --------------------------------------------------------------
Line Domain/Statistics/Http/Controllers/StatsController.php
------ --------------------------------------------------------------
6 Syntax error, unexpected T_VARIABLE, expecting ';' on line 6
------ --------------------------------------------------------------
What I can tell you is that, for example, SchedulePlanController doesn't even have 217 lines so, I guess, its referring to some issue in some of the blade templates rendered by the controller?
My composer.json
is something like:
{
"require": {
"php": ">=8.0",
"laravel/framework": "^8.0",
"laravel/helpers": "^1.2",
"laravel/legacy-factories": "^1.1",
"laravel/ui": "^3.0",
},
"require-dev": {
"canvural/phpstan-blade-rule": "^0.1.0",
"nunomaduro/larastan": "^1.0",
},
"autoload": {
"classmap": [
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Domain\\": "app/Domain/",
"Common\\": "app/Common/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Common/helpers.php"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
My phpstan.neon
file:
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/canvural/phpstan-blade-rule/config/extension.neon
- ./vendor/symplify/template-phpstan-compiler/config/services.neon
- ./vendor/symplify/astral/config/services.neon
parameters:
paths:
- app/Domain
- app/Common
templatePaths:
- resources/views
# The level 8 is the highest level
level: 8
#ignoreErrors:
# - '#Unsafe usage of new static#'
excludePaths:
- ./*/*/FileToBeExcluded.php
checkMissingIterableValueType: false
I've also tried to comment larastan extension but nothing.
Thought it might be useful to start tracking some errors/false negatives that show up.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.