Skip to content

shabananavas/drupal8-coding-standards

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

Guidelines

The KrystalCode Drupal 8 Standards is a set of rules that builds on top of the Drupal 8 coding standards. The main goal is to improve readability.

Classes, properties and methods

Extends and implements

Similarly to PSR-2, implements MUST be split across multiple lines IF the line length exceeds 80 characters.

// commerce_sheets/src/Plugin/QueueWorker/Import.php

class Import extends QueueWorkerBase implements
  ContainerFactoryPluginInterface {
}

Methods

Methods should be ordered based on their visibility i.e. public methods first, protected methods then and private methods at the end.

class MyClass {

  public function myPublicFunction {

  }

  protected function myProtectedFunction {

  }

  private function myPrivateFunction {

  }
}

Method arguments

Similarly to PSR-2, the argument list MUST be split across multiple lines IF the line length exceeds 80 characters.

// commerce_sheets/src/Plugin/QueueWorker/Import.php

/**
 * Constructs a new Import object.
 *
 * @param array $configuration
 *   A configuration array containing information about the plugin instance.
 * @param string $plugin_id
 *   The plugin_id for the plugin instance.
 * @param array $plugin_definition
 *   The plugin implementation definition.
 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
 *   The entity type manager.
 * @param \Psr\Log\LoggerInterface $logger
 *   The Commerce Sheets logger.
 * @param \Drupal\commerce_sheets\Sheet\ReaderInterface $reader
 *   The Commerce Sheets reader service.
 */                                                                   
public function __construct(
  array $configuration,
  $plugin_id,
  array $plugin_definition,
  EntityTypeManagerInterface $entity_type_manager,
  LoggerInterface $logger,
  ReaderInterface $reader
) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);

  $this->importStorage = $entity_type_manager
    ->getStorage('commerce_sheets_import');

  $this->logger = $logger;
  $this->reader = $reader;
}

Code structure

Module files

If the module file grows large, break its content into sections:

  • Hooks
  • Callbacks
  • Public API - functions that constitute a Public API and may be used by other modules; they should remain unchanged for the same major version.
  • Functions for internal use - functions meant to be used only within the scope of the module and its submodules; they are not guaranteed to remain unchanged.
<?php

/**
 * Hooks and functionality for the My Module module.
 */

/**
 * Hooks.
 */

// Hooks here.

/**
 * Callbacks.
 */

// Callbacks here.

/**
 * Public API.
 */

// Public API functions here.

/**
 * Functions for internal use.
 */

// Functions for internal use here.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published