Conditions | 9 |
Total Lines | 60 |
Code Lines | 46 |
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 | import { DynamicModule, Global, Module } from '@nestjs/common'; |
||
54 | |||
55 | static forDynamic( |
||
56 | rbac: new () => IDynamicStorageRbac, |
||
57 | providers?: any[], |
||
58 | imports?: any[], |
||
59 | ): DynamicModule { |
||
60 | const inject = [ModuleRef, rbac]; |
||
61 | |||
62 | if (RBAcModule.cache) { |
||
63 | inject.push(RBAcModule.cache); |
||
64 | } |
||
65 | |||
66 | const commonProviders = [ |
||
67 | ...(providers || []), |
||
68 | rbac, |
||
69 | { |
||
70 | provide: StorageRbacService, |
||
71 | useFactory: async (moduleRef: ModuleRef, rbacService: IDynamicStorageRbac, cache?: ICacheRBAC) => { |
||
72 | if (cache && !RBAcModule.cacheOptions) { |
||
73 | return cache; |
||
74 | } |
||
75 | if (cache && RBAcModule.cacheOptions.KEY) { |
||
76 | cache.KEY = RBAcModule.cacheOptions.KEY; |
||
77 | } |
||
78 | |||
79 | if (cache && RBAcModule.cacheOptions.TTL) { |
||
80 | cache.TTL = RBAcModule.cacheOptions.TTL; |
||
81 | } |
||
82 | return new StorageRbacService(moduleRef, rbacService, cache); |
||
83 | }, |
||
84 | inject, |
||
85 | }, |
||
86 | ]; |
||
87 | |||
88 | if (RBAcModule.cache) { |
||
89 | commonProviders.push(RBAcModule.cache, { |
||
90 | provide: 'ICacheRBAC', |
||
91 | useFactory: (cache: ICacheRBAC): ICacheRBAC => { |
||
92 | if (!RBAcModule.cacheOptions) { |
||
93 | return cache; |
||
94 | } |
||
95 | if (RBAcModule.cacheOptions.KEY) { |
||
96 | cache.KEY = RBAcModule.cacheOptions.KEY; |
||
97 | } |
||
98 | |||
99 | if (RBAcModule.cacheOptions.TTL) { |
||
100 | cache.TTL = RBAcModule.cacheOptions.TTL; |
||
101 | } |
||
102 | |||
103 | return cache; |
||
104 | }, |
||
105 | inject: [RBAcModule.cache], |
||
106 | }); |
||
107 | } |
||
108 | |||
109 | return { |
||
110 | module: RBAcModule, |
||
111 | providers: commonProviders, |
||
112 | imports: [ |
||
113 | ...(imports || []), |
||
114 | ], |
||
118 |