File tree Expand file tree Collapse file tree 6 files changed +68
-6
lines changed
resources/fileTemplates/internal
testData/actions/generation/generator
generateDataModelWithoutInterface
DataModelInterfaceGenerator/generateDataModelInterface
tests/com/magento/idea/magento2plugin/actions/generation/generator Expand file tree Collapse file tree 6 files changed +68
-6
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,9 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has
55
55
#end
56
56
public function get$propertyUpperCamel(): ?$propertyType
57
57
{
58
+ #set($propertyCast = "#if($propertyType != 'string')($propertyType)#{else}#end")
58
59
return $this->getData(self::$propertyUpperSnake) === null ? null
59
- : ($propertyType) $this->getData(self::$propertyUpperSnake);
60
+ : $propertyCast $this->getData(self::$propertyUpperSnake);
60
61
}
61
62
62
63
#if ($hasInterface)
Original file line number Diff line number Diff line change 8
8
9
9
class Sample extends DataObject implements SampleInterface
10
10
{
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ public function getIdProperty (): ?int
15
+ {
16
+ return $ this ->getData (self ::ID_PROPERTY ) === null ? null
17
+ : (int )$ this ->getData (self ::ID_PROPERTY );
18
+ }
19
+
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ public function setIdProperty (?int $ idProperty ): void
24
+ {
25
+ $ this ->setData (self ::ID_PROPERTY , $ idProperty );
26
+ }
27
+
11
28
/**
12
29
* @inheritDoc
13
30
*/
14
31
public function getSampleProperty (): ?string
15
32
{
16
33
return $ this ->getData (self ::SAMPLE_PROPERTY ) === null ? null
17
- : ( string ) $ this ->getData (self ::SAMPLE_PROPERTY );
34
+ : $ this ->getData (self ::SAMPLE_PROPERTY );
18
35
}
19
36
20
37
/**
Original file line number Diff line number Diff line change @@ -10,8 +10,32 @@ class Sample extends DataObject
10
10
/**
11
11
* String constants for property names
12
12
*/
13
+ const ID_PROPERTY = "id_property " ;
13
14
const SAMPLE_PROPERTY = "sample_property " ;
14
15
16
+ /**
17
+ * Getter for IdProperty.
18
+ *
19
+ * @return int|null
20
+ */
21
+ public function getIdProperty (): ?int
22
+ {
23
+ return $ this ->getData (self ::ID_PROPERTY ) === null ? null
24
+ : (int )$ this ->getData (self ::ID_PROPERTY );
25
+ }
26
+
27
+ /**
28
+ * Setter for IdProperty.
29
+ *
30
+ * @param int|null $idProperty
31
+ *
32
+ * @return void
33
+ */
34
+ public function setIdProperty (?int $ idProperty ): void
35
+ {
36
+ $ this ->setData (self ::ID_PROPERTY , $ idProperty );
37
+ }
38
+
15
39
/**
16
40
* Getter for SampleProperty.
17
41
*
@@ -20,7 +44,7 @@ class Sample extends DataObject
20
44
public function getSampleProperty (): ?string
21
45
{
22
46
return $ this ->getData (self ::SAMPLE_PROPERTY ) === null ? null
23
- : ( string ) $ this ->getData (self ::SAMPLE_PROPERTY );
47
+ : $ this ->getData (self ::SAMPLE_PROPERTY );
24
48
}
25
49
26
50
/**
Original file line number Diff line number Diff line change @@ -8,8 +8,25 @@ interface SampleInterface
8
8
/**
9
9
* String constants for property names
10
10
*/
11
+ const ID_PROPERTY = "id_property " ;
11
12
const SAMPLE_PROPERTY = "sample_property " ;
12
13
14
+ /**
15
+ * Getter for IdProperty.
16
+ *
17
+ * @return int|null
18
+ */
19
+ public function getIdProperty (): ?int ;
20
+
21
+ /**
22
+ * Setter for IdProperty.
23
+ *
24
+ * @param int|null $idProperty
25
+ *
26
+ * @return void
27
+ */
28
+ public function setIdProperty (?int $ idProperty ): void ;
29
+
13
30
/**
14
31
* Getter for SampleProperty.
15
32
*
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ public void testGenerateDataModel() {
22
22
"Foo_Bar" ,
23
23
"Foo\\ Bar\\ Model\\ Data\\ Sample" ,
24
24
"Foo\\ Bar\\ Api\\ Data\\ SampleInterface" ,
25
- "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
25
+ "ID_PROPERTY;id_property;int;IdProperty;idProperty," +
26
+ "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
26
27
true
27
28
);
28
29
final DataModelGenerator generator = new DataModelGenerator (
@@ -50,7 +51,8 @@ public void testGenerateDataModelWithoutInterface() {
50
51
"Foo_Bar" ,
51
52
"Foo\\ Bar\\ Model\\ Data\\ Sample" ,
52
53
"Foo\\ Bar\\ Api\\ Data\\ SampleInterface" ,
53
- "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
54
+ "ID_PROPERTY;id_property;int;IdProperty;idProperty," +
55
+ "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty" ,
54
56
false
55
57
);
56
58
final DataModelGenerator generator = new DataModelGenerator (
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ public void testGenerateDataModelInterface() {
21
21
"SampleInterface" ,
22
22
"Foo_Bar" ,
23
23
"Foo\\ Bar\\ Api\\ Data\\ SampleInterface" ,
24
- "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty"
24
+ "ID_PROPERTY;id_property;int;IdProperty;idProperty," +
25
+ "SAMPLE_PROPERTY;sample_property;string;SampleProperty;sampleProperty"
25
26
);
26
27
final DataModelInterfaceGenerator generator = new DataModelInterfaceGenerator (
27
28
project , interfaceData
You can’t perform that action at this time.
0 commit comments