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

[4.x]: wrong type annotation in generated CustomFieldBehavior #14421

Closed
d--j opened this issue Feb 17, 2024 · 2 comments
Closed

[4.x]: wrong type annotation in generated CustomFieldBehavior #14421

d--j opened this issue Feb 17, 2024 · 2 comments

Comments

@d--j
Copy link
Contributor

d--j commented Feb 17, 2024

What happened?

Description

/**
* @var string[] List of supported field handles.
*/
public static $fieldHandles = [

the type annotation string[] is wrong here. What gets generated is a bool[] or more specifically an array<string,bool>:

    public static $fieldHandles = [
        'field1' => true,
        'field2' => true,
        'field3' => true,
    ];

PHPStan (level 5) trips over this.

A stub file like this

<?php

namespace craft\behaviors;

class CustomFieldBehavior
{
    /**
     * @var array<string,bool>
     */
    public static $fieldHandles = [];
}

fixes this but you might just want to use the correct type annotation in the first place so this stub is not necessary anymore.

Craft CMS version

4.7.3

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for pointing that out! Fixed for the next release.

@brandonkelly
Copy link
Member

Craft 4.7.4 is out with that fix. Note you’ll need to run php craft clear-caches/compiled-classes to regenerate CustomFieldBehavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants