Method em()->create return hint incorrectly

truonglv

Well-known member
Affected version
2.3.0
PHP:
/**
 * @template T of Entity
 *
 * @param class-string<T> $shortName
 *
 * @return T|null
 */
public function create($shortName)
{
   return $this->instantiateEntity($shortName);
}

I though that method never return null in any case.
 
It can return null, in the case an addon doesn't have any primary keys defined.

PHP:
		/** @var Entity $entity */
		$entity = new $className($this, $structure, $values, $relations);
		if ($values)
		{
			$class = get_class($entity);
			$keys = $entity->getIdentifierValues();
			if (!$keys)
			{
				// must contain nulls, so not a valid entity
				if (!($options & self::INSTANTIATE_ALLOW_INVALID))
				{
					throw new \LogicException("Cannot instantiate $shortName ($className) without primary key values");
				}

				return null;
			}

Honestly that being made a hard failure wouldn't be the worst thing.
 
Back
Top Bottom