diff --git a/src/Utils/AbstractBeanPropertyDescriptor.php b/src/Utils/AbstractBeanPropertyDescriptor.php index 9a377df0..22ab42ef 100644 --- a/src/Utils/AbstractBeanPropertyDescriptor.php +++ b/src/Utils/AbstractBeanPropertyDescriptor.php @@ -48,7 +48,14 @@ public function useAlternativeName() * * @return null|string */ - abstract public function getClassName(); + abstract public function getClassName(): ?string; + + /** + * Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....) + * + * @return string + */ + abstract public function getPhpType(): string; /** * Returns the param annotation for this property (useful for constructor). diff --git a/src/Utils/ObjectBeanPropertyDescriptor.php b/src/Utils/ObjectBeanPropertyDescriptor.php index 9e71a49a..7241e02b 100644 --- a/src/Utils/ObjectBeanPropertyDescriptor.php +++ b/src/Utils/ObjectBeanPropertyDescriptor.php @@ -51,11 +51,22 @@ public function getForeignKey() * * @return null|string */ - public function getClassName() + public function getClassName(): ?string { return $this->namingStrategy->getBeanClassName($this->foreignKey->getForeignTableName()); } + /** + * Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....) + * + * @return string + */ + public function getPhpType(): string + { + return $this->getClassName(); + } + + /** * Returns the param annotation for this property (useful for constructor). * diff --git a/src/Utils/ScalarBeanPropertyDescriptor.php b/src/Utils/ScalarBeanPropertyDescriptor.php index 975b495e..23ca0c86 100644 --- a/src/Utils/ScalarBeanPropertyDescriptor.php +++ b/src/Utils/ScalarBeanPropertyDescriptor.php @@ -46,8 +46,7 @@ public function getForeignKey() */ public function getParamAnnotation() { - $className = $this->getClassName(); - $paramType = $className ?: TDBMDaoGenerator::dbalTypeToPhpType($this->column->getType()); + $paramType = $this->getPhpType(); $str = ' * @param %s %s'; @@ -59,9 +58,20 @@ public function getParamAnnotation() * * @return null|string */ - public function getClassName() + public function getClassName(): ?string { - return; + return null; + } + + /** + * Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....) + * + * @return string + */ + public function getPhpType(): string + { + $type = $this->column->getType(); + return TDBMDaoGenerator::dbalTypeToPhpType($type); } /** @@ -121,8 +131,7 @@ public function isPrimaryKey() */ public function getGetterSetterCode() { - $type = $this->column->getType(); - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); + $normalizedType = $this->getPhpType(); $columnGetterName = $this->getGetterName(); $columnSetterName = $this->getSetterName(); @@ -183,8 +192,7 @@ public function %s(%s%s $%s) : void */ public function getJsonSerializeCode() { - $type = $this->column->getType(); - $normalizedType = TDBMDaoGenerator::dbalTypeToPhpType($type); + $normalizedType = $this->getPhpType(); if ($normalizedType == '\\DateTimeInterface') { return ' $array['.var_export($this->namingStrategy->getJsonProperty($this), true).'] = ($this->'.$this->getGetterName().'() === null) ? null : $this->'.$this->getGetterName()."()->format('c');\n"; @@ -202,4 +210,5 @@ public function getColumnName() { return $this->column->getName(); } + }