From a27c10daa66a38c453393fcaf0c545d60f041f30 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 14 Nov 2019 19:57:43 +0100 Subject: Make isXXX available for bool properties only Signed-off-by: Daniel Kesselberg --- lib/public/AppFramework/Db/Entity.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/public/AppFramework/Db') diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index 091b90257b4..8bd537211fc 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -87,7 +87,7 @@ abstract class Entity { return $this->_fieldTypes; } - + /** * Marks the entity as clean needed for setting the id after the insertion * @since 7.0.0 @@ -115,7 +115,7 @@ abstract class Entity { $this->$name = $args[0]; } else { - throw new \BadFunctionCallException($name . + throw new \BadFunctionCallException($name . ' is not a valid attribute'); } } @@ -129,7 +129,7 @@ abstract class Entity { if(property_exists($this, $name)){ return $this->$name; } else { - throw new \BadFunctionCallException($name . + throw new \BadFunctionCallException($name . ' is not a valid attribute'); } } @@ -137,7 +137,7 @@ abstract class Entity { /** * Each time a setter is called, push the part after set - * into an array: for instance setId will save Id in the + * into an array: for instance setId will save Id in the * updated fields array so it can be easily used to create the * getter method * @since 7.0.0 @@ -147,7 +147,7 @@ abstract class Entity { $this->setter(lcfirst(substr($methodName, 3)), $args); } elseif (strpos($methodName, 'get') === 0) { return $this->getter(lcfirst(substr($methodName, 3))); - } elseif (strpos($methodName, 'is') === 0) { + } elseif ($this->isGetterForBoolProperty($methodName)) { return $this->getter(lcfirst(substr($methodName, 2))); } else { throw new \BadFunctionCallException($methodName . @@ -156,6 +156,18 @@ abstract class Entity { } + /** + * @param string $methodName + * @return bool + * @since 18.0.0 + */ + protected function isGetterForBoolProperty(string $methodName): bool { + if (strpos($methodName, 'is') === 0) { + $fieldName = lcfirst(substr($methodName, 2)); + return isset($this->_fieldTypes[$fieldName]) && strpos($this->_fieldTypes[$fieldName], 'bool') === 0; + } + return false; + } /** * Mark am attribute as updated @@ -168,7 +180,7 @@ abstract class Entity { /** - * Transform a database columnname to a property + * Transform a database columnname to a property * @param string $columnName the name of the column * @return string the property name * @since 7.0.0 -- cgit v1.2.3