Symplify: Problem with ecs check --config custom/path/ecs.php

Created on 13 Nov 2020  路  8Comments  路  Source: symplify/symplify

Hi.

I might have located a Problem with the option --config custom/path/ecs.php.
If I have the ecs.php file located in my project root directory

The PATHS and EXCLUDE_PATHS looking like this

$parameters->set(Option::PATHS, [
        __DIR__ . '/app',
        __DIR__ . '/tests',
        __DIR__ . '/ecs.php',
    ]);

    $parameters->set(Option::EXCLUDE_PATHS, [
        __DIR__ . '/tests/fixtures/**',
    ]);

It works perfectly fine.
But moving the ecs.php to a sub-folder e.g. build/ecs.php and adjusting the sections too

$parameters->set(Option::PATHS, [
        __DIR__ . '/../app',
        __DIR__ . '/../tests',
        __DIR__ . '/ecs.php',
    ]);

    $parameters->set(Option::EXCLUDE_PATHS, [
        __DIR__ . '/../tests/fixtures/**',
    ]);

Only the PATHS works, not the EXCLUDE_PATHS. If I don't adjust the PATHS section ecs complains that path isn't found. But not with the EXCLUDE_PATH.

I haven't found the reason for this yet, but looks like the EXCLUDE_PATHS is ignored in this context.
Will dig into this and try to figure out what the problem is.

Forgot to mention: I'm on version 8.3.48

All 8 comments

The problem as I see it is within this function:
https://github.com/symplify/symplify/blob/3b215261fd/packages/skipper/src/Skipper/Skipper.php#L165

Having ecs.php in project root, the value is as following:

$smartFileInfo->getRealPath() = "/jez/tests/fixtures/file.php"
// Before reassigned 
$ignorePath = "/jez/tests/fixtures/**"

// After Normalized
$ignorePath = "*/jez/tests/fixtures/**"

$smartFileInfo->endsWith($ignoredPath) = false 
$smartFileInfo->doesFnmatch($ignoredPath) = true

With the build/ecs.php the values are as following:

$smartFileInfo->getRealPath() = "/jez/tests/fixtures/file.php"
// Before reassigned 
$ignorePath = "/jez/build/../tests/fixtures/**"

// After Normalized
$ignorePath = "*/jez/build/../tests/fixtures/**"

$smartFileInfo->endsWith($ignoredPath) = false 
$smartFileInfo->doesFnmatch($ignoredPath) = false

As the $ignorePath contains the build/../ it will never match.

I don't know about the beauty of the fix. But added realpath() around the return $path in
https://github.com/symplify/symplify/blob/3b215261fd/packages/skipper/src/FileSystem/PathNormalizer.php#L39

Would do the trick.

 return realpath($path);

This is by the way all references to the mono-repo the version 8.3.48 is a little different where the files and fuctions are located.

I would love to do a PR but haven't found where to add the tests, and I would prefer having feedback before implementing the change.

Hi, thank you for finding the problematic spot!

A quick look... the PathNormalizer should have PathNormalizerTest.
So you can create it and test there.

Do I look at the wrong place? I only find tests for the Skipper not for the PathNormalizer, I can add them, but wanted to be sure I'm not on the wrong location.

Screenshot

Yes, you need to create the test file

Will do :)

Thank you :) :clap:

Was this page helpful?
0 / 5 - 0 ratings