Giter VIP home page Giter VIP logo

phpstan-blade-rule's Issues

Unable to use `use` statements in a blade template that is included

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();
});

Internal error when used with PHPStan 1.8.x

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!

Syntax error, unexpected ')', expecting T_VARIABLE on line 2

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 is so nice project

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

Syntax error, unexpected T_ENDIF on line X

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.