diff --git a/composer.json b/composer.json index 592c317..ad001b0 100644 --- a/composer.json +++ b/composer.json @@ -1,70 +1,72 @@ { - "name": "worksome/graphlint", - "description": "A static analysis tool for GraphQl", - "type": "project", - "require": { - "php": "^8.2", - "webonyx/graphql-php": "^15.0.1", - "symfony/console": "^6.1", - "illuminate/support": "^10.0", - "symfony/dependency-injection": "^6.0", - "symfony/http-kernel": "^6.0", - "symfony/config": "^6.0", - "symplify/autowire-array-parameter": "^11.0", - "symplify/package-builder": "^11.0", - "thecodingmachine/safe": "^2.4", - "jawira/case-converter": "^3.5" - }, - "require-dev": { - "pestphp/pest": "^2.34", - "symfony/var-dumper": "^6.4", - "symplify/easy-testing": "^11.0", - "worksome/coding-style": "^2.10.2" - }, - "license": "MIT", - "autoload": { - "psr-4": { - "Worksome\\Graphlint\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Worksome\\Graphlint\\Tests\\": "tests/" - } - }, - "bin": [ - "bin/graphlint" - ], - "authors": [ - { - "name": "Oliver Nybroe", - "email": "oliver@worksome.com" - } - ], - "config": { - "allow-plugins": { - "pestphp/pest-plugin": true, - "dealerdirect/phpcodesniffer-composer-installer": true, - "worksome/coding-style": true - } - }, - "scripts": { - "ecs": "vendor/bin/ecs", - "ecs:fix": "vendor/bin/ecs --fix", - "phpstan": "vendor/bin/phpstan analyse", - "rector": "vendor/bin/rector process --dry-run --ansi", - "rector:fix": "vendor/bin/rector process --ansi", - "pest": "vendor/bin/pest --parallel", - "test": [ - "@ecs", - "@phpstan", - "@rector", - "@pest" - ] - }, - "suggest": { - "ext-dom": "Required for Checkstyle output format." - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "worksome/graphlint", + "description": "A static analysis tool for GraphQl", + "type": "project", + "require": { + "php": "^8.2", + "illuminate/support": "^10.0", + "jawira/case-converter": "^3.5", + "symfony/config": "^6.0", + "symfony/console": "^6.1", + "symfony/dependency-injection": "^6.0", + "symfony/filesystem": "^6.4", + "symfony/http-kernel": "^6.0", + "symplify/autowire-array-parameter": "^11.0", + "symplify/package-builder": "^11.0", + "thecodingmachine/safe": "^2.4", + "webonyx/graphql-php": "^15.0.1" + }, + "require-dev": { + "pestphp/pest": "^2.34", + "symfony/var-dumper": "^6.4", + "symplify/easy-testing": "^11.0", + "worksome/coding-style": "^2.10.2" + }, + "license": "MIT", + "autoload": { + "psr-4": { + "Worksome\\Graphlint\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Worksome\\Graphlint\\Tests\\": "tests/" + } + }, + "bin": [ + "bin/graphlint" + ], + "authors": [ + { + "name": "Oliver Nybroe", + "email": "oliver@worksome.com" + } + ], + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "worksome/coding-style": true + } + }, + "scripts": { + "ecs": "vendor/bin/ecs", + "ecs:fix": "vendor/bin/ecs --fix", + "phpstan": "vendor/bin/phpstan analyse", + "rector": "vendor/bin/rector process --dry-run --ansi", + "rector:fix": "vendor/bin/rector process --ansi", + "pest": "vendor/bin/pest --parallel", + "test": [ + "@ecs", + "@phpstan", + "@rector", + "@pest" + ] + }, + "suggest": { + "ext-dom": "Required for Checkstyle output format." + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Commands/AnalyseCommand.php b/src/Commands/AnalyseCommand.php index c428185..d647f2b 100644 --- a/src/Commands/AnalyseCommand.php +++ b/src/Commands/AnalyseCommand.php @@ -14,12 +14,14 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Filesystem\Path; use Symplify\PackageBuilder\Console\Output\ConsoleDiffer; use Worksome\Graphlint\EmptyDocumentNode; use Worksome\Graphlint\Graphlint; use Worksome\Graphlint\Kernel; use Worksome\Graphlint\Listeners\CheckstyleListener; use Worksome\Graphlint\Listeners\ConsolePrinterListener; +use Worksome\Graphlint\ShouldNotHappenException; use function Safe\file_get_contents; @@ -49,17 +51,24 @@ protected function configure(): void $this->addOption( self::INPUT, null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'The format for the schema inputs.', InputFormat::FILE->value, ); $this->addOption( self::FORMAT, null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'The output format.', OutputFormat::Text->value, ); + $this->addOption( + 'configuration', + 'c', + InputOption::VALUE_REQUIRED, + 'The configuration file.', + 'graphlint.php', + ); } /** @throws SyntaxError|FilesystemException|JsonException */ @@ -70,10 +79,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output ); - $configurationFile = getcwd() . DIRECTORY_SEPARATOR . 'graphlint.php'; + $currentWorkingDirectory = getcwd(); + if ($currentWorkingDirectory === false) { + throw new ShouldNotHappenException(); + } + + /** @var string $configurationFile */ + $configurationFile = $input->getOption('configuration'); + + /** @var non-empty-string $configurationFile */ + $configurationFile = Path::makeAbsolute($configurationFile, $currentWorkingDirectory); if (! is_file($configurationFile) || ! is_readable($configurationFile)) { - $style->error("Unable to find a \"graphlint.php\" configuration file in your current directory."); + $style->error("Unable to find a \"{$configurationFile}\" configuration file."); return self::FAILURE; }