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) {
* @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) {
* 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]) {
* 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;
* 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) {
* @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;
}