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

Warning: count(): Parameter must be an array or an object that implements Countable #51

Closed
marlord opened this issue Feb 17, 2021 · 3 comments
Assignees
Labels

Comments

@marlord
Copy link

marlord commented Feb 17, 2021

Hey there,

I get the following errors when I enter any console commands in symfony 5.
In DebugCommand.php line 55:
Warning: count (): Parameters must be an array or an object that implements Countable

after debug I was able to determine that this is due to the contentful package.
In DebugCommand.php in line 55, "count" is used to check whether the entry of the "client-name" argument should be a mandatory field or an optional field. Php 7.4 doesn't like that :)
This happens if the contentful client is not initialized !!

    # vendor\contentful\contentful-bundle\src\Command\Delivery\DebugCommand.php::__construct (line 55)
        $this->addArgument(
            'client-name',
            \count($this->clients) > 1 ? InputArgument::REQUIRED : InputArgument::OPTIONAL,
            'The name of the client to use'
        );

Would be great if you could improve that. A solution could look like this:

        $this->addArgument(
            'client-name',
            !is_null($this->clients) && \count($this->clients) > 1 ? InputArgument::REQUIRED : InputArgument::OPTIONAL,
            'The name of the client to use'
        );

Thanks in advance
greetings

Env:
php 7.4.10
symfony 5.2
contentful/contentful-bundle 6.1.0

@Sebb767
Copy link
Collaborator

Sebb767 commented Feb 19, 2021

Hi marlord,

thanks for reporting this issue - and directly proposing a fix ;)

I'll integrate that in the next release. However, as I'm just taking over the maintenance of this repo at the moment, this might take a bit (I'd estimate ~2 weeks) - I hope this works for you. Thank you!

@Sebb767 Sebb767 self-assigned this Feb 19, 2021
@Sebb767 Sebb767 added the bug label Feb 19, 2021
@Sebb767 Sebb767 modified the milestone: 2.0.0 Feb 19, 2021
Sebb767 added a commit that referenced this issue Mar 26, 2021
This commit avoids a warning when the library tries to call count() on a
non-array object. The issue is avoided by checking whether the object is
an array beforehand.

See #51
@Sebb767
Copy link
Collaborator

Sebb767 commented Mar 26, 2021

Hi @marlord ,

I've just implemented a fix for this. Would you mind checking out the version dev-issue-51 to check whether the fix works for you before I merge it into master?

Thank you! :)

@Sebb767
Copy link
Collaborator

Sebb767 commented Jan 21, 2022

This is fixed with version 7.0

@Sebb767 Sebb767 closed this as completed Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants