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

Feature/exclude directory for insights #293

Merged

Conversation

Jibbarth
Copy link
Collaborator

Q A
Bug fix? no
New feature? yes
Fixed tickets #240 #243 #108 (comment)

This PR add possibility to configure exclude part with a directory in addition of filepath:

        ForbiddenSetterSniff::class => [
            'exclude' => [
                'src/Domain/MySpeciedClass',
                'src/Models',
            ],
        ],

In the example above, all classes in src/Models will be excluded for the ForbiddenSetterSniff

This PR also port the exclude feature to our own Insights (ForbiddenDefineGlobalConstants, ForbiddenGlobals ...). I added the exclude check for each Insights that implement HasDetail interface.

@Jibbarth Jibbarth added the enhancement New feature or request label Oct 19, 2019
Copy link
Collaborator

@olivernybroe olivernybroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have commented on some small improvements for readability and performance :)

src/Domain/Insights/CyclomaticComplexityIsHigh.php Outdated Show resolved Hide resolved
src/Domain/Helper/FilesFinder.php Outdated Show resolved Hide resolved
src/Domain/Insights/FixerDecorator.php Show resolved Hide resolved
src/Domain/Insights/ForbiddenFinalClasses.php Show resolved Hide resolved
src/Domain/Insights/Insight.php Show resolved Hide resolved
@olivernybroe
Copy link
Collaborator

We should maybe consider changing our preset after this gets merged. I think we could help the Laravel developers at least with some changes here.

@Jibbarth Jibbarth force-pushed the feature/exclude-directory-for-insights branch from 079a48e to 5b39da7 Compare October 28, 2019 18:50
Copy link
Collaborator

@olivernybroe olivernybroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I think this is almost ready now.

There is a duplication on a method which I think we should handle, either with a trait, a helper class or just a adding the method to our insight class.

src/Domain/Insights/CyclomaticComplexityIsHigh.php Outdated Show resolved Hide resolved
src/Domain/Insights/ForbiddenDefineGlobalConstants.php Outdated Show resolved Hide resolved
src/Domain/Insights/ForbiddenFinalClasses.php Outdated Show resolved Hide resolved
src/Domain/Insights/ForbiddenNormalClasses.php Outdated Show resolved Hide resolved
src/Domain/Insights/ForbiddenTraits.php Outdated Show resolved Hide resolved
$exclude = $config['exclude'] ?? [];
if (count($exclude) > 0) {
$this->excludedFiles = Files::find(
(string) getcwd(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this act in case where getcwd returns false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried and it throw a DirectoryNotFoundException.

I can add a check on $basedir in Files::find and return an empty array if it's not exist to avoid throw an exception ? WDYT

Copy link
Collaborator

@olivernybroe olivernybroe Nov 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm whatever you prefer here tbh. I don't really have an opinion

src/Domain/Insights/InsightFactory.php Outdated Show resolved Hide resolved
src/Domain/Insights/FixerDecorator.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@olivernybroe olivernybroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, when you have figured out which way you want to handle that weird edgecase with cwd, then you can go ahead 👍

The code is really nice, great work! 😃

@Jibbarth Jibbarth force-pushed the feature/exclude-directory-for-insights branch from d948c30 to f595789 Compare November 16, 2019 10:44
@Jibbarth
Copy link
Collaborator Author

@olivernybroe I add a fallback when getcwd return false to use configuration Directory 😉

@Jibbarth Jibbarth merged commit 261e151 into nunomaduro:master Nov 16, 2019
@Jibbarth Jibbarth deleted the feature/exclude-directory-for-insights branch November 16, 2019 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants