Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
},
"scripts": {
"set-phpcs-paths": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility,vendor/magento-ecg/coding-standard",
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs -i"
"OpenMage\\Scripts\\Composer\\SetupPhpCs::run"
],
"post-install-cmd": [
"@set-phpcs-paths"
Expand Down Expand Up @@ -74,6 +73,9 @@
"autoload-dev": {
"psr-4": { "OpenMage\\Tests\\Unit\\": "dev/tests/unit" }
},
"autoload": {
"psr-4": { "OpenMage\\Scripts\\Composer\\": "dev/scripts/composer" }
},
"extra": {
"branch-alias": {
"dev-main": "1.9.4.x-dev"
Expand Down
10 changes: 10 additions & 0 deletions dev/scripts/composer/ScriptInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace OpenMage\Scripts\Composer;

use Composer\Script\Event;

interface ScriptInterface
{
public static function run(Event $event);
}
57 changes: 57 additions & 0 deletions dev/scripts/composer/SetupPhpCs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace OpenMage\Scripts\Composer;

use Composer\Script\Event;

class SetupPhpCs implements ScriptInterface
{
/** @var Composer\Composer $composer */
static $composer;

/** @var string $vendorPath */
static $vendorPath;

/** @var string $binPath */
static $binPath;

private static function init(Event $event)
{
self::$composer = $event->getComposer();
self::$vendorPath = self::$composer->getConfig()->get('vendor-dir');
self::$binPath = self::$composer->getConfig()->get('bin-dir');
}

/**
* Setup PHP_CodeSniffer Environment
*
* @param Event $event
*/
public static function run(Event $event)
{
self::init($event);

if ($event->isDevMode() === false) {
return;
}

if (!function_exists('exec')) {
echo "exec() has been disabled for security reasons, skipping...\n";
return;
}

$phpcs = PHP_BINARY . ' ' . self::$binPath . DIRECTORY_SEPARATOR . 'phpcs';

$paths = implode(',', [
self::$vendorPath . '/phpcompatibility/php-compatibility',
self::$vendorPath . '/magento-ecg/coding-standard',
]);

$output = [];

exec("$phpcs --config-set installed_paths $paths", $output);
exec("$phpcs -i", $output);

echo implode("\n", $output) . "\n";
}
}