From e5c07c5e797a912d347ea358e21093d33aecff76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Tue, 19 Feb 2019 10:00:34 +0100 Subject: [PATCH] Fix execution path --- README.md | 5 ++++- sonar-scanner | 37 +++++++++++-------------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8474e97..f8bd36d 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@

Run SonarQube Scanner with composer

+[![Latest Stable Version](https://poser.pugx.org/rogervila/php-sonarqube-scanner/v/stable)](https://packagist.org/packages/rogervila/php-sonarqube-scanner) +[![Total Downloads](https://poser.pugx.org/rogervila/php-sonarqube-scanner/downloads)](https://packagist.org/packages/rogervila/php-sonarqube-scanner) [![Build Status](https://travis-ci.org/rogervila/php-sonarqube-scanner.svg?branch=master)](https://travis-ci.org/rogervila/php-sonarqube-scanner) [![Build status](https://ci.appveyor.com/api/projects/status/weidwo98jcdrtkxm?svg=true)](https://ci.appveyor.com/project/roger-vila/php-sonarqube-scanner) + # Run SonarQube Scanner with composer ## Usage @@ -11,7 +14,7 @@ **Install the package as a dev requirement** ``` -composer install rogervila/php-sonarqube-scanner --dev +composer require rogervila/php-sonarqube-scanner --dev ``` diff --git a/sonar-scanner b/sonar-scanner index 52a93af..6ad659c 100755 --- a/sonar-scanner +++ b/sonar-scanner @@ -5,35 +5,12 @@ if (!ini_get('date.timezone')) { ini_set('date.timezone', 'UTC'); } -$paths = [ - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php', - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php', - __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php', -]; - -foreach ($paths as $file) { - if (file_exists($file)) { - define('COMPOSER_AUTOLOAD_FILE', $file); - break; - } -} - -$paths = [ - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json', - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json', - __DIR__ . DIRECTORY_SEPARATOR . 'composer.json', -]; +$file = getcwd() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; -foreach ($paths as $file) { - if (file_exists($file)) { - define('COMPOSER_CONFIG_FILE', $file); - break; - } +if (file_exists($file)) { + define('COMPOSER_AUTOLOAD_FILE', $file); } -unset($file); -unset($paths); - if (!defined('COMPOSER_AUTOLOAD_FILE')) { fwrite( STDERR, @@ -45,6 +22,14 @@ if (!defined('COMPOSER_AUTOLOAD_FILE')) { die(1); } +$file = getcwd() . DIRECTORY_SEPARATOR . 'composer.json'; + +if (file_exists($file)) { + define('COMPOSER_CONFIG_FILE', $file); +} + +unset($file); + require COMPOSER_AUTOLOAD_FILE; $app = new \Sonar\Scanner();