Skip to content

Commit

Permalink
Merge pull request #113 from lemberg/feature/php-codesniffer
Browse files Browse the repository at this point in the history
Add & configure PHP code sniffer
  • Loading branch information
T2L committed Dec 16, 2019
2 parents b83a4fe + 2410ef8 commit 5c48c96
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 19 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ before_script:
script:
- composer validate --no-check-all --ansi
- vagrant status
- ./bin/phpcs
- ./bin/phpunit
- molecule test
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"prefer-stable": true,
"require-dev": {
"composer/composer": "^1.9",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"drupal/coder": "^8.3",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^6.5 | ^7"
},
Expand Down
156 changes: 155 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!-- See http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<ruleset name="Drupal">
<description>Drupal coding standard</description>
<!-- All PHP code files must be UTF-8 encoded and we treat them as such. -->
<arg name="encoding" value="utf-8"/>
<!-- Look for *.php files only. -->
<arg name="extensions" value="php"/>
<!-- Use colors in output. -->
<arg name="colors"/>

<!-- Scan directories with PHP code only. -->
<file>./src/</file>
<file>./tests/</file>

<!-- Include the whole Drupal standard -->
<rule ref="Drupal">
<!--Ignore "Missing short description in doc comment". -->
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
<!--Ignore "Doc comment short description must be on a single line, further text should be a separate paragraph". -->
<exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/>
<!--Ignore "Missing parameter comment". -->
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<!--Ignore "Description for the @return value is missing". -->
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
</rule>

</ruleset>
6 changes: 2 additions & 4 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class App {
];

/**
* @var \Composer\Composer $composer
* @var \Composer\Composer
*/
protected $composer;

/**
* @var \Composer\IO\IOInterface $io
* @var \Composer\IO\IOInterface
*/
protected $io;

Expand All @@ -54,8 +54,6 @@ public function __construct(Composer $composer, IOInterface $io, string $directo
* Pre package uninstall event callback.
*
* @param \Composer\Installer\PackageEvent $event
*
* @return void
*/
public function onPrePackageUninstall(PackageEvent $event): void {
// Clean up Draft Environment config files upon package uninstallation.
Expand Down
6 changes: 1 addition & 5 deletions src/Composer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Plugin implements PluginInterface, EventSubscriberInterface {

/**
* @var \Lemberg\Draft\Environment\App $app
* @var \Lemberg\Draft\Environment\App
*/
protected $app;

Expand All @@ -40,8 +40,6 @@ public static function getSubscribedEvents(): array {
* Pre package uninstall event callback.
*
* @param \Composer\Installer\PackageEvent $event
*
* @return void
*/
public function onPrePackageUninstall(PackageEvent $event): void {
$this->app->onPrePackageUninstall($event);
Expand All @@ -51,8 +49,6 @@ public function onPrePackageUninstall(PackageEvent $event): void {
* Set an app this plugin will be using for the events handling.
*
* @param \Lemberg\Draft\Environment\App $app
*
* @return void
*/
public function setApp(App $app): void {
$this->app = $app;
Expand Down
15 changes: 9 additions & 6 deletions src/Configurer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;

/**
* Draft Environment interactive configurator.
*/
class Configurer {

/**
Expand All @@ -18,21 +21,21 @@ class Configurer {
public static function setUp(Event $event) {
$composer = $event->getComposer();

// This package can be utilized as a root package (for example in Travis CI).
// This package can be used as a root package (for example in Travis CI).
if ($composer->getPackage()->getName() === 'lemberg/draft-environment') {
$installPath = '.';
}
else {
// Use Composer's local repository to find the path to Draft Environment.
$package = $composer
->getRepositoryManager()
->getLocalRepository()
->findPackage('lemberg/draft-environment', '*');
->getRepositoryManager()
->getLocalRepository()
->findPackage('lemberg/draft-environment', '*');

if ($package) {
$installPath = $composer
->getInstallationManager()
->getInstallPath($package);
->getInstallationManager()
->getInstallPath($package);
}
else {
throw new \RuntimeException('lemberg/draft-environment package not found in local repository.');
Expand Down
6 changes: 3 additions & 3 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
class AppTest extends TestCase {

/**
* @var \Composer\Composer $composer
* @var \Composer\Composer
*/
protected $composer;

/**
* @var \Composer\IO\IOInterface $io
* @var \Composer\IO\IOInterface
*/
protected $io;

/**
* @var \Lemberg\Draft\Environment\App $app
* @var \Lemberg\Draft\Environment\App
*/
protected $app;

Expand Down

0 comments on commit 5c48c96

Please sign in to comment.