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

excludePaths config doesn't merge when using different styles #4561

Closed
jshah4517 opened this issue Feb 18, 2021 · 7 comments
Closed

excludePaths config doesn't merge when using different styles #4561

jshah4517 opened this issue Feb 18, 2021 · 7 comments
Labels

Comments

@jshah4517
Copy link

Bug report

If you have one config file with excludePaths in one format (single level), and another config file with excludePaths in another format (two levels, with analyse and analyseAndScan options), you get an error that the configuration is invalid when they are used together.

Code snippet that reproduces the problem

We use the Larastan extension (https://github.com/nunomaduro/larastan).

Their parameters includes the following:

    excludePaths:
        - *.blade.php

Our config file looks like the following. We have some directories that we want to scan but not analyse.

includes:
    - ./vendor/nunomaduro/larastan/extension.neon

parameters:
    level: 8
    paths:
        - app/
    excludePaths:
        analyse:
            - app/Plugins/*
        analyseAndScan:
            - */node_modules/*
            - */vendor/*

This gives the following error:

Invalid configuration:
Unexpected option 'parameters › excludePaths › 0', 'parameters › excludePaths › analyseAndScan'.
Invalid configuration:
Unexpected option 'parameters › excludePaths › 0', 'parameters › excludePaths › analyse'.
Invalid configuration:
Unexpected option 'parameters › excludePaths › 0'.

Expected output

It merges the config correctly and uses analyseAndScan as the option for the config that is single level.

@mergeable
Copy link

mergeable bot commented Feb 18, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ZeWaren
Copy link

ZeWaren commented Apr 26, 2021

Until this bug is fixed, here is a dirty workaround.

Here is a PHP file that loads the neon file from larastan and renames the entry so that if fits the other schema style so that the other files can be merged with it:

<?php

/**
 * This file loads the PHPStan neon file from LaraStan, and rename the entry with the excluded paths.
 *
 * See:
 *   phpstan/phpstan: "excludePaths config doesn't merge when using different styles #4561"
 *   https://github.com/phpstan/phpstan/issues/4561
 */

use PHPStan\DependencyInjection\NeonAdapter;

# Load the neon file from LaraStan:
$neonAdapter = new NeonAdapter();
$data = $neonAdapter->load('./vendor/nunomaduro/larastan/extension.neon');

# Replace parameters.excludePaths with parameters.excludePaths.analyseAndScan:
$laraStanExcludedPaths = $data['parameters']['excludePaths'];
unset($data['parameters']['excludePaths']);
$data['parameters']['excludePaths'] = [
    'analyseAndScan' => $laraStanExcludedPaths,
];

# Return the file:
return $data;

The file can be included the same way neon files are included as usual:

includes:
    - ./phpstan_larastan_neon_loader.php

@canvural
Copy link
Contributor

@ZeWaren If it'll make other people's life easier and if there is no BC break, I can accept a PR to Larastan that changes this 👍

@ondrejmirtes
Copy link
Member

@canvural There's no combination Larastan can have in its extension.neon, it'd always break someone's config. I haven't thought of this scenario when I allowed multiple different notations for excludePaths. It needs to be fixed and allowed in phpstan/phpstan.

@canvural
Copy link
Contributor

@ondrejmirtes Ah, ok. I understand now.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@e7ac788

Feel free to test dev-master: composer require --dev phpstan/phpstan:dev-master --prefer-dist

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants