Skip to content
Merged
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: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"phpstan/phpstan-phpunit": "^2.0.3",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^11.5.2",
"rector/rector": "^2.0.5",
"rector/rector": "^2.0.7",
"rector/type-perfect": "^2.0.1",
"symplify/phpstan-extensions": "^12.0",
"symplify/vendor-patches": "^11.3.7",
Expand Down
6 changes: 4 additions & 2 deletions src/Configuration/ECSConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,20 @@ private function applyEditorConfigSettings(): void
*/
$editorConfig = (new EditorConfigFactory())->load();

if ($editorConfig->indentStyle instanceof IndentStyle) {
if ($editorConfig->indentStyle !== null) {
$this->indentation = match ($editorConfig->indentStyle) {
IndentStyle::Space => Option::INDENTATION_SPACES,
IndentStyle::Tab => Option::INDENTATION_TAB,
default => Option::INDENTATION_SPACES,
};
}

if ($editorConfig->endOfLine instanceof EndOfLine) {
if ($editorConfig->endOfLine !== null) {
$this->lineEnding = match ($editorConfig->endOfLine) {
EndOfLine::Posix => "\n",
EndOfLine::Legacy => "\r",
EndOfLine::Windows => "\r\n",
default => "\n",
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/Configuration/EditorConfig/EditorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class EditorConfig
{
public function __construct(
public readonly ?IndentStyle $indentStyle,
public readonly ?EndOfLine $endOfLine,
public readonly ?string $indentStyle,
public readonly ?string $endOfLine,
public readonly ?bool $trimTrailingWhitespace,
public readonly ?bool $insertFinalNewline,
public readonly ?int $maxLineLength,
public readonly ?QuoteType $quoteType
public readonly ?string $quoteType
) {
}
}
6 changes: 3 additions & 3 deletions src/Configuration/EditorConfig/EditorConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function parse(string $editorConfigFileContents): EditorConfig

// Just letting "validation" happen with PHP's type hints.
return new EditorConfig(
indentStyle: $this->field($config, 'indent_style', IndentStyle::tryFrom(...)),
endOfLine: $this->field($config, 'end_of_line', EndOfLine::tryFrom(...)),
indentStyle: $config['indent_style'] ?? null,
endOfLine: $config['end_of_line'] ?? null,
trimTrailingWhitespace: $this->field($config, 'trim_trailing_whitespace', $this->id(...)),
insertFinalNewline: $this->field($config, 'insert_final_newline', $this->id(...)),
maxLineLength: $this->field($config, 'max_line_length', $this->id(...)),
quoteType: $this->field($config, 'quote_type', QuoteType::tryFrom(...)),
quoteType: $config['quote_type'] ?? null,
);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Configuration/EditorConfig/EndOfLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Symplify\EasyCodingStandard\Configuration\EditorConfig;

enum EndOfLine: string
final class EndOfLine
{
case Posix = 'lf';
case Legacy = 'cr';
case Windows = 'crlf';
public const Posix = 'lf';

public const Legacy = 'cr';

public const Windows = 'crlf';
}
7 changes: 4 additions & 3 deletions src/Configuration/EditorConfig/IndentStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace Symplify\EasyCodingStandard\Configuration\EditorConfig;

enum IndentStyle: string
final class IndentStyle
{
case Space = 'space';
case Tab = 'tab';
public const Space = 'space';

public const Tab = 'tab';
}
10 changes: 6 additions & 4 deletions src/Configuration/EditorConfig/QuoteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
/**
* @see https://github.com/jednano/codepainter#quote_type-single-double-auto
*/
enum QuoteType: string
final class QuoteType
{
case Single = 'single';
case Double = 'double';
case Auto = 'auto';
public const Single = 'single';

public const Double = 'double';

public const Auto = 'auto';
}