Conditions | 2 |
Paths | 2 |
Total Lines | 114 |
Code Lines | 92 |
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 |
||
95 | public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
||
96 | $repo = WikibaseRepo::getDefaultInstance(); |
||
97 | |||
98 | $language = $repo->getUserLanguage(); |
||
99 | $formatterOptions = new FormatterOptions(); |
||
100 | $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
||
101 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
||
102 | $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
||
103 | |||
104 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
||
105 | $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
||
106 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
||
107 | $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
||
108 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
||
109 | $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
||
110 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
||
111 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
||
112 | $unitConverter = $repo->getUnitConverter(); |
||
113 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
||
114 | $loggingHelper = new LoggingHelper( |
||
115 | $dataFactory, |
||
116 | LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
||
117 | $config |
||
118 | ); |
||
119 | $constraintParameterRenderer = new ConstraintParameterRenderer( |
||
120 | $entityIdHtmlLinkFormatter, |
||
121 | $valueFormatter, |
||
122 | $config |
||
123 | ); |
||
124 | $constraintReportFactory = new ConstraintReportFactory( |
||
125 | $repo->getEntityLookup(), |
||
126 | $repo->getPropertyDataTypeLookup(), |
||
127 | $repo->getStatementGuidParser(), |
||
128 | $config, |
||
129 | $constraintParameterRenderer, |
||
130 | new ConstraintParameterParser( |
||
131 | $config, |
||
132 | $repo->getBaseDataModelDeserializerFactory(), |
||
133 | $constraintParameterRenderer |
||
134 | ), |
||
135 | new ViolationMessageSerializer(), |
||
136 | new ViolationMessageDeserializer( |
||
137 | $repo->getEntityIdParser(), |
||
138 | $repo->getDataValueFactory() |
||
139 | ), |
||
140 | $repo->getRdfVocabulary(), |
||
141 | $repo->getEntityIdParser(), |
||
142 | $titleParser, |
||
143 | $unitConverter, |
||
144 | $dataFactory |
||
145 | ); |
||
146 | |||
147 | $checkResultsRenderer = new CheckResultsRenderer( |
||
148 | $repo->getEntityTitleLookup(), |
||
149 | $entityIdLabelFormatter, |
||
150 | new MultilingualTextViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter, $config ), |
||
151 | $config |
||
152 | ); |
||
153 | $resultsSource = new CheckingResultsSource( |
||
154 | $constraintReportFactory->getConstraintChecker() |
||
155 | ); |
||
156 | if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
||
157 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
||
158 | $repo->getEntityNamespaceLookup() |
||
159 | ); |
||
160 | $entityIdParser = $repo->getEntityIdParser(); |
||
161 | $checkResultSerializer = new CheckResultSerializer( |
||
162 | new ConstraintSerializer( |
||
163 | false // this API doesn’t expose the constraint parameters |
||
164 | ), |
||
165 | new ContextCursorSerializer(), |
||
166 | new ViolationMessageSerializer(), |
||
167 | false // unnecessary to serialize individual result dependencies |
||
168 | ); |
||
169 | $checkResultDeserializer = new CheckResultDeserializer( |
||
170 | new ConstraintDeserializer(), |
||
171 | new ContextCursorDeserializer(), |
||
172 | new ViolationMessageDeserializer( |
||
173 | $entityIdParser, |
||
174 | $repo->getDataValueFactory() |
||
175 | ), |
||
176 | $entityIdParser |
||
177 | ); |
||
178 | $resultsSource = new CachingResultsSource( |
||
179 | $resultsSource, |
||
180 | ResultsCache::getDefaultInstance(), |
||
181 | $checkResultSerializer, |
||
182 | $checkResultDeserializer, |
||
183 | $wikiPageEntityMetaDataAccessor, |
||
184 | $entityIdParser, |
||
185 | $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
||
186 | [ |
||
187 | $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
||
188 | $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
||
189 | $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
||
190 | $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
||
191 | ], |
||
192 | $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
||
193 | $loggingHelper |
||
194 | ); |
||
195 | } |
||
196 | |||
197 | return new CheckConstraints( |
||
198 | $main, |
||
199 | $name, |
||
200 | $prefix, |
||
201 | $repo->getEntityIdParser(), |
||
202 | $repo->getStatementGuidValidator(), |
||
203 | $repo->getApiHelperFactory( RequestContext::getMain() ), |
||
204 | $resultsSource, |
||
205 | $checkResultsRenderer, |
||
206 | $dataFactory |
||
207 | ); |
||
208 | } |
||
209 | |||
399 |