diff --git a/app/Factories/ConfigurationFactory.php b/app/Factories/ConfigurationFactory.php index f6df2454..3a74b7e1 100644 --- a/app/Factories/ConfigurationFactory.php +++ b/app/Factories/ConfigurationFactory.php @@ -44,6 +44,8 @@ public static function preset($rules) { return (new Config()) ->setFinder(self::finder()) + ->setIndent(resolve(ConfigurationJsonRepository::class)->indent()) + ->setLineEnding(resolve(ConfigurationJsonRepository::class)->lineEnding()) ->setRules(array_merge($rules, resolve(ConfigurationJsonRepository::class)->rules())) ->setRiskyAllowed(true) ->setUsingCache(true) diff --git a/app/Repositories/ConfigurationJsonRepository.php b/app/Repositories/ConfigurationJsonRepository.php index f8ad90c4..ea01d197 100644 --- a/app/Repositories/ConfigurationJsonRepository.php +++ b/app/Repositories/ConfigurationJsonRepository.php @@ -2,6 +2,8 @@ namespace App\Repositories; +use PhpCsFixer\Config; + class ConfigurationJsonRepository { /** @@ -39,6 +41,26 @@ public function finder() ->toArray(); } + /** + * Get the indent option. + * + * @return string + */ + public function indent() + { + return $this->get()['indent'] ?? (new Config)->getIndent(); + } + + /** + * Get the line ending option. + * + * @return string + */ + public function lineEnding() + { + return $this->get()['line-ending'] ?? (new Config)->getLineEnding(); + } + /** * Get the rules options. * diff --git a/tests/Fixtures/indent/pint.json b/tests/Fixtures/indent/pint.json new file mode 100644 index 00000000..e13663ab --- /dev/null +++ b/tests/Fixtures/indent/pint.json @@ -0,0 +1,3 @@ +{ + "indent": "\t" +} diff --git a/tests/Fixtures/line-ending/pint.json b/tests/Fixtures/line-ending/pint.json new file mode 100644 index 00000000..1c7d0e7e --- /dev/null +++ b/tests/Fixtures/line-ending/pint.json @@ -0,0 +1,3 @@ +{ + "line-ending": "\r\n" +} diff --git a/tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php b/tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php index 2987151c..f1f72eb7 100644 --- a/tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php +++ b/tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php @@ -41,6 +41,18 @@ ]); }); +it('may have an indent option', function () { + $repository = new ConfigurationJsonRepository(dirname(__DIR__, 2).'/Fixtures/indent/pint.json', null); + + expect($repository->indent())->toBe("\t"); +}); + +it('may have a line ending option', function () { + $repository = new ConfigurationJsonRepository(dirname(__DIR__, 2).'/Fixtures/line-ending/pint.json', null); + + expect($repository->lineEnding())->toBe("\r\n"); +}); + it('may have a preset option', function () { $repository = new ConfigurationJsonRepository(dirname(__DIR__, 2).'/Fixtures/preset/pint.json', null);