Does Psalm not support {@inheritdoc} annotations right now? I could have sworn it did.
<?php
namespace App;
class TestSessionHandler implements \SessionHandlerInterface
{
/**
* {@inheritdoc}
*/
public function open($save_path, $name)
{
return true;
}
/**
* {@inheritdoc}
*/
public function close()
{
return true;
}
/**
* {@inheritdoc}
*/
public function read($session_id)
{
return 'a string';
}
/**
* {@inheritdoc}
*/
public function write($session_id, $session_data)
{
return true;
}
/**
* {@inheritdoc}
*/
public function destroy($session_id)
{
return true;
}
/**
* {@inheritdoc}
*/
public function gc($maxlifetime)
{
return true;
}
}
$ ./vendor/bin/psalm app/TestSessionHandler.php
ERROR: MethodSignatureMismatch - app/TestSessionHandler.php:9:26 - Argument 1 of App\TestSessionHandler::open has wrong type '', expecting 'string' as defined by SessionHandlerInterface::open
public function open($save_path, $name)
ERROR: MethodSignatureMismatch - app/TestSessionHandler.php:25:26 - Argument 1 of App\TestSessionHandler::read has wrong type '', expecting 'string' as defined by SessionHandlerInterface::read
public function read($session_id)
ERROR: MethodSignatureMismatch - app/TestSessionHandler.php:33:27 - Argument 1 of App\TestSessionHandler::write has wrong type '', expecting 'string' as defined by SessionHandlerInterface::write
public function write($session_id, $session_data)
ERROR: MethodSignatureMismatch - app/TestSessionHandler.php:41:29 - Argument 1 of App\TestSessionHandler::destroy has wrong type '', expecting 'string' as defined by SessionHandlerInterface::destroy
public function destroy($session_id)
ERROR: MethodSignatureMismatch - app/TestSessionHandler.php:49:24 - Argument 1 of App\TestSessionHandler::gc has wrong type '', expecting 'int' as defined by SessionHandlerInterface::gc
public function gc($maxlifetime)
Checks took 0.3144907951355 and used 17.287MB
It's implicit in Psalm's handling of methods. But it doesn't inherit builtin classes (which don't have docs). But it should, because adding those things causes errors and stuff.
Ah yeah that makes sense. Using PHPStorm, I forgot about that because clicking through to internal classes PHPStorm has those locally with docs.
This was fixed some time ago
It looks like an issue is reproducible again. @psalm-suppress MethodSignatureMismatch on method level didn't help too.
Psalm output (using commit ea20a2b):
ERROR: MethodSignatureMismatch - 9:26 - Argument 1 of App\TestSessionHandler::open has wrong type '', expecting 'string' as defined by SessionHandlerInterface::open
ERROR: MethodSignatureMismatch - 25:26 - Argument 1 of App\TestSessionHandler::read has wrong type '', expecting 'string' as defined by SessionHandlerInterface::read
ERROR: MethodSignatureMismatch - 33:27 - Argument 1 of App\TestSessionHandler::write has wrong type '', expecting 'string' as defined by SessionHandlerInterface::write
ERROR: MethodSignatureMismatch - 41:29 - Argument 1 of App\TestSessionHandler::destroy has wrong type '', expecting 'string' as defined by SessionHandlerInterface::destroy
ERROR: MethodSignatureMismatch - 49:24 - Argument 1 of App\TestSessionHandler::gc has wrong type '', expecting 'int' as defined by SessionHandlerInterface::gc
Somehow, it was unfixed: https://psalm.dev/r/7e417fd6f6 vs https://psalm.dev/r/b589d5ac3b
I found these snippets:
https://psalm.dev/r/7e417fd6f6
<?php
class Test {}
interface TestList extends \IteratorAggregate {
/** @psalm-return \Generator<array-key, Test, mixed, void> */
public function getIterator(): \Generator;
}
class ConcreteTestList implements TestList {
/** @psalm-var iterable<array-key, Test> */
private $tests;
/** @psalm-param iterable<array-key, Test> $tests */
public function __construct(iterable $tests) {
$this->tests = $tests;
}
/** {@inheritDoc} */
public function getIterator(): \Generator {
yield from $this->tests;
}
}
Psalm output (using commit 7639e17):
ERROR: LessSpecificImplementedReturnType - 20:36 - The inherited return type 'Generator<array-key, Test, mixed, void>' for TestList::getIterator is more specific than the implemented return type for ConcreteTestList::getiterator 'Generator'
https://psalm.dev/r/b589d5ac3b
<?php
class Test {}
interface TestList extends \IteratorAggregate {
/** @psalm-return \Generator<array-key, Test, mixed, void> */
public function getIterator(): \Generator;
}
class ConcreteTestList implements TestList {
/** @psalm-var iterable<array-key, Test> */
private $tests;
/** @psalm-param iterable<array-key, Test> $tests */
public function __construct(iterable $tests) {
$this->tests = $tests;
}
/**
* Here's the parrent's comment without inheritance.
*
* @psalm-return \Generator<array-key, Test, mixed, void>
*/
public function getIterator(): \Generator {
yield from $this->tests;
}
}
Psalm output (using commit 7639e17):
No issues!
This is essentially what's being addressed with this ticket (the inheritdoc is now always implicit). Hopefully I'll have time to fix it tomorrow.