Conditions | 2 |
Paths | 2 |
Total Lines | 66 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | <?php |
||
63 | public function __construct(IApplicationConfiguration $appConfig) |
||
64 | { |
||
65 | $this->appConfig = $appConfig; |
||
66 | |||
67 | $twigPaths = [ |
||
68 | $appConfig->getLibdir().'/templates', |
||
69 | $appConfig->getComposerDir().'/symfony/twig-bridge/Resources/views/Form', |
||
70 | ]; |
||
71 | |||
72 | if (null !== $appConfig->getCustomTwigDir()) { |
||
73 | $twigPaths[] = $appConfig->getCustomTwigDir(); |
||
74 | } |
||
75 | |||
76 | $loader = new Twig_Loader_Filesystem($twigPaths); |
||
77 | $twig = new Twig_Environment($loader, [ |
||
78 | "cache" => false, |
||
79 | ]); |
||
80 | $assetFunction = new Twig_Function("asset", [ |
||
81 | $appConfig, |
||
82 | "getAssetUri", |
||
83 | ]); |
||
84 | $twig->addFunction($assetFunction); |
||
85 | $translator = new Translator('en'); |
||
86 | $translator->addLoader('xlf', new XliffFileLoader()); |
||
87 | // $translator->addResource( |
||
88 | // 'xlf', |
||
89 | // __DIR__.'/path/to/translations/messages.en.xlf', |
||
90 | // 'en' |
||
91 | // ); |
||
92 | $twig->addExtension(new TranslationExtension($translator)); |
||
93 | |||
94 | $csrfGenerator = new UriSafeTokenGenerator(); |
||
95 | $csrfStorage = $this->appConfig->getTokenStorage(); |
||
96 | $csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage); |
||
97 | |||
98 | $defaultFormTheme = "form_div_layout.html.twig"; |
||
99 | |||
100 | $formEngine = new TwigRendererEngine([$defaultFormTheme], $twig); |
||
101 | $twig->addRuntimeLoader(new Twig_FactoryRuntimeLoader([ |
||
102 | FormRenderer::class => function () use ($formEngine, $csrfManager) { |
||
103 | return new FormRenderer($formEngine, $csrfManager); |
||
104 | }, |
||
105 | ])); |
||
106 | $twig->addExtension(new FormExtension()); |
||
107 | $validator = Validation::createValidator(); |
||
108 | $formFactory = Forms::createFormFactoryBuilder() |
||
109 | ->addExtension(new CsrfExtension($csrfManager)) |
||
110 | ->addExtension(new HttpFoundationExtension()) |
||
111 | ->addExtension(new HttpFoundationExtension()) |
||
112 | ->addExtension(new ValidatorExtension($validator)) |
||
113 | ->getFormFactory() |
||
114 | ; |
||
115 | |||
116 | $containerBuilder = new ContainerBuilder(); |
||
117 | $containerBuilder->addDefinitions([ |
||
118 | IApplicationConfiguration::class => function () use ($appConfig) { |
||
119 | return $appConfig; |
||
120 | }, |
||
121 | Twig_Environment::class => function () use ($twig) { |
||
122 | return $twig; |
||
123 | }, |
||
124 | FormFactoryInterface::class => function () use ($formFactory) { |
||
125 | return $formFactory; |
||
126 | }, |
||
127 | ]); |
||
128 | $this->container = $containerBuilder->build(); |
||
129 | } |
||
190 |