DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
75 stars 9 forks source link

Improved `implements abstract` #575

Closed ging-dev closed 3 weeks ago

ging-dev commented 3 weeks ago
<?php

interface A {

}

interface ITest {
    /**
     * Desc
     * @template T of A
     * @param class-string<T>|class-string[]|0|1|'other' $class
     * @return void
     */
    public function test(string|array $class);
}

class Test implements ITest {

    /**
     * Desc
     * @template T
     *
     * @param class-string<T>|class-string[]|int|string $class
     * @return void
     */
    public function test(array|string $class) {
        // The comments of ITest::test() and Test::test() are different.
    }
}

Instead of trying to create docblocks similar to interface class, I thought we could use something like @inheritDoc:

<?php

interface A {

}

interface ITest {
    /**
     * Desc
     * @template T of A
     * @param class-string<T>|class-string[]|0|1|'other' $class
     * @return void
     */
    public function test(string|array $class);
}

class Test implements ITest {
    /**
     * @inheritDoc
     */
    public function test(array|string $class) {
        // Having problems because the parameter does not use the type provided by docblock, but uses the native type hint
    }
}
jakubmisek commented 3 weeks ago

I agree, good point.

This was implemented a long time ago when there were no generics.