Closed Method em()->create return hint incorrectly

truonglv

Well-known member
Licensed customer
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.
 
Automated triage: Not a bug

Thank you for reporting this issue. This hint has since been corrected: in current 2.3 releases the method is documented as always returning an entity, never null. If you still see a wrong hint on the current version, please open a new report with details.

This is an automated assessment. A member of staff may review and update it.
 
@Chris D the bot has been resolving a bunch of these XF2.2 bugs as a "not a bug" when they have been fixed in XF2.3
FWIW the distinction as far as the bot is concerned is that it can see the issue has been resolved, but it cannot find a relevant bug report to call it a duplicate. So either there may have been a bug report and it couldn't locate it, or it was something we managed to fix along the way.

It will only call out a duplicate if it can find that original bug report, and I think that's reasonable.

A new status named "Stale" was something I considered but for all intents and purposes "Not a bug" is fine in this case and I'd rather duplicates be accompanied by the relevant bug report if one exists.

It's a short term thing though. The Bug Bot is here to stay and issues will be triaged as they come in rather than a brief look by staff and triaged in * waves hands * the future. Anomalies such as this shouldn't be a long term issue.

It may still happen if someone on an older version reports a bug that was already fixed and the closing bug can't be located, I suppose, but on balance I still think "Not a bug" is fine for those.
 
Also, to be clear, I appreciate "Fixed" is another valid option here but we tend to prefer "Fixed" to lead to the bug report that actually led to the fix being made. We might not have always been consistent with that but the Bug Bot will help us keep on track there :)
 
Back
Top Bottom