Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Add indent and line-ending options #230

Closed
wants to merge 3 commits into from
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
2 changes: 2 additions & 0 deletions app/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions app/Repositories/ConfigurationJsonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Repositories;

use PhpCsFixer\Config;

class ConfigurationJsonRepository
{
/**
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/indent/pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"indent": "\t"
}
3 changes: 3 additions & 0 deletions tests/Fixtures/line-ending/pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"line-ending": "\r\n"
}
12 changes: 12 additions & 0 deletions tests/Unit/Repositories/ConfigurationJsonRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down