| Conditions | 5 |
| Total Lines | 55 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 17 | |||
| 18 | // eslint-disable-next-line sw-deprecation-rules/private-feature-declarations |
||
| 19 | export default function initializeRepositoryFactory(container: InitContainer) { |
||
| 20 | const httpClient = container.httpClient; |
||
| 21 | const factoryContainer = Shopware.Application.getContainer('factory'); |
||
| 22 | const serviceContainer = Shopware.Application.getContainer('service'); |
||
| 23 | |||
| 24 | return httpClient.get('_info/entity-schema.json', { |
||
| 25 | headers: { |
||
| 26 | Authorization: `Bearer ${serviceContainer.loginService.getToken()}`, |
||
| 27 | }, |
||
| 28 | }).then(({ data }) => { |
||
| 29 | const entityDefinitionFactory = factoryContainer.entityDefinition; |
||
| 30 | const customEntityDefinitionService = serviceContainer.customEntityDefinitionService; |
||
| 31 | const cmsPageTypeService = serviceContainer.cmsPageTypeService; |
||
| 32 | let hasCmsAwareDefinitions = false; |
||
| 33 | |||
| 34 | // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
||
| 35 | Object.entries(data).forEach(([key, value]) => { |
||
| 36 | entityDefinitionFactory.add(key, value); |
||
| 37 | |||
| 38 | if (key.startsWith('custom_entity_') || key.startsWith('ce_')) { |
||
| 39 | // @ts-expect-error - value is defined |
||
| 40 | customEntityDefinitionService.addDefinition(value); |
||
| 41 | // @ts-expect-error - value is defined |
||
| 42 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
||
| 43 | hasCmsAwareDefinitions = hasCmsAwareDefinitions || !!value?.flags?.['cms-aware']; |
||
| 44 | } |
||
| 45 | }); |
||
| 46 | |||
| 47 | if (hasCmsAwareDefinitions) { |
||
| 48 | customEntityTypes.forEach((customEntityType) => { |
||
| 49 | cmsPageTypeService.register(customEntityType); |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | |||
| 53 | const hydrator = new EntityHydrator(); |
||
| 54 | const changesetGenerator = new ChangesetGenerator(); |
||
| 55 | const entityFactory = new EntityFactory(); |
||
| 56 | const errorResolver = new ErrorResolverError(); |
||
| 57 | |||
| 58 | Shopware.Application.addServiceProvider('repositoryFactory', () => { |
||
| 59 | return new RepositoryFactory( |
||
| 60 | hydrator, |
||
| 61 | changesetGenerator, |
||
| 62 | entityFactory, |
||
| 63 | httpClient, |
||
| 64 | errorResolver, |
||
| 65 | ); |
||
| 66 | }); |
||
| 67 | Shopware.Application.addServiceProvider('entityHydrator', () => { |
||
| 68 | return hydrator; |
||
| 69 | }); |
||
| 70 | Shopware.Application.addServiceProvider('entityFactory', () => { |
||
| 71 | return entityFactory; |
||
| 72 | }); |
||
| 75 |