phpstan-dibi icon indicating copy to clipboard operation
phpstan-dibi copied to clipboard

fetchSingle returning mixed, how to approach?

Open dakorpar opened this issue 3 years ago • 0 comments

How to properly solve those? I know it will allways be ?int, but since fetchSingle is marked as returning mixed I can't solve this. I wouldn't want to just skip those checks....

	public function getIdByKey(string $key): ?int
	{
		return $this->db->select('id')->from($this->table)->where('%n = %s', 'key', $key)->fetchSingle();
	}

ofcours, here is integer in some other query will be something else...

only thing I think off as correct would maybe be:

	public function getIdByKey(string $key): ?int
	{
		/** @var int|null $id */
		$id = $this->db->select('id')->from($this->table)->where('%n = %s', 'key', $key)->fetchSingle();
	}

dakorpar avatar Jul 07 '22 09:07 dakorpar