From cfe3f6d972faaf24837651eaf8ddc3cf1101b157 Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Thu, 19 Dec 2019 14:46:29 +0100 Subject: [PATCH] Models output now matches php_cs_fixer output --- .../templates/Models/basemodel.php.twig | 159 ++++++++---------- .../templates/_overwrite_warning.twig | 25 ++- 2 files changed, 84 insertions(+), 100 deletions(-) diff --git a/src/Generator/templates/Models/basemodel.php.twig b/src/Generator/templates/Models/basemodel.php.twig index bb2a84b..8319353 100755 --- a/src/Generator/templates/Models/basemodel.php.twig +++ b/src/Generator/templates/Models/basemodel.php.twig @@ -1,36 +1,33 @@ get(Services\{{ column.getModel.getClassName }}Service::class); {% endif %} {% endfor %} - - $properties = [ + return [ {% for column in columns %} self::FIELD_{{ column.getFieldSanitised|upper }} => [ - 'type' => self::TYPE_{{ column.getFieldSanitised|upper }}, + 'type' => self::TYPE_{{ column.getFieldSanitised|upper }}, {% if column.getMaxLength > 0 %} - 'length' => {{ column.getMaxLength }}, + 'length' => {{ column.getMaxLength }}, {% endif %} {% if column.getDbType == 'enum' and column.getPhpType == 'string' %} - 'options' => [ + 'options' => [ {% for permittedValue in column.getPermittedValues %} - '{{ permittedValue }}', + '{{ permittedValue }}', {% endfor %} - ], + ], {% if column.getDefaultvalue %} - 'default' => '{{ column.getDefaultValue() }}', + 'default' => '{{ column.getDefaultValue() }}', {% endif %} {% endif %} {% if column.hasRelatedObjects %} - 'remoteOptionsLoader' => ${{ column.getField|replace({"Id":"s"}) }}Service->getAll(), + 'remoteOptionsLoader' => ${{ column.getField|replace({"Id":"s"}) }}Service->getAll(), {% endif %} - ], + ], {% endfor %} ]; - return $properties; } {% for column in columns %} /** * @return {{ column.phptype }} */ - public function get{{ column.getPropertyFunction }}() {% if column.phptype %}: ?{{ column.phptype }}{% endif %} + public function get{{ column.getPropertyFunction }}(){{ column.phptype ? ": ?#{column.phptype}" }} { return $this->{{ column.getFieldSanitised }}; } /** * @param {{ column.phptype }} ${{ column.getFieldSanitised }} - * @return {{ class_name }}Model + * + * @return self */ - public function set{{ column.getPropertyFunction }}({{ column.phptype }} ${{ column.getFieldSanitised }} = null) : {{ class_name }}Model + public function set{{ column.getPropertyFunction }}({{ column.phptype }} ${{ column.getFieldSanitised }} = null): self { $this->{{ column.getFieldSanitised }} = ${{ column.getFieldSanitised }}; + return $this; } {% endfor %} - - /***************************************************** - * "Referenced To" Remote Constraint Object Fetchers * - *****************************************************/ {% for related_object in related_objects %} /** - * @return null|Models\{{ related_object.getRemoteClass }}Model - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ {% if related_object.getRemoteFunctionName != class_name %} - public function fetch{{ related_object.getRemoteFunctionName|singularize|transform_camel_to_studly }}Object() : ?Models\{{ related_object.getRemoteClass }}Model + public function fetch{{ related_object.getRemoteFunctionName|singularize|transform_camel_to_studly }}Object(): ?Models\{{ related_object.getRemoteClass }}Model {% else %} - public function fetchRelated{{ related_object.getRemoteFunctionName|singularize|transform_camel_to_studly }}Object() : ?Models\{{ related_object.getRemoteClass }}Model + public function fetchRelated{{ related_object.getRemoteFunctionName|singularize|transform_camel_to_studly }}Object(): ?Models\{{ related_object.getRemoteClass }}Model {% endif %} { /** @var ${{ related_object.getRemoteClass }}Service Services\{{ related_object.getRemoteClass }}Service */ @@ -153,31 +147,26 @@ abstract class Base{{ class_name }}Model {% endfor %} {% if remote_objects %} - /***************************************************** - * "Referenced By" Remote Constraint Object Fetchers * - *****************************************************/ {% for remote_object in remote_objects %} {% if remote_object.getLocalClass != class_name %} {% if remote_object.getLocalFunctionName|singularize|transform_camel_to_studly not in existingMethods %} {% set existingMethods = existingMethods|merge([ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly ]) %} /** - * Fetch a singular {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that references this {{ class_name }}Model. + * Fetch a singular {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that references this Models\{{ class_name }}Model. * * @param $orderBy string Column to order by. Recommended to use the Constants in Models\{{ remote_object.getLocalClass }}Model:: * @param $orderDirection string Either "DESC" or "ASC". Recommend using Select::ORDER_ASCENDING or Select::ORDER_DESCENDING * - * @return null|Models\{{ remote_object.getLocalClass }}Model - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function fetch{{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }}Object( {% if remote_object.local_model_key != 'id' %} $orderBy = null, $orderDirection='ASC' {% endif %} - ) : ?Models\{{ remote_object.getLocalClass }}Model { + ): ?Models\{{ remote_object.getLocalClass }}Model { /** @var ${{ remote_object.getLocalVariable }}Service Services\{{ remote_object.getLocalClass }}Service */ ${{ remote_object.getLocalVariable }}Service = App::Container()->get(Services\{{ remote_object.getLocalClass }}Service::class); {% if remote_object.local_model_key == 'id' %} @@ -188,7 +177,7 @@ abstract class Base{{ class_name }}Model } /** - * Fetch all matching {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that reference this {{ class_name }}Model. + * Fetch all matching {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that reference this Models\{{ class_name }}Model. * * @param $limit int Number to fetch maximum * @param $orderBy string Column to order by. Recommended to use the Constants in Models\{{ remote_object.getLocalClass }}Model:: @@ -196,14 +185,14 @@ abstract class Base{{ class_name }}Model * * @return Models\{{ remote_object.getLocalClass }}Model[] * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function fetch{{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }}Objects( int $limit = null, string $orderBy = null, string $orderDirection='ASC' - ) : ?array { + ): ?array { /** @var ${{ remote_object.getLocalVariable }}Service Services\{{ remote_object.getLocalClass }}Service */ ${{ remote_object.getLocalVariable }}Service = App::Container()->get(Services\{{ remote_object.getLocalClass }}Service::class); {% if remote_object.local_model_key == 'id' %} @@ -214,14 +203,13 @@ abstract class Base{{ class_name }}Model } /** - * Count the number of matching {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that reference this {{ class_name }}Model. + * Count the number of matching {{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }} that reference this Models\{{ class_name }}Model. + * Returns the number of objects found. * - * @return int Number of objects found. - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function count{{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }}Objects() : int { + public function count{{ remote_object.getLocalFunctionName|singularize|transform_camel_to_studly }}Objects(): int { /** @var ${{ remote_object.getLocalVariable }}Service Services\{{ remote_object.getLocalClass }}Service */ ${{ remote_object.getLocalVariable }}Service = App::Container()->get(Services\{{ remote_object.getLocalClass }}Service::class); {% if remote_object.local_model_key == 'id' %} @@ -234,44 +222,41 @@ abstract class Base{{ class_name }}Model {% endif %} {% endfor %} {% endif %} - /** - * @return {{ class_name }}Model - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function save() + public function save(): Models\{{ class_name }}Model { - /** @var $tableGateway TableGateways\{{ class_name }}TableGateway */ + /** @var TableGateways\{{ class_name }}TableGateway $tableGateway */ $tableGateway = App::Container()->get(TableGateways\{{ class_name }}TableGateway::class); + return $tableGateway->save($this); } /** * Destroy the current record. + * Returns the number of affected rows. * - * @return int Number of affected rows. - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function destroy() : int + public function destroy(): int { - /** @var $tableGateway TableGateways\{{ class_name }}TableGateway */ + /** @var TableGateways\{{ class_name }}TableGateway $tableGateway */ $tableGateway = App::Container()->get(TableGateways\{{ class_name }}TableGateway::class); + return $tableGateway->delete($this->getPrimaryKeys()); } /** * Destroy the current record, and any dependencies upon it, recursively. + * Returns the number of affected rows. * - * @return int Number of affected models. - * - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function destroyThoroughly() : int + public function destroyThoroughly(): int { {% if remote_objects.length > 0 %} $countOfThingsDestroyed = 0; @@ -296,12 +281,12 @@ abstract class Base{{ class_name }}Model {% endif %} } - /** * Provides an array of all properties in this model. - * @return array + * + * @return string[] */ - public function getListOfProperties() + public function getListOfProperties(): array { return [ {% for column in columns %} @@ -309,4 +294,4 @@ abstract class Base{{ class_name }}Model {% endfor %} ]; } -} \ No newline at end of file +} diff --git a/src/Generator/templates/_overwrite_warning.twig b/src/Generator/templates/_overwrite_warning.twig index eedcc0a..a13b42d 100755 --- a/src/Generator/templates/_overwrite_warning.twig +++ b/src/Generator/templates/_overwrite_warning.twig @@ -1,13 +1,12 @@ -/******************************************************** - * ___ __ * - * / _ \___ ____ ___ ____ ____/ / * - * / // / _ `/ _ \/ _ `/ -_) __/_/ * - * /____/\_,_/_//_/\_, /\__/_/ (_) * - * /___/ * - * * - * Anything in this file is prone to being overwritten! * - * * - * This file was programatically generated. To modify * - * this classes behaviours, do so in the class that * - * extends this, or modify the Zenderator Template! * - ********************************************************/ \ No newline at end of file +/** ___ __ + * / _ \___ ____ ___ ____ ____/ / + * / // / _ `/ _ \/ _ `/ -_) __/_/ + * /____/\_,_/_//_/\_, /\__/_/ (_) + * /___/. + * + * Anything in this file is prone to being overwritten! + * + * This file was programatically generated. To modify + * this classes behaviours, do so in the class that + * extends this, or modify the Zenderator Template! + */ \ No newline at end of file