Skip to content

Commit 0097124

Browse files
Code refactoring after CR
1 parent f5da382 commit 0097124

File tree

6 files changed

+11
-25
lines changed

6 files changed

+11
-25
lines changed

resources/fileTemplates/code/Magento Entity Data Mapper.php.ft

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use $use;
99
#end
1010

1111
/**
12-
* ${ENTITY_NAME} magento model collection to entity data transfer object array mapper.
12+
* Converts a collection of ${ENTITY_NAME} entities to an array of data transfer objects.
1313
*/
1414
class ${CLASS_NAME}
1515
{

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ private void generateWhitelistJsonFile(final @NotNull DbSchemaXmlData dbSchemaXm
10191019
*/
10201020
private void generateEntityDataMapperFile() {
10211021
final EntityDataMapperFile entityDataMapperFile =
1022-
EntityDataMapperFile.getInstance(getEntityName());
1022+
new EntityDataMapperFile(getEntityName());
10231023

10241024
final String namespace = entityDataMapperFile.getNamespace(getModuleName());
10251025
final String classFqn = entityDataMapperFile.getClassFqn(getModuleName());
@@ -1073,7 +1073,7 @@ private void generateModelGetListQueryFile() {
10731073
*/
10741074
private String getEntityDataMapperType() {
10751075
final EntityDataMapperFile entityDataMapperFile =
1076-
EntityDataMapperFile.getInstance(getEntityName());
1076+
new EntityDataMapperFile(getEntityName());
10771077

10781078
return entityDataMapperFile.getClassFqn(getModuleName());
10791079
}

src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public EntityDataMapperGenerator(
6262
this.entityDataMapperData = entityDataMapperData;
6363
this.project = project;
6464
this.checkFileAlreadyExists = checkFileAlreadyExists;
65-
entityDataMapperFile = EntityDataMapperFile
66-
.getInstance(entityDataMapperData.getEntityName());
65+
entityDataMapperFile = new EntityDataMapperFile(entityDataMapperData.getEntityName());
6766
fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project);
6867
directoryGenerator = DirectoryGenerator.getInstance();
6968
moduleIndex = ModuleIndex.getInstance(project);

src/com/magento/idea/magento2plugin/magento/files/EntityDataMapperFile.java

+5-17
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,23 @@
1111
import com.magento.idea.magento2plugin.magento.packages.Package;
1212
import org.jetbrains.annotations.NotNull;
1313

14-
public final class EntityDataMapperFile implements ModuleFileInterface {
14+
public class EntityDataMapperFile implements ModuleFileInterface {
1515

1616
public static final String CLASS_NAME_SUFFIX = "DataMapper";
1717
public static final String FILE_EXTENSION = "php";
1818
public static final String TEMPLATE = "Magento Entity Data Mapper";
1919
private static final String DIRECTORY = "Mapper";
20-
private static EntityDataMapperFile instance;
21-
private String className;
20+
private final String className;
2221
private String namespaceFqn;
2322
private String classFqn;
2423

25-
private EntityDataMapperFile() {}
26-
2724
/**
28-
* Get singleton object of entity data mapper file.
25+
* Entity data mapper file constructor.
2926
*
3027
* @param entityName String
31-
*
32-
* @return EntityDataMapperFile
3328
*/
34-
public static EntityDataMapperFile getInstance(final @NotNull String entityName) {
35-
synchronized (EntityDataMapperFile.class) {
36-
if (instance == null) {
37-
instance = new EntityDataMapperFile();
38-
instance.className = entityName.concat(CLASS_NAME_SUFFIX);
39-
}
40-
}
41-
42-
return instance;
29+
public EntityDataMapperFile(final @NotNull String entityName) {
30+
this.className = entityName.concat(CLASS_NAME_SUFFIX);
4331
}
4432

4533
/**

testData/actions/generation/generator/EntityDataMapperClassGenerator/generateEntityDataMapperFile/UnicornDataMapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1010

1111
/**
12-
* Unicorn magento model collection to entity data transfer object array mapper.
12+
* Converts a collection of Unicorn entities to an array of data transfer objects.
1313
*/
1414
class UnicornDataMapper
1515
{

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public void testGenerateEntityDataMapperFile() {
3636
myFixture.getProject(),
3737
false
3838
);
39-
final EntityDataMapperFile entityDataMapperFile =
40-
EntityDataMapperFile.getInstance(ENTITY_NAME);
39+
final EntityDataMapperFile entityDataMapperFile = new EntityDataMapperFile(ENTITY_NAME);
4140
final String filePath = this.getFixturePath(entityDataMapperFile.getFileName());
4241

4342
assertGeneratedFileIsCorrect(

0 commit comments

Comments
 (0)