Issue #3041985 by alexpott, pifagor: Add Generic.CodeAnalysis.EmptyPHPStatement to phpcs rules to prevent empty PHP statements

merge-requests/1119/head
catch 2019-04-16 21:22:07 +09:00
parent fe33718231
commit f2eaf0178c
20 changed files with 21 additions and 23 deletions

View File

@ -837,7 +837,7 @@ function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = N
// Assign an arbitrary id: don't rely on a serial column in the 'batch' // Assign an arbitrary id: don't rely on a serial column in the 'batch'
// table, since non-progressive batches skip database storage completely. // table, since non-progressive batches skip database storage completely.
$batch['id'] = \Drupal::database()->nextId();; $batch['id'] = \Drupal::database()->nextId();
// Move operations to a job queue. Non-progressive batches will use a // Move operations to a job queue. Non-progressive batches will use a
// memory-based queue. // memory-based queue.

View File

@ -76,7 +76,7 @@ class DeletedFieldsRepository implements DeletedFieldsRepositoryInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function removeFieldDefinition(FieldDefinitionInterface $field_definition) { public function removeFieldDefinition(FieldDefinitionInterface $field_definition) {
$deleted_field_definitions = $this->state->get('field.field.deleted', []);; $deleted_field_definitions = $this->state->get('field.field.deleted', []);
unset($deleted_field_definitions[$field_definition->getUniqueIdentifier()]); unset($deleted_field_definitions[$field_definition->getUniqueIdentifier()]);
$this->state->set('field.field.deleted', $deleted_field_definitions); $this->state->set('field.field.deleted', $deleted_field_definitions);

View File

@ -49,7 +49,6 @@ class AggregatorLocalTasksTest extends LocalTaskIntegrationTestBase {
$this->assertLocalTasks($route, [ $this->assertLocalTasks($route, [
0 => ['entity.aggregator_feed.canonical', 'entity.aggregator_feed.edit_form', 'entity.aggregator_feed.delete_form'], 0 => ['entity.aggregator_feed.canonical', 'entity.aggregator_feed.edit_form', 'entity.aggregator_feed.delete_form'],
]); ]);
;
} }
/** /**

View File

@ -55,7 +55,7 @@ class CommentFieldsTest extends CommentTestBase {
// Test adding a field that defaults to CommentItemInterface::CLOSED. // Test adding a field that defaults to CommentItemInterface::CLOSED.
$this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies'); $this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
$field = FieldConfig::load('node.test_node_type.who_likes_ponies');; $field = FieldConfig::load('node.test_node_type.who_likes_ponies');
$this->assertEqual($field->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED); $this->assertEqual($field->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED);
} }

View File

@ -556,7 +556,7 @@ class ContactSitewideTest extends BrowserTestBase {
* Deletes all forms. * Deletes all forms.
*/ */
public function deleteContactForms() { public function deleteContactForms() {
$contact_forms = ContactForm::loadMultiple();; $contact_forms = ContactForm::loadMultiple();
foreach ($contact_forms as $id => $contact_form) { foreach ($contact_forms as $id => $contact_form) {
if ($id == 'personal') { if ($id == 'personal') {
// Personal form could not be deleted. // Personal form could not be deleted.

View File

@ -56,7 +56,7 @@ class ModerationStateNodeTest extends ModerationStateTestBase {
// Disable content moderation. // Disable content moderation.
$edit['bundles[moderated_content]'] = FALSE; $edit['bundles[moderated_content]'] = FALSE;
$this->drupalPostForm('admin/config/workflow/workflows/manage/editorial/type/node', $edit, t('Save'));; $this->drupalPostForm('admin/config/workflow/workflows/manage/editorial/type/node', $edit, t('Save'));
// Ensure the parent environment is up-to-date. // Ensure the parent environment is up-to-date.
// @see content_moderation_workflow_insert() // @see content_moderation_workflow_insert()
\Drupal::service('entity_type.bundle.info')->clearCachedBundles(); \Drupal::service('entity_type.bundle.info')->clearCachedBundles();

View File

@ -34,7 +34,7 @@ class ImageUrlFormatter extends ImageFormatter {
public function settingsForm(array $form, FormStateInterface $form_state) { public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state); $element = parent::settingsForm($form, $form_state);
unset($element['image_link']);; unset($element['image_link']);
return $element; return $element;
} }

View File

@ -82,7 +82,7 @@ abstract class ConfigurableLanguageResourceTestBase extends EntityResourceTestBa
*/ */
public function testGetDefaultConfig() { public function testGetDefaultConfig() {
$this->initAuthentication(); $this->initAuthentication();
$url = Url::fromUri('base:/entity/configurable_language/en')->setOption('query', ['_format' => static::$format]);; $url = Url::fromUri('base:/entity/configurable_language/en')->setOption('query', ['_format' => static::$format]);
$request_options = $this->getAuthenticationRequestOptions('GET'); $request_options = $this->getAuthenticationRequestOptions('GET');
$this->provisionEntityResource(); $this->provisionEntityResource();
$this->setUpAuthorization('GET'); $this->setUpAuthorization('GET');

View File

@ -117,7 +117,7 @@ class BlockFilterTest extends WebDriverTestBase {
}); });
// Test Drupal.announce() message when all blocks are listed. // Test Drupal.announce() message when all blocks are listed.
$filter->setValue('');; $filter->setValue('');
$this->assertAnnounceContains('All available blocks are listed.'); $this->assertAnnounceContains('All available blocks are listed.');
// Confirm the Content Fields category remains collapsed after filtering. // Confirm the Content Fields category remains collapsed after filtering.
$this->assertFalse($promoteToFrontPageLink->isVisible()); $this->assertFalse($promoteToFrontPageLink->isVisible());

View File

@ -1141,13 +1141,13 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$this->assertResourceErrorResponse(403, "Access denied on updating field 'field_rest_test'.", $response); $this->assertResourceErrorResponse(403, "Access denied on updating field 'field_rest_test'.", $response);
// DX: 403 when entity trying to update an entity's ID field. // DX: 403 when entity trying to update an entity's ID field.
$request_options[RequestOptions::BODY] = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPatchEntity(), 'id'), static::$format);; $request_options[RequestOptions::BODY] = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPatchEntity(), 'id'), static::$format);
$response = $this->request('PATCH', $url, $request_options); $response = $this->request('PATCH', $url, $request_options);
$this->assertResourceErrorResponse(403, "Access denied on updating field '{$this->entity->getEntityType()->getKey('id')}'. The entity ID cannot be changed.", $response); $this->assertResourceErrorResponse(403, "Access denied on updating field '{$this->entity->getEntityType()->getKey('id')}'. The entity ID cannot be changed.", $response);
if ($this->entity->getEntityType()->hasKey('uuid')) { if ($this->entity->getEntityType()->hasKey('uuid')) {
// DX: 403 when entity trying to update an entity's UUID field. // DX: 403 when entity trying to update an entity's UUID field.
$request_options[RequestOptions::BODY] = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPatchEntity(), 'uuid'), static::$format);; $request_options[RequestOptions::BODY] = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPatchEntity(), 'uuid'), static::$format);
$response = $this->request('PATCH', $url, $request_options); $response = $this->request('PATCH', $url, $request_options);
$this->assertResourceErrorResponse(403, "Access denied on updating field '{$this->entity->getEntityType()->getKey('uuid')}'. The entity UUID cannot be changed.", $response); $this->assertResourceErrorResponse(403, "Access denied on updating field '{$this->entity->getEntityType()->getKey('uuid')}'. The entity UUID cannot be changed.", $response);
} }

View File

@ -372,7 +372,7 @@ abstract class TermResourceTestBase extends EntityResourceTestBase {
protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) { protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) {
// @see \Drupal\taxonomy\TermAccessControlHandler::checkAccess() // @see \Drupal\taxonomy\TermAccessControlHandler::checkAccess()
return parent::getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) return parent::getExpectedUnauthorizedEntityAccessCacheability($is_authenticated)
->addCacheTags(['taxonomy_term:1']);; ->addCacheTags(['taxonomy_term:1']);
} }
} }

View File

@ -47,7 +47,6 @@ class UpdateLocalTasksTest extends LocalTaskIntegrationTestBase {
$this->assertLocalTasks($route, [ $this->assertLocalTasks($route, [
0 => ['update.module_update'], 0 => ['update.module_update'],
]); ]);
;
} }
/** /**
@ -68,7 +67,6 @@ class UpdateLocalTasksTest extends LocalTaskIntegrationTestBase {
$this->assertLocalTasks($route, [ $this->assertLocalTasks($route, [
0 => ['update.theme_update'], 0 => ['update.theme_update'],
]); ]);
;
} }
/** /**

View File

@ -148,6 +148,7 @@
<!-- Generic sniffs --> <!-- Generic sniffs -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement" />
<rule ref="Generic.Files.ByteOrderMark"/> <rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/> <rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/> <rule ref="Generic.Formatting.SpaceAfterCast"/>

View File

@ -737,7 +737,7 @@ class InstallHelper implements ContainerInjectionInterface {
*/ */
protected function getUser($name) { protected function getUser($name) {
$user_storage = $this->entityTypeManager->getStorage('user'); $user_storage = $this->entityTypeManager->getStorage('user');
$users = $user_storage->loadByProperties(['name' => $name]);; $users = $user_storage->loadByProperties(['name' => $name]);
if (empty($users)) { if (empty($users)) {
// Creating user without any password. // Creating user without any password.
$user = $user_storage->create([ $user = $user_storage->create([

View File

@ -117,7 +117,7 @@ class ConfigDependencyTest extends EntityKernelTestBase {
'type' => 'entity_test', 'type' => 'entity_test',
]); ]);
$entity_test->save(); $entity_test->save();
$entity2->setEnforcedDependencies(['config' => [$entity1->getConfigDependencyName()], 'content' => [$entity_test->getConfigDependencyName()]])->save();; $entity2->setEnforcedDependencies(['config' => [$entity1->getConfigDependencyName()], 'content' => [$entity_test->getConfigDependencyName()]])->save();
$dependents = $config_manager->findConfigEntityDependents('content', [$entity_test->getConfigDependencyName()]); $dependents = $config_manager->findConfigEntityDependents('content', [$entity_test->getConfigDependencyName()]);
$this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on the content entity.'); $this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on the content entity.');
$this->assertTrue(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 has a dependency on the content entity.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 has a dependency on the content entity.');
@ -175,7 +175,7 @@ class ConfigDependencyTest extends EntityKernelTestBase {
// Add a fake missing dependency to ensure multiple missing dependencies // Add a fake missing dependency to ensure multiple missing dependencies
// work. // work.
$entity1->setEnforcedDependencies(['content' => [$entity_test->getConfigDependencyName(), 'entity_test:bundle:uuid']])->save();; $entity1->setEnforcedDependencies(['content' => [$entity_test->getConfigDependencyName(), 'entity_test:bundle:uuid']])->save();
$expected['uuid'] = [ $expected['uuid'] = [
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'bundle' => 'bundle', 'bundle' => 'bundle',

View File

@ -39,7 +39,7 @@ class StreamWrapperTest extends FileTestBase {
parent::setUp(); parent::setUp();
// Add file_private_path setting. // Add file_private_path setting.
$request = Request::create('/');; $request = Request::create('/');
$site_path = DrupalKernel::findSitePath($request); $site_path = DrupalKernel::findSitePath($request);
$this->setSetting('file_private_path', $site_path . '/private'); $this->setSetting('file_private_path', $site_path . '/private');
} }

View File

@ -170,7 +170,7 @@ class FieldDefinitionTest extends UnitTestCase {
*/ */
public function testDefaultFieldSettings($factory_name) { public function testDefaultFieldSettings($factory_name) {
$definition = $this->initializeFieldUsingFactory($factory_name); $definition = $this->initializeFieldUsingFactory($factory_name);
$expected_settings = $this->fieldTypeDefinition['field_settings'] + $this->fieldTypeDefinition['storage_settings'];; $expected_settings = $this->fieldTypeDefinition['field_settings'] + $this->fieldTypeDefinition['storage_settings'];
$this->assertEquals($expected_settings, $definition->getSettings()); $this->assertEquals($expected_settings, $definition->getSettings());
foreach ($expected_settings as $setting => $value) { foreach ($expected_settings as $setting => $value) {
$this->assertEquals($value, $definition->getSetting($setting)); $this->assertEquals($value, $definition->getSetting($setting));

View File

@ -218,7 +218,7 @@ class DefaultHtmlRouteProviderTest extends UnitTestCase {
$entity_type1->hasLinkTemplate('canonical')->willReturn(FALSE); $entity_type1->hasLinkTemplate('canonical')->willReturn(FALSE);
$data['no_canonical_link_template'] = [NULL, $entity_type1->reveal()]; $data['no_canonical_link_template'] = [NULL, $entity_type1->reveal()];
$entity_type2 = $this->getEntityType();; $entity_type2 = $this->getEntityType();
$entity_type2->hasLinkTemplate('canonical')->willReturn(TRUE); $entity_type2->hasLinkTemplate('canonical')->willReturn(TRUE);
$entity_type2->hasViewBuilderClass()->willReturn(FALSE); $entity_type2->hasViewBuilderClass()->willReturn(FALSE);
$data['no_view_builder'] = [NULL, $entity_type2->reveal()]; $data['no_view_builder'] = [NULL, $entity_type2->reveal()];

View File

@ -1477,7 +1477,7 @@ class FormStateDecoratorBaseTest extends UnitTestCase {
$form = $this->getMock(FormInterface::class); $form = $this->getMock(FormInterface::class);
$this->decoratedFormState->setFormObject($form) $this->decoratedFormState->setFormObject($form)
->shouldBeCalled();; ->shouldBeCalled();
$this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormObject($form)); $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormObject($form));
} }

View File

@ -2,8 +2,8 @@
namespace Drupal\Tests\Listeners; namespace Drupal\Tests\Listeners;
use Drupal\KernelTests\KernelTestBase;; use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\BrowserTestBase;; use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\AssertionFailedError;