Conditions | 8 |
Paths | 6 |
Total Lines | 124 |
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 | <?php |
||
55 | public function prepend(ContainerBuilder $container) |
||
56 | { |
||
57 | $hosts = []; |
||
58 | if ($container->hasParameter('kunstmaan_search.hostname') && $container->hasParameter('kunstmaan_search.port')) { |
||
59 | $host = $container->getParameter('kunstmaan_search.hostname').':'.$container->getParameter('kunstmaan_search.port'); |
||
60 | |||
61 | if ($container->hasParameter('kunstmaan_search.username') && $container->hasParameter('kunstmaan_search.password') && |
||
62 | null !== $container->getParameter('kunstmaan_search.username') && null !== $container->getParameter('kunstmaan_search.password')) { |
||
63 | $host = sprintf( |
||
64 | '%s:%s@%s', |
||
65 | $container->getParameter('kunstmaan_search.username'), |
||
66 | $container->getParameter('kunstmaan_search.password'), |
||
67 | $host |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | $hosts[] = $host; |
||
72 | } |
||
73 | |||
74 | $this->useElasticSearchVersion6 = ElasticSearchUtil::useVersion6($hosts); |
||
75 | |||
76 | if ($this->useElasticSearchVersion6) { |
||
77 | $mapping = [ |
||
78 | 'mapping' => [ |
||
79 | 'root_id' => [ |
||
80 | 'type' => 'integer', |
||
81 | ], |
||
82 | 'node_id' => [ |
||
83 | 'type' => 'integer', |
||
84 | ], |
||
85 | 'nodetranslation_id' => [ |
||
86 | 'type' => 'integer', |
||
87 | ], |
||
88 | 'nodeversion_id' => [ |
||
89 | 'type' => 'integer', |
||
90 | ], |
||
91 | 'title' => [ |
||
92 | 'type' => 'text', |
||
93 | ], |
||
94 | 'slug' => [ |
||
95 | 'type' => 'text', |
||
96 | ], |
||
97 | 'type' => [ |
||
98 | 'type' => 'keyword', |
||
99 | ], |
||
100 | 'page_class' => [ |
||
101 | 'type' => 'keyword', |
||
102 | ], |
||
103 | 'content' => [ |
||
104 | 'type' => 'text', |
||
105 | ], |
||
106 | 'view_roles' => [ |
||
107 | 'type' => 'keyword', |
||
108 | ], |
||
109 | ] |
||
110 | ]; |
||
111 | } else { |
||
112 | $mapping = [ |
||
113 | 'mapping' => [ |
||
114 | 'root_id' => [ |
||
115 | 'type' => 'integer', |
||
116 | 'include_in_all' => false, |
||
117 | 'index' => 'not_analyzed' |
||
118 | ], |
||
119 | 'node_id' => [ |
||
120 | 'type' => 'integer', |
||
121 | 'include_in_all' => false, |
||
122 | 'index' => 'not_analyzed' |
||
123 | ], |
||
124 | 'nodetranslation_id' => [ |
||
125 | 'type' => 'integer', |
||
126 | 'include_in_all' => false, |
||
127 | 'index' => 'not_analyzed' |
||
128 | ], |
||
129 | 'nodeversion_id' => [ |
||
130 | 'type' => 'integer', |
||
131 | 'include_in_all' => false, |
||
132 | 'index' => 'not_analyzed' |
||
133 | ], |
||
134 | 'title' => [ |
||
135 | 'type' => 'string', |
||
136 | 'boost' => 2, |
||
137 | 'include_in_all' => true |
||
138 | ], |
||
139 | 'slug' => [ |
||
140 | 'type' => 'string', |
||
141 | 'include_in_all' => false, |
||
142 | 'index' => 'not_analyzed' |
||
143 | ], |
||
144 | 'type' => [ |
||
145 | 'type' => 'string', |
||
146 | 'include_in_all' => false, |
||
147 | 'index' => 'not_analyzed' |
||
148 | ], |
||
149 | 'page_class' => [ |
||
150 | 'type' => 'string', |
||
151 | 'include_in_all' => false, |
||
152 | 'index' => 'not_analyzed' |
||
153 | ], |
||
154 | 'content' => [ |
||
155 | 'type' => 'string', |
||
156 | 'include_in_all' => true |
||
157 | ], |
||
158 | 'created' => [ |
||
159 | 'type' => 'date', |
||
160 | 'include_in_all' => false, |
||
161 | 'index' => 'not_analyzed' |
||
162 | ], |
||
163 | 'updated' => [ |
||
164 | 'type' => 'date', |
||
165 | 'include_in_all' => false, |
||
166 | 'index' => 'not_analyzed' |
||
167 | ], |
||
168 | 'view_roles' => [ |
||
169 | 'type' => 'string', |
||
170 | 'include_in_all' => true, |
||
171 | 'index' => 'not_analyzed', |
||
172 | ], |
||
173 | ] |
||
174 | ]; |
||
175 | } |
||
176 | |||
177 | $container->prependExtensionConfig('kunstmaan_node_search', $mapping); |
||
178 | } |
||
179 | } |
||
180 |