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
Merged

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

merged 13 commits into from
Aug 22, 2019

Conversation

terabytesoftw
Copy link
Member

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

@terabytesoftw terabytesoftw marked this pull request as ready for review August 19, 2019 18:43
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
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

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

@terabytesoftw
Copy link
Member Author

terabytesoftw 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
Copy link
Member Author

terabytesoftw 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.

@samdark samdark added the status:code review The pull request needs review. label Aug 20, 2019
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
@samdark samdark added status:under development Someone is working on a pull request. and removed status:code review The pull request needs review. labels Aug 21, 2019
@terabytesoftw
Copy link
Member Author

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
Copy link
Member Author

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 samdark removed the status:under development Someone is working on a pull request. label Aug 21, 2019
@samdark
Copy link
Member

samdark commented Aug 21, 2019

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

@terabytesoftw
Copy link
Member Author

terabytesoftw 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
Copy link
Member

samdark 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
Copy link
Member Author

Ok then for my part everything is ready too.

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

samdark 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants