Skip to content

Error: "Property has no typehint specified" although the type is specified in constructor #47

Description

@karser

Hello,
Strict-rules require all class properties to have typehint, although the ones that are specified in the constructor are perfectly inferred by the IDE.
Maybe we could do the property typehint optional if type of the property is specified in the constructor?

The code:

<?php declare(strict_types = 1);

class Foo
{
    private $bar;

    public function __construct(Bar $bar)
    {
        $this->bar = $bar;
    }
}

class Bar {}

Output:

+------------------------------------------------------+
| Line | test.php                                      |
+------------------------------------------------------+
| 5    | Property Foo::$bar has no typehint specified. |
+------------------------------------------------------+

 [ERROR] Found 1 error 

Expected output:
No errors

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions