From 4207b307d3436a6eabfed508baaef4df69aad751 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Wed, 6 Sep 2017 10:34:51 +0100 Subject: [PATCH] Issue #2901727 by iainp999, mfernea: Fix 'Drupal.Methods.MethodDeclaration' coding standard --- .../Annotation/Reflection/MockFileFinder.php | 2 +- core/lib/Drupal/Component/Utility/Timer.php | 6 +++--- .../Drupal/Core/Config/Schema/ArrayElement.php | 2 +- .../Drupal/Core/Field/FieldUpdateActionBase.php | 2 +- .../Drupal/Core/FileTransfer/FileTransfer.php | 16 ++++++++-------- .../ImageToolkit/ImageToolkitOperationBase.php | 2 +- .../src/Plugin/Filter/EditorFileReference.php | 2 +- .../destination/ComponentEntityDisplayBase.php | 2 +- .../Plugin/migrate/source/SourcePluginBase.php | 2 +- .../node/src/Plugin/Search/NodeSearch.php | 2 +- .../Cache/GenericCacheBackendUnitTestBase.php | 2 +- .../user/src/Plugin/Search/UserSearch.php | 2 +- .../src/Plugin/views/area/AreaPluginBase.php | 2 +- core/phpcs.xml.dist | 5 +++++ .../Cache/GenericCacheBackendUnitTestBase.php | 2 +- 15 files changed, 28 insertions(+), 23 deletions(-) diff --git a/core/lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php b/core/lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php index 9f585f9119dc..ecfefc371e74 100644 --- a/core/lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php +++ b/core/lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php @@ -30,7 +30,7 @@ public function findFile($class) { /** * Creates new mock file finder objects. */ - static public function create($filename) { + public static function create($filename) { $object = new static(); $object->filename = $filename; return $object; diff --git a/core/lib/Drupal/Component/Utility/Timer.php b/core/lib/Drupal/Component/Utility/Timer.php index b8dc0269764a..4fc36e43aea9 100644 --- a/core/lib/Drupal/Component/Utility/Timer.php +++ b/core/lib/Drupal/Component/Utility/Timer.php @@ -20,7 +20,7 @@ class Timer { * @param $name * The name of the timer. */ - static public function start($name) { + public static function start($name) { static::$timers[$name]['start'] = microtime(TRUE); static::$timers[$name]['count'] = isset(static::$timers[$name]['count']) ? ++static::$timers[$name]['count'] : 1; } @@ -34,7 +34,7 @@ static public function start($name) { * @return int * The current timer value in ms. */ - static public function read($name) { + public static function read($name) { if (isset(static::$timers[$name]['start'])) { $stop = microtime(TRUE); $diff = round(($stop - static::$timers[$name]['start']) * 1000, 2); @@ -57,7 +57,7 @@ static public function read($name) { * A timer array. The array contains the number of times the timer has been * started and stopped (count) and the accumulated timer value in ms (time). */ - static public function stop($name) { + public static function stop($name) { if (isset(static::$timers[$name]['start'])) { $stop = microtime(TRUE); $diff = round(($stop - static::$timers[$name]['start']) * 1000, 2); diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php index b38a94b3c22a..b16cee0aeaaa 100644 --- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php +++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php @@ -48,7 +48,7 @@ protected function parse() { * * @return \Drupal\Core\TypedData\DataDefinitionInterface */ - protected abstract function getElementDefinition($key); + abstract protected function getElementDefinition($key); /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Field/FieldUpdateActionBase.php b/core/lib/Drupal/Core/Field/FieldUpdateActionBase.php index 6714794f1057..03b5255b3701 100644 --- a/core/lib/Drupal/Core/Field/FieldUpdateActionBase.php +++ b/core/lib/Drupal/Core/Field/FieldUpdateActionBase.php @@ -33,7 +33,7 @@ abstract class FieldUpdateActionBase extends ActionBase { * @return array * Array of values with field names as keys. */ - protected abstract function getFieldsToUpdate(); + abstract protected function getFieldsToUpdate(); /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php index 25014f133805..af395a20bbea 100644 --- a/core/lib/Drupal/Core/FileTransfer/FileTransfer.php +++ b/core/lib/Drupal/Core/FileTransfer/FileTransfer.php @@ -115,7 +115,7 @@ abstract public function connect(); * @param string $destination * The destination path. */ - public final function copyDirectory($source, $destination) { + final public function copyDirectory($source, $destination) { $source = $this->sanitizePath($source); $destination = $this->fixRemotePath($destination); $this->checkPath($destination); @@ -136,7 +136,7 @@ public final function copyDirectory($source, $destination) { * * @see http://php.net/chmod */ - public final function chmod($path, $mode, $recursive = FALSE) { + final public function chmod($path, $mode, $recursive = FALSE) { if (!($this instanceof ChmodInterface)) { throw new FileTransferException('Unable to change file permissions'); } @@ -152,7 +152,7 @@ public final function chmod($path, $mode, $recursive = FALSE) { * @param string $directory * The directory to be created. */ - public final function createDirectory($directory) { + final public function createDirectory($directory) { $directory = $this->fixRemotePath($directory); $this->checkPath($directory); $this->createDirectoryJailed($directory); @@ -164,7 +164,7 @@ public final function createDirectory($directory) { * @param string $directory * The directory to be removed. */ - public final function removeDirectory($directory) { + final public function removeDirectory($directory) { $directory = $this->fixRemotePath($directory); $this->checkPath($directory); $this->removeDirectoryJailed($directory); @@ -178,7 +178,7 @@ public final function removeDirectory($directory) { * @param string $destination * The destination file. */ - public final function copyFile($source, $destination) { + final public function copyFile($source, $destination) { $source = $this->sanitizePath($source); $destination = $this->fixRemotePath($destination); $this->checkPath($destination); @@ -191,7 +191,7 @@ public final function copyFile($source, $destination) { * @param string $destination * The destination file to be removed. */ - public final function removeFile($destination) { + final public function removeFile($destination) { $destination = $this->fixRemotePath($destination); $this->checkPath($destination); $this->removeFileJailed($destination); @@ -205,7 +205,7 @@ public final function removeFile($destination) { * * @throws \Drupal\Core\FileTransfer\FileTransferException */ - protected final function checkPath($path) { + final protected function checkPath($path) { $full_jail = $this->chroot . $this->jail; $full_path = drupal_realpath(substr($this->chroot . $path, 0, strlen($full_jail))); $full_path = $this->fixRemotePath($full_path, FALSE); @@ -229,7 +229,7 @@ protected final function checkPath($path) { * @return string * The modified path. */ - protected final function fixRemotePath($path, $strip_chroot = TRUE) { + final protected function fixRemotePath($path, $strip_chroot = TRUE) { $path = $this->sanitizePath($path); $path = preg_replace('|^([a-z]{1}):|i', '', $path); // Strip out windows driveletter if its there. if ($strip_chroot) { diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index c9a93ffe4d3c..dcc3b3d12134 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -166,7 +166,7 @@ protected function validateArguments(array $arguments) { /** * {@inheritdoc} */ - public final function apply(array $arguments) { + final public function apply(array $arguments) { $arguments = $this->prepareArguments($arguments); $arguments = $this->validateArguments($arguments); return $this->execute($arguments); diff --git a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php index cf725a71371d..ad2ac033fad1 100644 --- a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php +++ b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php @@ -50,7 +50,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition /** * {@inheritdoc} */ - static public function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, diff --git a/core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php b/core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php index 660248494e11..eaf3b54da6f9 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php @@ -64,6 +64,6 @@ public function fields(MigrationInterface $migration = NULL) { * @return \Drupal\Core\Entity\Display\EntityDisplayInterface * The entity display object. */ - protected abstract function getEntity($entity_type, $bundle, $mode); + abstract protected function getEntity($entity_type, $bundle, $mode); } diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index cef98823befa..503b1e3d50d0 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -177,7 +177,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition * @return array * An array of the data for this source. */ - protected abstract function initializeIterator(); + abstract protected function initializeIterator(); /** * Gets the module handler. diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 6d7c8eb7d47e..c200f34b6107 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -117,7 +117,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter /** * {@inheritdoc} */ - static public function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php index d47e88a51c37..01fef632839f 100644 --- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -69,7 +69,7 @@ protected function getTestBin() { * @return \Drupal\Core\Cache\CacheBackendInterface * Cache backend to test. */ - protected abstract function createCacheBackend($bin); + abstract protected function createCacheBackend($bin); /** * Allows specific implementation to change the environment before a test run. diff --git a/core/modules/user/src/Plugin/Search/UserSearch.php b/core/modules/user/src/Plugin/Search/UserSearch.php index 063d3ef11225..08ea7241a1bc 100644 --- a/core/modules/user/src/Plugin/Search/UserSearch.php +++ b/core/modules/user/src/Plugin/Search/UserSearch.php @@ -52,7 +52,7 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface { /** * {@inheritdoc} */ - static public function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $container->get('database'), $container->get('entity.manager'), diff --git a/core/modules/views/src/Plugin/views/area/AreaPluginBase.php b/core/modules/views/src/Plugin/views/area/AreaPluginBase.php index 813e4306c098..476a808cd133 100644 --- a/core/modules/views/src/Plugin/views/area/AreaPluginBase.php +++ b/core/modules/views/src/Plugin/views/area/AreaPluginBase.php @@ -107,7 +107,7 @@ public function preRender(array $results) { * @return array * In any case we need a valid Drupal render array to return. */ - public abstract function render($empty = FALSE); + abstract public function render($empty = FALSE); /** * Does that area have nothing to show. diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 1913d89f35d3..5eeb7ce563dc 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -77,6 +77,11 @@ <rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php"/> <rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php"/> <rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php"/> + <rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Methods/MethodDeclarationSniff.php"> + <!-- Silence method name underscore warning which is covered already in + Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps. --> + <exclude name="Drupal.Methods.MethodDeclaration.Underscore"/> + </rule> <rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/NamingConventions/ValidVariableNameSniff.php"> <!-- Sniff for: LowerStart --> <exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/> diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php index 4e57a71f6cdf..0143f868d38e 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php @@ -66,7 +66,7 @@ protected function getTestBin() { * @return \Drupal\Core\Cache\CacheBackendInterface * Cache backend to test. */ - protected abstract function createCacheBackend($bin); + abstract protected function createCacheBackend($bin); /** * Allows specific implementation to change the environment before a test run. -- GitLab