Skip to content

Commit e24e09c

Browse files
author
Ashutosh Srivastva
authored
Merge pull request #9 from ashutoshwebkul/dev
Dev
2 parents 9ffb21c + 85b6897 commit e24e09c

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

Model/Generate/Model.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public function createApiClass($dir, $data, $columns)
124124
MethodGenerator::FLAG_INTERFACE,
125125
null,
126126
DocBlockGenerator::fromArray([
127-
'shortDescription' => 'set '.$fieldName,
127+
'shortDescription' => 'Set '.$fieldName,
128128
'longDescription' => null,
129129
'tags' => [
130-
new Tag\ParamTag($camelCase, [$column['type']]),
130+
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
131131
new Tag\ReturnTag([
132132
'datatype' => $nameSpace.'\\'.$data['name'].'Interface',
133133
]),
@@ -140,11 +140,11 @@ public function createApiClass($dir, $data, $columns)
140140
MethodGenerator::FLAG_INTERFACE,
141141
null,
142142
'docblock' => DocBlockGenerator::fromArray([
143-
'shortDescription' => 'get '.$fieldName,
143+
'shortDescription' => 'Get '.$fieldName,
144144
'longDescription' => null,
145145
'tags' => [
146146
new Tag\ReturnTag([
147-
'datatype' => $nameSpace.'\\'.$data['name'].'Interface',
147+
'datatype' => $this->helper->getReturnType($column['type']),
148148
]),
149149
],
150150
]),
@@ -280,10 +280,10 @@ public function createModelClass($dir, $data, $columns)
280280
MethodGenerator::FLAG_PUBLIC,
281281
'return $this->setData(self::'.strtoupper($field).', $'.$camelCase.');',
282282
DocBlockGenerator::fromArray([
283-
'shortDescription' => 'set '.$fieldName,
283+
'shortDescription' => 'Set '.$fieldName,
284284
'longDescription' => null,
285285
'tags' => [
286-
new Tag\ParamTag($camelCase, [$column['type']]),
286+
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
287287
new Tag\ReturnTag([
288288
'datatype' => $nameSpace.'\\'.$data['name'].'Interface',
289289
]),
@@ -296,11 +296,11 @@ public function createModelClass($dir, $data, $columns)
296296
MethodGenerator::FLAG_PUBLIC,
297297
'return parent::getData(self::'.strtoupper($field).');',
298298
'docblock' => DocBlockGenerator::fromArray([
299-
'shortDescription' => 'get '.$fieldName,
299+
'shortDescription' => 'Get '.$fieldName,
300300
'longDescription' => null,
301301
'tags' => [
302302
new Tag\ReturnTag([
303-
'datatype' => $nameSpace.'\\'.$data['name'].'Interface',
303+
'datatype' => $this->helper->getReturnType($column['type']),
304304
]),
305305
],
306306
]),

Model/Helper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ public function getHeadDocBlock($moduleName)
3838
]);
3939
}
4040

41+
/**
42+
* Map valid database types
43+
*
44+
* @param string $type
45+
* @return string
46+
*/
47+
public function getReturnType($type = 'default')
48+
{
49+
$validTypes = [
50+
'varchar' => 'string',
51+
'text' => 'string',
52+
'smallint' => 'int',
53+
'int' => 'int',
54+
'integer' => 'int',
55+
'decimal' => 'float',
56+
'boolean' => 'bool'
57+
];
58+
return isset($validTypes[$type]) ? $validTypes[$type] : 'string';
59+
}
60+
4161
public static function createDirectory($dirPath, $permission = 0777)
4262
{
4363
if (!is_dir($dirPath)) {

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
``` composer require webkul/code-generator ```
66

7-
``` php -f bin/magento setup:update ```
7+
``` php -f bin/magento setup:upgrade ```
88

99
# Usage
1010

1111
- To create new Module
1212

13-
``` php bin/magento generate:code Module_Name type=new-module ```
13+
``` php bin/magento generate:code Module_Name --type=new-module ```
1414

1515
- To create models
1616

0 commit comments

Comments
 (0)