Skip to content

phpactor does not understand nullable return typehints #753

Closed
phpactor/code-builder
#11

Description

@einenlum

When implementing an interface, phpactor does not take in account the nullable return typehints.

Example 1, with scalar return typehint:

<?php

namespace App;

interface TestInterface1
{
    public function returnMaybeString(): ?string;
}

If I create a class Test1 that implements this interface and I ask phpactor to implement contracts:

<?php

namespace App;

class Test1 implements TestInterface1
{
    public function returnMaybeString(): string
    {
    }
}

Example 2 with a class return typehint:

<?php

namespace App;

interface TestInterface2
{
    public function returnMaybeFoo(): ?Foo;
}

If I ask to implement contracts:

<?php

namespace App;

class Test2 implements TestInterface2
{
    public function returnMaybeFoo(): Foo
    {
    }
}

The ? disappears in the implementations.

Activity

  1. dantleech commented on Apr 16, 2019

    @dantleech
    Collaborator

    Yeah, this is a missing feature :) This is the offending code:

    https://github.com/phpactor/code-transform/blob/master/lib/Adapter/WorseReflection/GenerateFromExisting/InterfaceFromExistingGenerator.php

    Not sure if the underlying code generation (https://github.com/phpactor/code-builder) supports nullable types yet.

  2. einenlum commented on May 20, 2019

    @einenlum
    CollaboratorAuthor

    Seems that the Type class in the worse-reflection repo should also be changed to allow nullable: https://github.com/phpactor/worse-reflection/blob/master/lib/Core/Type.php

  3. dantleech commented on Jun 14, 2019

    @dantleech
    Collaborator

    Made a (quick) attempt at this phpactor/worse-reflection#55 still needs parameter support.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions