Skip to content

Commit 9332338

Browse files
committed
Removed converting for string
1 parent 7ca38ac commit 9332338

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

resources/fileTemplates/internal/Magento Data Model.php.ft

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has
5555
#end
5656
public function get$propertyUpperCamel(): ?$propertyType
5757
{
58+
#set($propertyCast = "#if($propertyType != 'string')($propertyType)#{else}#end")
5859
return $this->getData(self::$propertyUpperSnake) === null ? null
59-
: ($propertyType) $this->getData(self::$propertyUpperSnake);
60+
: $propertyCast $this->getData(self::$propertyUpperSnake);
6061
}
6162

6263
#if ($hasInterface)

testData/actions/generation/generator/DataModelGenerator/generateDataModel/Sample.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@
88

99
class Sample extends DataObject implements SampleInterface
1010
{
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+
1128
/**
1229
* @inheritDoc
1330
*/
1431
public function getSampleProperty(): ?string
1532
{
1633
return $this->getData(self::SAMPLE_PROPERTY) === null ? null
17-
: (string)$this->getData(self::SAMPLE_PROPERTY);
34+
: $this->getData(self::SAMPLE_PROPERTY);
1835
}
1936

2037
/**

testData/actions/generation/generator/DataModelGenerator/generateDataModelWithoutInterface/Sample.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,32 @@ class Sample extends DataObject
1010
/**
1111
* String constants for property names
1212
*/
13+
const ID_PROPERTY = "id_property";
1314
const SAMPLE_PROPERTY = "sample_property";
1415

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+
1539
/**
1640
* Getter for SampleProperty.
1741
*
@@ -20,7 +44,7 @@ class Sample extends DataObject
2044
public function getSampleProperty(): ?string
2145
{
2246
return $this->getData(self::SAMPLE_PROPERTY) === null ? null
23-
: (string)$this->getData(self::SAMPLE_PROPERTY);
47+
: $this->getData(self::SAMPLE_PROPERTY);
2448
}
2549

2650
/**

testData/actions/generation/generator/DataModelInterfaceGenerator/generateDataModelInterface/SampleInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,25 @@ interface SampleInterface
88
/**
99
* String constants for property names
1010
*/
11+
const ID_PROPERTY = "id_property";
1112
const SAMPLE_PROPERTY = "sample_property";
1213

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+
1330
/**
1431
* Getter for SampleProperty.
1532
*

tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGeneratorTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public void testGenerateDataModel() {
2222
"Foo_Bar",
2323
"Foo\\Bar\\Model\\Data\\Sample",
2424
"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",
2627
true
2728
);
2829
final DataModelGenerator generator = new DataModelGenerator(
@@ -50,7 +51,8 @@ public void testGenerateDataModelWithoutInterface() {
5051
"Foo_Bar",
5152
"Foo\\Bar\\Model\\Data\\Sample",
5253
"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",
5456
false
5557
);
5658
final DataModelGenerator generator = new DataModelGenerator(

tests/com/magento/idea/magento2plugin/actions/generation/generator/DataModelInterfaceGeneratorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public void testGenerateDataModelInterface() {
2121
"SampleInterface",
2222
"Foo_Bar",
2323
"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"
2526
);
2627
final DataModelInterfaceGenerator generator = new DataModelInterfaceGenerator(
2728
project, interfaceData

0 commit comments

Comments
 (0)