Skip to content

fetchSingle returning mixed, how to approach? #31

Open
@dakorpar

Description

@dakorpar

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();
	}

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