Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate smarter loader #25

Closed
ruudk opened this issue Dec 13, 2024 · 4 comments
Closed

Generate smarter loader #25

ruudk opened this issue Dec 13, 2024 · 4 comments
Labels
question Further information is requested

Comments

@ruudk
Copy link

ruudk commented Dec 13, 2024

I think one of the use cases for this package is to be able to work on a single problem (error identifier) at a time.

My ideal workflow would be to be able to delete a specific error identifier baseline and then run PHPStan.

Then see the errors, click the line where the error is happening, and fix it one by one.

But there is one problem with this: you also have to edit the loader.php file.

It would be great if the loader.php would read all the files in the directory automatically, and load them.

Something like this:

$files = Finder::create()->files()->name('*.php')->sortByName()->in(__DIR__ . '/src-dev/PHPStan/baselines');

return [
    'includes' => [
        ...array_values(array_map(fn ($file) => $file->getRealPath(), iterator_to_array($files))),
    ],

For now, I can solve this by not using the generated loader.php file, and manually include the baselines.

But it might be good to support this here too.

@janedbal
Copy link
Member

But there is one problem with this: you also have to edit the loader.php file.

I'm not sure I fully understand. What is the issue with adjusting loader file?

Also, just to see the errors, I think you can delete just contents of the single baseline (to maintain result cache usage).

@janedbal janedbal added the question Further information is requested label Dec 13, 2024
@ruudk
Copy link
Author

ruudk commented Dec 13, 2024

Sure, that also works, but it's more work.

With the finder method, it automatically works when you remove the file. Just an idea.

And as long as the files are there, the result cache is also the same.

@janedbal
Copy link
Member

I dont feel implementing that directly, sorry.

The only support for this I can imagine is to add some support for custom BaselineHandler, possibly via some --handler=My\Custom\BaselineHandler. Then, you could do whatever you like.

@ruudk
Copy link
Author

ruudk commented Dec 13, 2024

Ok, thanks.

For now, I can do it easily like this:

 "generate:baseline:phpstan": [
            "vendor/bin/phpstan analyse --memory-limit=-1 --configuration=phpstan.php --generate-baseline src-dev/PHPStan/config/baseline/loader.php",
            "split-phpstan-baseline src-dev/PHPStan/config/baseline/loader.php",
            "rm -f src-dev/PHPStan/config/baseline/loader.php"
        ]
$files = Finder::create()
    ->files()
    ->name('*.php')
    ->sortByName()
    ->in(__DIR__ . '/src-dev/PHPStan/config')
    ->notName('baseline-loader.php');

return [
    'includes' => [
        ...array_values(array_map(fn ($file) => $file->getRealPath(), iterator_to_array($files))),
    ],

@ruudk ruudk closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants