diff --git a/composer.json b/composer.json index 91374e70bb4..fe61c403497 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -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" diff --git a/dev/scripts/composer/ScriptInterface.php b/dev/scripts/composer/ScriptInterface.php new file mode 100644 index 00000000000..683769e0353 --- /dev/null +++ b/dev/scripts/composer/ScriptInterface.php @@ -0,0 +1,10 @@ +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"; + } +}