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

add functions [filterPath(), normalizeOptions(), copyDirectory()] #5

Merged
merged 13 commits into from Aug 22, 2019

Conversation

@terabytesoftw
Copy link
Contributor

commented Aug 19, 2019

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Tests pass? ✔️
Fixed issues (#4)

@terabytesoftw terabytesoftw marked this pull request as ready for review Aug 19, 2019

src/FileHelper.php Outdated Show resolved Hide resolved
src/FileHelper.php Outdated Show resolved Hide resolved
src/FileHelper.php Outdated Show resolved Hide resolved
src/FileHelper.php Outdated Show resolved Hide resolved
src/FileHelper.php Outdated Show resolved Hide resolved
@samdark
Copy link
Member

left a comment

Looks OK to me now. Do you plan more changes?

@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2019

We will review all possible use cases that we can have with the copyDirectory () and filterPath () from the AssetManager and based on those uses we will debug the filtering function well and know exactly what it returns for each case, Please do not merge.

@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2019

Please check the code and tests, add 3 cases of only and except, and it works perfect, remove the filter option within filterPath, it had no use there, filterPath is only used for copyDirectory(), only and except are sufficient to filter in copyDirectory().

I think that using well only and except you can delete beforeCopy() and afterCopy(), it's just an opinion.

src/FileHelper.php Outdated Show resolved Hide resolved
src/FileHelper.php Outdated Show resolved Hide resolved
tests/FileHelperTest.php Outdated Show resolved Hide resolved
tests/FileHelperTest.php Outdated Show resolved Hide resolved
tests/FileHelperTest.php Outdated Show resolved Hide resolved
tests/FileHelperTest.php Outdated Show resolved Hide resolved
tests/FileHelperTest.php Show resolved Hide resolved
tests/FileHelperTest.php Show resolved Hide resolved
tests/FileHelperTest.php Show resolved Hide resolved
tests/FileHelperTest.php Show resolved Hide resolved
@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 21, 2019

On the other hand I have been trying to raise the coverage to the tests but for example:

        if (!is_dir($directory)) { // double check if it does not exist
            return;
        }

        if (!empty($options['traverseSymlinks']) || !is_link($directory)) {
            if (!($handle = opendir($directory))) { // double check if it does not exist
                return; // It will never run.
            }
            while (($file = readdir($handle)) !== false) {
                if ($file === '.' || $file === '..') {
                    continue;
                }
                $path = $directory . '/' . $file;
                if (is_dir($path)) {
                    self::removeDirectory($path, $options);
                } else {
                    self::unlink($path);
                }
            }
            closedir($handle);
        }

Solution:

    if (!empty($options['traverseSymlinks']) || !is_link($directory)) {
        if (!($handle = @opendir($directory))) {  //@ avoid the exception https://www.php.net/manual/es/function.opendir.php
            return; // if it runs
        }

        while (($file = readdir($handle)) !== false) {
            if ($file === '.' || $file === '..') {
                continue;
            }
            $path = $directory . '/' . $file;
            if (is_dir($path)) {
                self::removeDirectory($path, $options);
            } else {
                self::unlink($path);
            }
        }

        closedir($handle);
    }
@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 21, 2019

Already fix all the phpdocs of FileHelperTest, and try to simplify and improve FileHelper, the Yii2 code works perfect, it is the only utility that copies, and allows filtering and excepting files in github.

@samdark

This comment has been minimized.

Copy link
Member

commented Aug 21, 2019

Seems to be OK now. Anything else you want in?

@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 21, 2019

Seems to be OK now. Anything else you want in?

What do you think of creating BaseFileHelper as in Yii2, or creating a new FilterHelper.php, and passing the filtering classes there and lowering the cognitive complexity of FileHelper.php that scrutinizer punishes heavily, those filters are only used by the copyDirectory() function.

@samdark

This comment has been minimized.

Copy link
Member

commented Aug 21, 2019

I see no need for Base*Helper.

those filters are only used by the copyDirectory () function

Then I see no reason to have them in a separate helper.

@terabytesoftw

This comment has been minimized.

Copy link
Contributor Author

commented Aug 21, 2019

Ok then for my part everything is ready too.

@samdark samdark merged commit 0bc9e73 into yiisoft:master Aug 22, 2019

2 checks passed

Scrutinizer Analysis: 34 updated code elements – Tests: passed
Details
Travis CI - Pull Request Build Passed
Details
@samdark

This comment has been minimized.

Copy link
Member

commented Aug 22, 2019

Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.