Skip to content

CountOnNullRector Converting Known Array #6961

@MGatner

Description

@MGatner

Bug Report

OS: Ubuntu 20.04
PHP: 7.4.11
Rector: dev-main
Install: Global

Rector keeps trying to check is_countable() on what is definitely an array:

-            log_message('debug', 'Merged ' . count($chunks) . ' chunks to ' . $path);
+            log_message('debug', 'Merged ' . (is_countable($chunks) ? count($chunks) : 0) . ' chunks to ' . $path);

Minimal PHP Code Causing Issue

I've tried to recreate this. I don't know if it is an issue with me, different Rector versions, or the actual code and config. Here's my latest (failed) attempt: https://getrector.org/demo/1ec7c946-5f44-6b9c-80b3-dfab2a5e5b19

This is happening "live" here: https://github.com/tattersoftware/codeigniter4-files/tree/devkit
Here is the code: https://github.com/tattersoftware/codeigniter4-files/blob/31d4fbea62773d23ec2fde7094b0a495bd3cf1da/src/Controllers/Files.php#L375-L389
And proof that get_filenames() always returns an array: https://github.com/codeigniter4/CodeIgniter4/blob/203d038536817f28075d897ce373cece493a5a50/system/Helpers/filesystem_helper.php#L198

Expected Behaviour

Rector should skip this line since $chunks is always an array.
Screen Shot 2022-01-23 at 4 36 32 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions