Skip to content

Commit

Permalink
Merge pull request #140 from openeuropa/tighten-coding-standards
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea authored Jul 1, 2020
2 parents 4d1884e + c951e51 commit e7cc2fa
Show file tree
Hide file tree
Showing 43 changed files with 320 additions and 179 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"require-dev": {
"openeuropa/code-review": "~1.0.0-beta3",
"phpunit/phpunit": "~6.0||~7.0"
"phpunit/phpunit": "~6.0||~7.0",
"slevomat/coding-standard": "~6.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
imports:
- { resource: vendor/openeuropa/code-review/dist/library-conventions.yml }
parameters:
tasks.phpcs.standard: phpcs.xml
tasks.phpcs.ignore_patterns:
- vendor/
- loadTasks.php
Expand Down
80 changes: 80 additions & 0 deletions phpcs-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<!-- PHP_CodeSniffer ruleset for TaskRunner. -->
<!-- See http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<ruleset name="TaskRunner">
<description>TaskRunner coding standard</description>

<!-- Include the Slevomat sniffs. -->
<rule ref="./vendor/squizlabs/php_codesniffer/src/Standards/PSR12" />
<config name="installed_paths" value="../../slevomat/coding-standard"/>

<!-- Exclude unsupported file types. -->
<exclude-pattern>*.gif</exclude-pattern>
<exclude-pattern>*.less</exclude-pattern>
<exclude-pattern>*.png</exclude-pattern>

<!-- Minified files don't have to comply with coding standards. -->
<exclude-pattern>*.min.css</exclude-pattern>
<exclude-pattern>*.min.js</exclude-pattern>

<!-- Require classes to be documented using docblock comments. -->
<rule ref="PEAR.Commenting.ClassComment.Missing"/>
<rule ref="PEAR.Commenting.ClassComment.WrongStyle"/>
<rule ref="Squiz.CSS.EmptyClassDefinition"/>

<!-- Require the strict types declaration in every PHP file. -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>

<!-- Detect unused use statements. -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>

<!-- Require nullable types to be preceded by the nullability symbol. -->
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>

<!-- Forbid obsolete annotations which are superseded by annotations and version control. -->
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property name="forbiddenAnnotations" type="array">
<element value="@author"/>
<element value="@created"/>
<element value="@copyright"/>
<element value="@license"/>
<element value="@package"/>
<element value="@version"/>
</property>
</properties>
</rule>

<!-- Forbid unhelpful documentation auto-generated by IDEs. -->
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenComments">
<properties>
<property name="forbiddenCommentPatterns" type="array">
<element value="/^Class [a-zA-z]*\.?$/"/>
<element value="/^Interface [a-zA-z]*\.?$/"/>
</property>
</properties>
</rule>

<!-- Enforce correct formatting of type hints for return types. -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>

<!-- Use statements should be ordered alphabetically. -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="caseSensitive" value="true"/>
</properties>
</rule>

<!-- The concatenation operator should be surrounded with a space. -->
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
</ruleset>
7 changes: 7 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="task-runner">
<description>PHP CodeSniffer configuration for TaskRunner.</description>
<rule ref="phpcs-ruleset.xml"/>
<file>src</file>
<file>tests</file>
</ruleset>
10 changes: 5 additions & 5 deletions src/Commands/AbstractCommands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

use Consolidation\AnnotatedCommand\AnnotationData;
Expand All @@ -15,9 +17,7 @@
use Symfony\Component\Console\Input\InputInterface;

/**
* Class AbstractCommands
*
* @package OpenEuropa\TaskRunner\Commands
* Base class for commands.
*/
abstract class AbstractCommands implements BuilderAwareInterface, IOAwareInterface, ConfigAwareInterface
{
Expand All @@ -34,7 +34,7 @@ abstract class AbstractCommands implements BuilderAwareInterface, IOAwareInterfa
*/
public function getConfigurationFile()
{
return __DIR__.'/../../config/commands/base.yml';
return __DIR__ . '/../../config/commands/base.yml';
}

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ public function initializeValuelessOptions(InputInterface $input, AnnotationData
*/
protected function getBin($name)
{
$filename = $this->getConfig()->get('runner.bin_dir').'/'.$name;
$filename = $this->getConfig()->get('runner.bin_dir') . '/' . $name;
if (!file_exists($filename) && !$this->isSimulating()) {
throw new TaskException($this, "Executable '{$filename}' not found.");
}
Expand Down
28 changes: 17 additions & 11 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

use Consolidation\AnnotatedCommand\CommandData;
Expand All @@ -12,7 +14,7 @@
use Symfony\Component\Yaml\Yaml;

/**
* Class DrupalCommands.
* Base class for Drupal commands.
*/
abstract class AbstractDrupalCommands extends AbstractCommands implements FilesystemAwareInterface
{
Expand All @@ -37,7 +39,7 @@ public function getDrupal()
*/
public function getConfigurationFile()
{
return __DIR__.'/../../config/commands/drupal.yml';
return __DIR__ . '/../../config/commands/drupal.yml';
}

/**
Expand Down Expand Up @@ -94,10 +96,11 @@ public function validateSiteInstall(CommandData $commandData)
]);

// Check if required files/folders exist and they are writable.
$requiredFiles = [$siteDirectory, $siteDirectory.'/settings.php'];
$requiredFiles = [$siteDirectory, $siteDirectory . '/settings.php'];
foreach ($requiredFiles as $requiredFile) {
if (file_exists($requiredFile) && !is_writable($requiredFile)) {
throw new \Exception(sprintf('The file/folder %s must be writable for installation to continue.', $requiredFile));
$message = 'The file/folder %s must be writable for installation to continue.';
throw new \Exception(sprintf($message, $requiredFile));
}
}
}
Expand Down Expand Up @@ -162,15 +165,16 @@ public function siteInstall(array $options = [
])
{
if ($options['database-type']) {
$this->io()->warning("Option 'database-type' is deprecated and it will be removed in 1.0.0. Use 'database-scheme' instead.");
$message = "'database-type' is deprecated and will be removed in 1.0.0. Use 'database-scheme' instead.";
$this->io()->warning($message);
$options['database-scheme'] = $options['database-type'];
}
if ($options['config-dir']) {
$this->io()->warning("The 'config-dir' option is deprecated. Use 'existing-config' instead.");
$options['existing-config'] = true;
}

$drush = $this->getConfig()->get('runner.bin_dir').'/drush';
$drush = $this->getConfig()->get('runner.bin_dir') . '/drush';
$task = $this->taskDrush($drush)
->root($options['root'])
->siteName($options['site-name'])
Expand Down Expand Up @@ -312,8 +316,9 @@ public function drushSetup(array $options = [
$yaml = Yaml::dump($config->get('drupal.drush'));

return $this->collectionBuilder()->addTaskList([
$this->taskWriteConfiguration($options['root'].'/sites/default/drushrc.php', $config)->setConfigKey('drupal.drush'),
$this->taskWriteToFile($options['config-dir'].'/drush.yml')->text($yaml),
$this->taskWriteConfiguration($options['root'] . '/sites/default/drushrc.php', $config)
->setConfigKey('drupal.drush'),
$this->taskWriteToFile($options['config-dir'] . '/drush.yml')->text($yaml),
]);
}

Expand Down Expand Up @@ -358,9 +363,10 @@ public function settingsSetup(array $options = [
'skip-permissions-setup' => false,
])
{
$settings_default_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/default.settings.php';
$settings_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/settings.php';
$settings_override_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/' . $options['settings-override-file'];
$base_path = $options['root'] . '/sites/' . $options['sites-subdir'] . '/';
$settings_default_path = $base_path . 'default.settings.php';
$settings_path = $base_path . 'settings.php';
$settings_override_path = $base_path . $options['settings-override-file'];

// Save the filename of the override file in a single variable to use it
// in the heredoc variable $custom_config hereunder.
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/ChangelogCommands.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

use OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use Symfony\Component\Console\Input\InputOption;

/**
* Class ChangelogCommands
*
* @package OpenEuropa\TaskRunner\Commands
* Command for generating a changelog.
*/
class ChangelogCommands extends AbstractCommands implements ComposerAwareInterface
{
Expand All @@ -20,7 +20,7 @@ class ChangelogCommands extends AbstractCommands implements ComposerAwareInterfa
*/
public function getConfigurationFile()
{
return __DIR__.'/../../config/commands/changelog.yml';
return __DIR__ . '/../../config/commands/changelog.yml';
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Drupal7Commands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Drupal8Commands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

/**
Expand Down
11 changes: 2 additions & 9 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<?php

namespace OpenEuropa\TaskRunner\Commands;
declare(strict_types=1);

use Consolidation\AnnotatedCommand\CommandData;
use NuvoleWeb\Robo\Task as NuvoleWebTasks;
use OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface;
use OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks;
use OpenEuropa\TaskRunner\Traits as TaskRunnerTraits;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;
namespace OpenEuropa\TaskRunner\Commands;

/**
* Base class for commands that interact with a Drupal installation.
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/DynamicCommands.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

use OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks;
Expand Down
17 changes: 10 additions & 7 deletions src/Commands/ReleaseCommands.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Commands;

use Gitonomy\Git\Reference\Branch;
use OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use OpenEuropa\TaskRunner\Contract\RepositoryAwareInterface;
use OpenEuropa\TaskRunner\Contract\TimeAwareInterface;
use OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use OpenEuropa\TaskRunner\Contract\ComposerAwareInterface as ComposerAware;
use OpenEuropa\TaskRunner\Contract\RepositoryAwareInterface as RepositoryAware;
use OpenEuropa\TaskRunner\Contract\TimeAwareInterface as TimeAware;
use OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks;
use OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use OpenEuropa\TaskRunner\Traits\RepositoryAwareTrait;
use OpenEuropa\TaskRunner\Traits\TimeAwareTrait;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
Expand All @@ -16,7 +18,7 @@
/**
* Project release commands.
*/
class ReleaseCommands extends AbstractCommands implements ComposerAwareInterface, RepositoryAwareInterface, TimeAwareInterface
class ReleaseCommands extends AbstractCommands implements ComposerAware, RepositoryAware, TimeAware
{
use ComposerAwareTrait;
use RepositoryAwareTrait;
Expand Down Expand Up @@ -139,9 +141,10 @@ private function getVersionString()
$tag = end($tags);

// Resolve local branch name for current HEAD.
$branches = array_filter($repository->getReferences()->getBranches(), function (Branch $branch) use ($revision) {
$filter = function (Branch $branch) use ($revision) {
return $branch->isLocal() && $branch->getRevision() === $revision;
});
};
$branches = array_filter($repository->getReferences()->getBranches(), $filter);
$branch = reset($branches);

// Make sure we always have a version string, i.e. when in detached state.
Expand Down
6 changes: 3 additions & 3 deletions src/Contract/ComposerAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Contract;

use OpenEuropa\TaskRunner\Services\Composer;

/**
* Interface ComposerAwareInterface
*
* @package OpenEuropa\TaskRunner\Contract
* Interface for classes that interact with the composer manifest.
*/
interface ComposerAwareInterface
{
Expand Down
3 changes: 1 addition & 2 deletions src/Contract/ConfigProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace OpenEuropa\TaskRunner\Contract;

use OpenEuropa\TaskRunner\Traits\ConfigFromFilesTrait;
use Robo\Config\Config;

/**
Expand All @@ -31,7 +30,7 @@ interface ConfigProviderInterface
*
* @var string
*/
const DEFAULT_CONFIG_LOCATION = 'openeuropa/taskrunner/runner.yml';
public const DEFAULT_CONFIG_LOCATION = 'openeuropa/taskrunner/runner.yml';

/**
* Adds or overrides configuration.
Expand Down
6 changes: 3 additions & 3 deletions src/Contract/FilesystemAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

declare(strict_types=1);

namespace OpenEuropa\TaskRunner\Contract;

/**
* Interface FilesystemAwareTrait
*
* @package OpenEuropa\TaskRunner\Contract
* Interface for classes that have to interact with the filesystem.
*/
interface FilesystemAwareInterface
{
Expand Down
Loading

0 comments on commit e7cc2fa

Please sign in to comment.