Skip to content

Commit

Permalink
Merge pull request #438 from jhedstrom/338-coding-standards
Browse files Browse the repository at this point in the history
Enforce coding standards
  • Loading branch information
jhedstrom committed Dec 6, 2017
2 parents ca50162 + d72c88c commit ff385ab
Show file tree
Hide file tree
Showing 65 changed files with 2,113 additions and 1,840 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -83,6 +83,8 @@ before_script:

script:
- vendor/bin/parallel-lint src spec features fixtures
- vendor/bin/phpcs --standard=./phpcs-ruleset.xml -p
- vendor/bin/phpcs --standard=./phpcs-drupal-ruleset.xml -p
- vendor/bin/phpspec run -f pretty --no-interaction
- vendor/bin/behat -fprogress --strict
- vendor/bin/behat -fprogress --profile=drupal${DRUPAL_VERSION} --strict
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -27,7 +27,8 @@
"phpspec/phpspec": "~2.0",
"phpunit/phpunit": "3.7.*",
"behat/mink-zombie-driver": "^1.2",
"jakub-onderka/php-parallel-lint": "^0.9.2"
"jakub-onderka/php-parallel-lint": "^0.9.2",
"drupal/coder": "^8.2"
},
"autoload": {
"psr-0": {
Expand Down
5 changes: 5 additions & 0 deletions fixtures/drupal6/modules/behat_test/behat_test.install
@@ -1,5 +1,10 @@
<?php

/**
* @file
* Install hooks for the behat_test module.
*/

/**
* Implements hook_install().
*/
Expand Down
5 changes: 5 additions & 0 deletions fixtures/drupal6/modules/behat_test/behat_test.module
@@ -1 +1,6 @@
<?php

/**
* @file
* Intentionally empty file.
*/
@@ -1,4 +1,5 @@
<?php

/**
* @file
* behat_test.features.field_base.inc
Expand All @@ -10,7 +11,7 @@
function behat_test_field_default_field_bases() {
$field_bases = array();

// Exported field_base: 'body'
// Exported field_base: 'body'.
$field_bases['body'] = array(
'active' => 1,
'cardinality' => 1,
Expand Down Expand Up @@ -39,7 +40,7 @@ function behat_test_field_default_field_bases() {
'type' => 'text_with_summary',
);

// Exported field_base: 'field_post_address'
// Exported field_base: 'field_post_address'.
$field_bases['field_post_address'] = array(
'active' => 1,
'cardinality' => 2,
Expand All @@ -54,7 +55,7 @@ function behat_test_field_default_field_bases() {
'type' => 'addressfield',
);

// Exported field_base: 'field_post_date'
// Exported field_base: 'field_post_date'.
$field_bases['field_post_date'] = array(
'active' => 1,
'cardinality' => 1,
Expand Down Expand Up @@ -84,7 +85,7 @@ function behat_test_field_default_field_bases() {
'type' => 'datetime',
);

// Exported field_base: 'field_post_dates'
// Exported field_base: 'field_post_dates'.
$field_bases['field_post_dates'] = array(
'active' => 1,
'cardinality' => 1,
Expand Down Expand Up @@ -114,7 +115,7 @@ function behat_test_field_default_field_bases() {
'type' => 'datetime',
);

// Exported field_base: 'field_post_links'
// Exported field_base: 'field_post_links'.
$field_bases['field_post_links'] = array(
'active' => 1,
'cardinality' => -1,
Expand Down Expand Up @@ -144,7 +145,7 @@ function behat_test_field_default_field_bases() {
'type' => 'link_field',
);

// Exported field_base: 'field_post_reference'
// Exported field_base: 'field_post_reference'.
$field_bases['field_post_reference'] = array(
'active' => 1,
'cardinality' => -1,
Expand Down Expand Up @@ -175,7 +176,7 @@ function behat_test_field_default_field_bases() {
'type' => 'entityreference',
);

// Exported field_base: 'field_post_select'
// Exported field_base: 'field_post_select'.
$field_bases['field_post_select'] = array(
'active' => 1,
'cardinality' => -1,
Expand All @@ -202,7 +203,7 @@ function behat_test_field_default_field_bases() {
'type' => 'list_text',
);

// Exported field_base: 'field_tags'
// Exported field_base: 'field_tags'.
$field_bases['field_tags'] = array(
'active' => 1,
'cardinality' => -1,
Expand Down
@@ -1,4 +1,5 @@
<?php

/**
* @file
* behat_test.features.field_instance.inc
Expand All @@ -10,7 +11,7 @@
function behat_test_field_default_field_instances() {
$field_instances = array();

// Exported field_instance: 'node-post-body'
// Exported field_instance: 'node-post-body'.
$field_instances['node-post-body'] = array(
'bundle' => 'post',
'default_value' => NULL,
Expand Down Expand Up @@ -54,7 +55,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_address'
// Exported field_instance: 'node-post-field_post_address'.
$field_instances['node-post-field_post_address'] = array(
'bundle' => 'post',
'default_value' => NULL,
Expand Down Expand Up @@ -109,7 +110,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_date'
// Exported field_instance: 'node-post-field_post_date'.
$field_instances['node-post-field_post_date'] = array(
'bundle' => 'post',
'deleted' => 0,
Expand Down Expand Up @@ -162,7 +163,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_dates'
// Exported field_instance: 'node-post-field_post_dates'.
$field_instances['node-post-field_post_dates'] = array(
'bundle' => 'post',
'deleted' => 0,
Expand Down Expand Up @@ -215,7 +216,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_links'
// Exported field_instance: 'node-post-field_post_links'.
$field_instances['node-post-field_post_links'] = array(
'bundle' => 'post',
'default_value' => NULL,
Expand Down Expand Up @@ -272,7 +273,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_reference'
// Exported field_instance: 'node-post-field_post_reference'.
$field_instances['node-post-field_post_reference'] = array(
'bundle' => 'post',
'default_value' => NULL,
Expand Down Expand Up @@ -311,7 +312,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'node-post-field_post_select'
// Exported field_instance: 'node-post-field_post_select'.
$field_instances['node-post-field_post_select'] = array(
'bundle' => 'post',
'default_value' => NULL,
Expand Down Expand Up @@ -348,7 +349,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'user-user-field_post_address'
// Exported field_instance: 'user-user-field_post_address'.
$field_instances['user-user-field_post_address'] = array(
'bundle' => 'user',
'default_value' => NULL,
Expand Down Expand Up @@ -397,7 +398,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'user-user-field_post_reference'
// Exported field_instance: 'user-user-field_post_reference'.
$field_instances['user-user-field_post_reference'] = array(
'bundle' => 'user',
'default_value' => NULL,
Expand Down Expand Up @@ -430,7 +431,7 @@ function behat_test_field_default_field_instances() {
),
);

// Exported field_instance: 'user-user-field_tags'
// Exported field_instance: 'user-user-field_tags'.
$field_instances['user-user-field_tags'] = array(
'bundle' => 'user',
'default_value' => NULL,
Expand Down
@@ -1,4 +1,5 @@
<?php

/**
* @file
* behat_test.features.inc
Expand Down
@@ -1,4 +1,5 @@
<?php

/**
* @file
* behat_test.features.taxonomy.inc
Expand Down
@@ -1,4 +1,5 @@
<?php

/**
* @file
* behat_test.features.user_permission.inc
Expand Down
1 change: 1 addition & 0 deletions fixtures/drupal7/modules/behat_test/behat_test.module
@@ -1,4 +1,5 @@
<?php

/**
* @file
* Code for the Behat test feature.
Expand Down
2 changes: 0 additions & 2 deletions fixtures/drupal8/modules/behat_test/behat_test.info.yml
Expand Up @@ -2,8 +2,6 @@ name: Behat test
type: module
description: 'Test feature exposing basic configuration for Behat Drupal extension test.'
package: Test
version: '8.x-1.x-dev'
core: '8.x'
project: 'behat_test'
dependencies:
- language
11 changes: 8 additions & 3 deletions fixtures/drupal8/modules/behat_test/behat_test.install
@@ -1,20 +1,25 @@
<?php

/**
* Implements hook_install()
* @file
* Install hooks for the behat_test module.
*/

/**
* Implements hook_install().
*/
function behat_test_install() {
$storage = \Drupal::service('behat_test.config.storage.install');

// Override Standard profile's user settings with our own.
$config_names = array(
$config_names = [
'core.entity_form_mode.user.register',
'core.entity_form_display.user.user.default',
'core.entity_view_display.user.user.default',
'core.entity_view_display.user.user.compact',
'core.entity_view_mode.user.compact',
'core.entity_view_mode.user.full',
);
];

foreach ($config_names as $config_name) {
$data = $storage->read($config_name);
Expand Down
Expand Up @@ -2,4 +2,3 @@ services:
behat_test.config.storage.install:
class: Drupal\behat_test\Config\BehatTestExtensionInstallStorage
arguments: ['@config.storage', 'config/install']

@@ -1,16 +1,14 @@
<?php

/**
* @file
* Contains \Drupal\behat_test\Config\BehatTestExtensionInstallStorage
*/

namespace Drupal\behat_test\Config;

use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Extension\ExtensionDiscovery;

/**
* Finds module folders.
*/
class BehatTestExtensionInstallStorage extends ExtensionInstallStorage {

/**
Expand All @@ -29,7 +27,7 @@ protected function getAllFolders() {
if (!isset($this->folders)) {
$listing = new ExtensionDiscovery(\Drupal::root());
$modules = $listing->scan('module');
$this->folders = $this->getComponentNames(array('behat_test' => $modules['behat_test']));
$this->folders = $this->getComponentNames(['behat_test' => $modules['behat_test']]);
}
return $this->folders;
}
Expand Down
@@ -1,10 +1,5 @@
<?php

/**
* @file
* Contains Drupal\behat_test\Plugin\Field\FieldFormatter\AddressFieldFormatter.
*/

namespace Drupal\behat_test\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldDefinitionInterface;
Expand All @@ -31,7 +26,7 @@ class AddressFieldFormatter extends FormatterBase implements ContainerFactoryPlu
/**
* The country manager.
*
* @var \Drupal\Core\Locale\CountryManagerInterface;
* @var \Drupal\Core\Locale\CountryManagerInterface
*/
protected $countryManager;

Expand Down
@@ -1,10 +1,5 @@
<?php

/**
* @file
* Contains \Drupal\behat_test\Plugin\Field\FieldType\AddressFieldItem.
*/

namespace Drupal\behat_test\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;
Expand Down
@@ -1,10 +1,5 @@
<?php

/**
* @file
* Contains \Drupal\behat_test\Plugin\field\widget\AddressFieldWidget.
*/

namespace Drupal\behat_test\Plugin\Field\FieldWidget;

use Drupal\Core\Field\FieldItemListInterface;
Expand Down
19 changes: 19 additions & 0 deletions phpcs-drupal-ruleset.xml
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- PHP_CodeSniffer standard -->
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<ruleset name="drupal/drupal-extension-fixtures">
<description>Drupal Behat Extension coding standards for packaged Drupal code</description>

<file>./fixtures</file>

<exclude-pattern>^/doc/*</exclude-pattern>
<exclude-pattern>^/drupal/*</exclude-pattern>
<exclude-pattern>^/drush/*</exclude-pattern>
<exclude-pattern>^/reports/*</exclude-pattern>
<exclude-pattern>^/spec/*</exclude-pattern>
<exclude-pattern>^/vendor/*</exclude-pattern>
<exclude-pattern>^/README.md</exclude-pattern>

<rule ref="./vendor/drupal/coder/coder_sniffer/Drupal"></rule>

</ruleset>
23 changes: 23 additions & 0 deletions phpcs-ruleset.xml
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!-- PHP_CodeSniffer standard -->
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<ruleset name="drupal/drupal-extension">
<description>Drupal Behat Extension coding standards</description>

<file>./src</file>

<exclude-pattern>^/doc/*</exclude-pattern>
<exclude-pattern>^/drupal/*</exclude-pattern>
<exclude-pattern>^/drush/*</exclude-pattern>
<exclude-pattern>^/fixtures/*</exclude-pattern>
<exclude-pattern>^/reports/*</exclude-pattern>
<exclude-pattern>^/spec/*</exclude-pattern>
<exclude-pattern>^/vendor/*</exclude-pattern>
<exclude-pattern>^/README.md</exclude-pattern>

<rule ref="PSR2">
<!-- @todo Fix long line length issues -->
<exclude name="Generic.Files.LineLength.TooLong" />
</rule>

</ruleset>

0 comments on commit ff385ab

Please sign in to comment.