nextcloud / nextcloud/server

Entities without nullable non-null properties

Open
#29,631 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop enhancement integration
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

How to use GitHub
  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Is your feature request related to a problem? Please describe.

Entities for db table abstraction represent one row of a database table. However, they do not reflect that some properties are never null. You can create an instance of an entity class without specifying any value. Not even the primary key is enforced.

$account = new Account();
$account->getId(); // NULL

Describe the solution you'd like

Allow entities to have a constructor with arguments that map directly to object properties.

class Account extends Entity {

	/** @var string */
	protected $userId;

	public function __construct(int $id, string $userId) {
		$this->id = $id;
		$this->userId = $userId;
	}
}

$account = new Account(123, 'admin');
$account->getId(); // Impossible to get NULL here

Describe alternatives you've considered

n/a

Additional context

n/a


@miaulalala as discussed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue concerns PHP Entity classes representing database rows, but it names no files, tests, or entry points. Start by locating the Entity abstraction and existing entity construction patterns. Done means entities can accept constructor arguments mapped to their properties so required values, including the primary key, cannot remain null.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.