Skip to content

Commit dff16be

Browse files
Issue #2929739 by drunken monkey, borisson_: Improved adherence to coding standards.
1 parent d744907 commit dff16be

File tree

13 files changed

+209
-27
lines changed

13 files changed

+209
-27
lines changed

Diff for: CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Search API 1.x, dev (xxxx-xx-xx):
22
---------------------------------
3+
- #2929739 by drunken monkey, borisson_: Improved adherence to coding standards.
34
- #2927748 by mkalkbrenner, mstiem, drunken monkey: Fixed Views field handler
45
for multiple processor-defined fields returned by the server.
56
- #2928944 by drunken monkey: Removed assert() calls with string parameters.

Diff for: phpcs.xml

+178-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,44 @@
66

77
<!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.-->
88
<!-- Drupal sniffs -->
9+
<rule ref="Drupal.Array.DisallowLongArraySyntax"/>
910
<rule ref="Drupal.Classes.ClassCreateInstance"/>
1011
<rule ref="Drupal.Classes.ClassDeclaration"/>
1112
<rule ref="Drupal.Classes.FullyQualifiedNamespace"/>
13+
<rule ref="Drupal.Classes.InterfaceName"/>
1214
<rule ref="Drupal.Classes.UnusedUseStatement"/>
1315
<rule ref="Drupal.Classes.UseLeadingBackslash"/>
1416
<rule ref="Drupal.CSS.ClassDefinitionNameSpacing"/>
1517
<rule ref="Drupal.CSS.ColourDefinition"/>
1618
<rule ref="Drupal.Commenting.ClassComment"/>
19+
<rule ref="Drupal.Commenting.DataTypeNamespace" />
1720
<rule ref="Drupal.Commenting.DocComment"/>
1821
<rule ref="Drupal.Commenting.DocCommentStar"/>
1922
<rule ref="Drupal.Commenting.FileComment"/>
2023
<rule ref="Drupal.Commenting.FunctionComment"/>
24+
<rule ref="Drupal.Commenting.InlineComment">
25+
<!-- This is impractical when commenting code out. -->
26+
<exclude name="Drupal.Commenting.InlineComment.InvalidEndChar" />
27+
<!-- We (rarely) use comments as "headings" for multiple functions. -->
28+
<exclude name="Drupal.Commenting.InlineComment.SpacingAfter" />
29+
<!--
30+
This disallows indentation in comments, even though it can sometimes be
31+
helpful for structured explanations.
32+
33+
@see \Drupal\search_api\Plugin\search_api\processor\ContentAccess::addNodeAccess()
34+
-->
35+
<exclude name="Drupal.Commenting.InlineComment.SpacingBefore" />
36+
</rule>
37+
<rule ref="Drupal.Commenting.VariableComment">
38+
<!-- This finds false positives when @code is used. -->
39+
<exclude name="Drupal.Commenting.VariableComment.VarOrder"/>
40+
</rule>
41+
<rule ref="Drupal.Commenting.PostStatementComment"/>
2142
<rule ref="Drupal.ControlStructures.ElseIf"/>
2243
<rule ref="Drupal.ControlStructures.ControlSignature"/>
44+
<rule ref="Drupal.ControlStructures.InlineControlStructure"/>
2345
<rule ref="Drupal.Files.EndFileNewline"/>
46+
<rule ref="Drupal.Files.FileEncoding"/>
2447
<rule ref="Drupal.Files.TxtFileLineLength"/>
2548
<rule ref="Drupal.Formatting.MultiLineAssignment"/>
2649
<rule ref="Drupal.Formatting.SpaceInlineIf"/>
@@ -31,50 +54,201 @@
3154
<rule ref="Drupal.InfoFiles.ClassFiles"/>
3255
<rule ref="Drupal.InfoFiles.DuplicateEntry"/>
3356
<rule ref="Drupal.InfoFiles.Required"/>
57+
<rule ref="Drupal.Methods.MethodDeclaration"/>
3458
<rule ref="Drupal.NamingConventions.ValidVariableName">
35-
<!-- Sniff for: LowerStart -->
59+
<!-- This interferes with the stored entity properties. -->
3660
<exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/>
3761
</rule>
3862
<rule ref="Drupal.Scope.MethodScope"/>
3963
<rule ref="Drupal.Semantics.EmptyInstall"/>
64+
<rule ref="Drupal.Semantics.FunctionAlias"/>
4065
<rule ref="Drupal.Semantics.FunctionT"/>
4166
<rule ref="Drupal.Semantics.FunctionWatchdog"/>
4267
<rule ref="Drupal.Semantics.InstallHooks"/>
4368
<rule ref="Drupal.Semantics.LStringTranslatable"/>
4469
<rule ref="Drupal.Semantics.PregSecurity"/>
4570
<rule ref="Drupal.Semantics.TInHookMenu"/>
4671
<rule ref="Drupal.Semantics.TInHookSchema"/>
72+
<rule ref="Drupal.WhiteSpace.CloseBracketSpacing"/>
4773
<rule ref="Drupal.WhiteSpace.Comma"/>
4874
<rule ref="Drupal.WhiteSpace.EmptyLines"/>
75+
<rule ref="Drupal.WhiteSpace.Namespace"/>
4976
<rule ref="Drupal.WhiteSpace.ObjectOperatorIndent"/>
5077
<rule ref="Drupal.WhiteSpace.ObjectOperatorSpacing"/>
78+
<rule ref="Drupal.WhiteSpace.OpenBracketSpacing"/>
5179
<rule ref="Drupal.WhiteSpace.OpenTagNewline"/>
5280
<rule ref="Drupal.WhiteSpace.OperatorSpacing"/>
81+
<rule ref="Drupal.WhiteSpace.ScopeClosingBrace"/>
5382
<rule ref="Drupal.WhiteSpace.ScopeIndent"/>
5483

5584
<!-- Drupal Practice sniffs -->
5685
<rule ref="DrupalPractice.Commenting.ExpectedException"/>
5786

5887
<!-- Generic sniffs -->
88+
<rule ref="Generic.Files.ByteOrderMark"/>
5989
<rule ref="Generic.Files.LineEndings"/>
90+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
6091
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
61-
<rule ref="Generic.NamingConventions.ConstructorName" />
92+
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
93+
<properties>
94+
<property name="checkClosures" value="true"/>
95+
</properties>
96+
</rule>
97+
<rule ref="Generic.NamingConventions.ConstructorName"/>
6298
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
6399
<rule ref="Generic.PHP.DeprecatedFunctions"/>
64100
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
101+
<rule ref="Generic.PHP.LowerCaseKeyword"/>
65102
<rule ref="Generic.PHP.UpperCaseConstant"/>
66103
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
67-
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
104+
105+
<!-- MySource sniffs -->
106+
<rule ref="MySource.Debug.DebugCode"/>
107+
108+
<!-- PEAR sniffs -->
109+
<rule ref="PEAR.Files.IncludingFile"/>
110+
<!-- Disable some error messages that we do not want. -->
111+
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
112+
<severity>0</severity>
113+
</rule>
114+
<rule ref="PEAR.Files.IncludingFile.UseInclude">
115+
<severity>0</severity>
116+
</rule>
117+
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
118+
<severity>0</severity>
119+
</rule>
120+
<rule ref="PEAR.Files.IncludingFile.UseRequire">
121+
<severity>0</severity>
122+
</rule>
123+
<rule ref="PEAR.Functions.ValidDefaultValue"/>
124+
125+
<!-- PEAR sniffs -->
126+
<rule ref="PEAR.Functions.FunctionCallSignature"/>
127+
<!-- The sniffs inside PEAR.Functions.FunctionCallSignature silenced below are
128+
also silenced in Drupal CS' ruleset.xml. The code below is a 1-on-1 copy
129+
from that file. -->
130+
<!-- Disable some error messages that we already cover. -->
131+
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
132+
<severity>0</severity>
133+
</rule>
134+
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
135+
<severity>0</severity>
136+
</rule>
137+
<!-- Disable some error messages that we do not want. -->
138+
<rule ref="PEAR.Functions.FunctionCallSignature.Indent">
139+
<severity>0</severity>
140+
</rule>
141+
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
142+
<severity>0</severity>
143+
</rule>
144+
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
145+
<severity>0</severity>
146+
</rule>
147+
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
148+
<severity>0</severity>
149+
</rule>
68150

69151
<!-- PSR-2 sniffs -->
70152
<rule ref="PSR2.Classes.PropertyDeclaration"/>
153+
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
154+
<rule ref="PSR2.Namespaces.UseDeclaration"/>
71155

72156
<!-- Squiz sniffs -->
157+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
158+
<rule ref="Squiz.Arrays.ArrayDeclaration">
159+
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
160+
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
161+
</rule>
162+
<!-- Disable some error messages that we do not want. -->
163+
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
164+
<severity>0</severity>
165+
</rule>
166+
<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
167+
<severity>0</severity>
168+
</rule>
169+
<rule ref="Squiz.Arrays.ArrayDeclaration.FirstValueNoNewline">
170+
<severity>0</severity>
171+
</rule>
172+
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
173+
<severity>0</severity>
174+
</rule>
175+
<rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed">
176+
<severity>0</severity>
177+
</rule>
178+
<rule ref="Squiz.Arrays.ArrayDeclaration.NoComma">
179+
<severity>0</severity>
180+
</rule>
181+
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast">
182+
<severity>0</severity>
183+
</rule>
184+
<rule ref="Squiz.Arrays.ArrayDeclaration.NotLowerCase">
185+
<severity>0</severity>
186+
</rule>
187+
<rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
188+
<severity>0</severity>
189+
</rule>
190+
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
191+
<severity>0</severity>
192+
</rule>
193+
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
194+
<severity>0</severity>
195+
</rule>
196+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
197+
<!-- Disable some error messages that we already cover. -->
198+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
199+
<severity>0</severity>
200+
</rule>
201+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
202+
<severity>0</severity>
203+
</rule>
204+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
205+
<severity>0</severity>
206+
</rule>
207+
<rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
208+
<!-- Disable some error messages that we already cover. -->
209+
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
210+
<severity>0</severity>
211+
</rule>
212+
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
213+
<severity>0</severity>
214+
</rule>
215+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
216+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
217+
<severity>0</severity>
218+
</rule>
219+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
220+
<severity>0</severity>
221+
</rule>
222+
<!-- Standard yet to be finalized on this (https://www.drupal.org/node/1539712). -->
223+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
224+
<severity>0</severity>
225+
</rule>
226+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
227+
<severity>0</severity>
228+
</rule>
229+
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
230+
<severity>0</severity>
231+
</rule>
232+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
233+
<properties>
234+
<property name="equalsSpacing" value="1"/>
235+
</properties>
236+
</rule>
237+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
238+
<severity>0</severity>
239+
</rule>
240+
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
73241
<rule ref="Squiz.Strings.ConcatenationSpacing">
74242
<properties>
75243
<property name="spacing" value="1"/>
76244
<property name="ignoreNewlines" value="true"/>
77245
</properties>
78-
</rule>
246+
</rule>
247+
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
248+
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
249+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
250+
251+
<!-- Zend sniffs -->
252+
<rule ref="Zend.Files.ClosingTag"/>
79253

80254
</ruleset>

Diff for: search_api.theme.inc

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function theme_search_api_form_item_list(array $variables) {
185185
*/
186186
function theme_search_api_server(array $variables) {
187187
// Get the search server.
188-
/** @var $server \Drupal\search_api\ServerInterface */
188+
/** @var \Drupal\search_api\ServerInterface $server */
189189
$server = $variables['server'];
190190

191191
$output = '';
@@ -296,7 +296,7 @@ function theme_search_api_server(array $variables) {
296296
* Implements hook_preprocess_search_api_index().
297297
*/
298298
function search_api_preprocess_search_api_index(array &$variables) {
299-
/** @var $index \Drupal\search_api\IndexInterface */
299+
/** @var \Drupal\search_api\IndexInterface $index */
300300
$index = $variables['index'];
301301

302302
if ($index->status()) {
@@ -331,7 +331,7 @@ function search_api_preprocess_search_api_index(array &$variables) {
331331
*/
332332
function theme_search_api_index(array $variables) {
333333
// Get the index.
334-
/** @var $index \Drupal\search_api\IndexInterface */
334+
/** @var \Drupal\search_api\IndexInterface $index */
335335
$index = $variables['index'];
336336
$server = $index->hasValidServer() ? $index->getServerInstance() : NULL;
337337
$tracker = $index->hasValidTracker() ? $index->getTrackerInstance() : NULL;

Diff for: src/Form/IndexForm.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public function buildAjaxTrackerConfigForm(array $form, FormStateInterface $form
483483
public function validateForm(array &$form, FormStateInterface $form_state) {
484484
parent::validateForm($form, $form_state);
485485

486-
/** @var $index \Drupal\search_api\IndexInterface */
486+
/** @var \Drupal\search_api\IndexInterface $index */
487487
$index = $this->getEntity();
488488

489489
$storage = $this->entityTypeManager->getStorage('search_api_index');
@@ -558,7 +558,7 @@ public function actions(array $form, FormStateInterface $form_state) {
558558
public function submitForm(array &$form, FormStateInterface $form_state) {
559559
parent::submitForm($form, $form_state);
560560

561-
/** @var $index \Drupal\search_api\IndexInterface */
561+
/** @var \Drupal\search_api\IndexInterface $index */
562562
$index = $this->getEntity();
563563
$index->setOptions($form_state->getValue('options', []) + $this->originalEntity->getOptions());
564564

Diff for: src/Form/IndexProcessorsForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ protected function getAllProcessors() {
360360
}
361361
elseif (class_exists($processor_definition['class'])) {
362362
if (call_user_func([$processor_definition['class'], 'supportsIndex'], $this->entity)) {
363-
/** @var $processor \Drupal\search_api\Processor\ProcessorInterface */
363+
/** @var \Drupal\search_api\Processor\ProcessorInterface $processor */
364364
$processor = $this->processorPluginManager->createInstance($name, $settings);
365365
$processors[$name] = $processor;
366366
}

Diff for: src/Plugin/search_api/datasource/ContentEntityDeriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterf
3636
public static function create(ContainerInterface $container, $base_plugin_id) {
3737
$deriver = new static();
3838

39-
/** @var $entity_type_manager \Drupal\Core\Entity\EntityTypeManagerInterface */
39+
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
4040
$entity_type_manager = $container->get('entity_type.manager');
4141
$deriver->setEntityTypeManager($entity_type_manager);
4242

Diff for: src/ProxyClass/ParamConverter/SearchApiConverter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class SearchApiConverter implements ParamConverterInterface {
3838
/**
3939
* The service container.
4040
*
41-
* @var ContainerInterface
41+
* @var \Symfony\Component\DependencyInjection\ContainerInterface
4242
*/
4343
protected $container;
4444

4545
/**
4646
* Constructs a ProxyClass Drupal proxy object.
4747
*
48-
* @param ContainerInterface $container
48+
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
4949
* The container.
5050
* @param string $drupal_proxy_original_service_id
5151
* The service ID of the original service.
@@ -58,7 +58,7 @@ public function __construct(ContainerInterface $container, $drupal_proxy_origina
5858
/**
5959
* Lazy loads the real service from the container.
6060
*
61-
* @return object
61+
* @return \Drupal\search_api\ParamConverter\SearchApiConverter
6262
* Returns the constructed real service.
6363
*/
6464
protected function lazyLoadItself() {

Diff for: src/Utility/FieldsHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class FieldsHelper implements FieldsHelperInterface {
8787
* The entity type manager.
8888
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
8989
* The entity field manager.
90-
* @param EntityTypeBundleInfoInterface $entityBundleInfo
90+
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityBundleInfo
9191
* The entity type bundle info service.
9292
* @param \Drupal\search_api\Utility\DataTypeHelperInterface $dataTypeHelper
9393
* The data type helper service.

Diff for: tests/src/Functional/IntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ protected function editServer() {
400400
];
401401
$this->submitForm($edit, 'Save');
402402

403-
/** @var $index \Drupal\search_api\IndexInterface */
403+
/** @var \Drupal\search_api\IndexInterface $index */
404404
$index = $this->indexStorage->load($this->indexId);
405405
$remaining = $index->getTrackerInstance()->getRemainingItemsCount();
406406
$this->assertEquals(0, $remaining, 'Index was not scheduled for re-indexing when saving its server.');
@@ -1462,7 +1462,7 @@ protected function deleteServer() {
14621462

14631463
// Confirm that the index hasn't been deleted.
14641464
$this->indexStorage->resetCache([$this->indexId]);
1465-
/** @var $index \Drupal\search_api\IndexInterface */
1465+
/** @var \Drupal\search_api\IndexInterface $index */
14661466
$index = $this->indexStorage->load($this->indexId);
14671467
$this->assertTrue($index, 'The index associated with the server was not deleted.');
14681468
$this->assertFalse($index->status(), 'The index associated with the server was disabled.');

Diff for: tests/src/Kernel/Datasource/ContentEntityDatasourceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function testItemDiscovery() {
243243
*/
244244
protected function getItemIds(array $bundles = NULL, array $languages = NULL) {
245245
$discovered_ids = [];
246-
for ($page = 0; ; ++$page) {
246+
for ($page = 0;; ++$page) {
247247
$new_ids = $this->datasource->getPartialItemIds($page, $bundles, $languages);
248248
if ($new_ids === NULL) {
249249
break;

Diff for: tests/src/Kernel/Processor/AddHierarchyTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class AddHierarchyTest extends ProcessorTestBase {
3737

3838
/**
3939
* A hierarchy to test.
40+
*
41+
* @var string[][]
4042
*/
4143
protected static $hierarchy = [
4244
'fruit' => [

Diff for: tests/src/Kernel/Processor/RenderedItemTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public function setUp($processor = NULL) {
161161
$this->index->setDatasources($datasources);
162162
$this->index->save();
163163

164-
165164
// Enable the classy and stable themes as the tests rely on markup from
166165
// that. Set stable as the active theme, but make classy the default. The
167166
// processor should switch to classy to perform the rendering.

0 commit comments

Comments
 (0)