Skip to content

Commit

Permalink
Improve typing in Entity.php
Browse files Browse the repository at this point in the history
Removing @method in Entity brings even more errors.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 20, 2023
1 parent 87ebf28 commit e91457d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@
use function substr;

/**
* @method integer getId()
* @method void setId(integer $id)
* @method int getId()
* @method void setId(int $id)
* @since 7.0.0
* @psalm-consistent-constructor
*/
abstract class Entity {
/**
* @var int
*/
public $id;

private $_updatedFields = [];
private $_fieldTypes = ['id' => 'integer'];

private array $_updatedFields = [];
private array $_fieldTypes = ['id' => 'integer'];

/**
* Simple alternative constructor for building entities from a request
* @param array $params the array which was obtained via $this->params('key')
* in the controller
* @return Entity
* @since 7.0.0
*/
public static function fromParams(array $params) {
public static function fromParams(array $params): static {
$instance = new static();

foreach ($params as $key => $value) {
Expand All @@ -64,7 +66,7 @@ public static function fromParams(array $params) {
* @param array $row the row to map onto the entity
* @since 7.0.0
*/
public static function fromRow(array $row) {
public static function fromRow(array $row): static {
$instance = new static();

foreach ($row as $key => $value) {
Expand Down Expand Up @@ -100,7 +102,7 @@ public function resetUpdatedFields() {
* Generic setter for properties
* @since 7.0.0
*/
protected function setter($name, $args) {
protected function setter(string $name, array $args): void {
// setters should only work for existing attributes
if (property_exists($this, $name)) {
if ($this->$name === $args[0]) {
Expand Down Expand Up @@ -142,7 +144,7 @@ protected function setter($name, $args) {
* Generic getter for properties
* @since 7.0.0
*/
protected function getter($name) {
protected function getter(string $name): mixed {
// getters should only work for existing attributes
if (property_exists($this, $name)) {
return $this->$name;
Expand All @@ -160,7 +162,7 @@ protected function getter($name) {
* getter method
* @since 7.0.0
*/
public function __call($methodName, $args) {
public function __call(string $methodName, array $args) {
if (strpos($methodName, 'set') === 0) {
$this->setter(lcfirst(substr($methodName, 3)), $args);
} elseif (strpos($methodName, 'get') === 0) {
Expand Down Expand Up @@ -191,7 +193,7 @@ protected function isGetterForBoolProperty(string $methodName): bool {
* @param string $attribute the name of the attribute
* @since 7.0.0
*/
protected function markFieldUpdated($attribute) {
protected function markFieldUpdated(string $attribute): void {
$this->_updatedFields[$attribute] = true;
}

Expand Down

0 comments on commit e91457d

Please sign in to comment.