Skip to content

Commit

Permalink
(auto): apply php-cs-fixer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FreakyWizard authored and github-actions[bot] committed Nov 20, 2024
1 parent 960bb04 commit 18ef20e
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 303 deletions.
124 changes: 62 additions & 62 deletions config/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,66 @@
declare(strict_types=1);

return [
'line_ending' => "\n",
'risky_allowed' => true,
'set_indent' => "\t",
'rules' => [
'@PSR2' => true,
'indentation_type' => true,
'single_quote' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'continue',
'curly_brace_block',
'parenthesis_brace_block',
],
],
'not_operator_with_successor_space' => true,
'logical_operators' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'phpdoc_var_without_name' => true,
'phpdoc_single_line_var_spacing' => true,
'unary_operator_spaces' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'no_superfluous_elseif' => true,
'single_blank_line_before_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_separation' => true,
'method_chaining_indentation' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'single_space',
'|' => 'single_space',
],
],
'return_type_declaration' => [
'space_before' => 'none',
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'full_opening_tag' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
'identical' => true,
'less_and_greater' => true,
],
'declare_strict_types' => true,
],
'line_ending' => "\n",
'risky_allowed' => true,
'set_indent' => "\t",
'rules' => [
'@PSR2' => true,
'indentation_type' => true,
'single_quote' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'continue',
'curly_brace_block',
'parenthesis_brace_block',
],
],
'not_operator_with_successor_space' => true,
'logical_operators' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'phpdoc_var_without_name' => true,
'phpdoc_single_line_var_spacing' => true,
'unary_operator_spaces' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'no_superfluous_elseif' => true,
'single_blank_line_before_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_separation' => true,
'method_chaining_indentation' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'single_space',
'|' => 'single_space',
],
],
'return_type_declaration' => [
'space_before' => 'none',
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'full_opening_tag' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
'identical' => true,
'less_and_greater' => true,
],
'declare_strict_types' => true,
],
];
69 changes: 34 additions & 35 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,51 @@

class Config extends \PhpCsFixer\Config implements ConfigInterface
{
use Helpers;
use Helpers;

private function __construct(string $name)
{
parent::__construct($name);
}
private function __construct(string $name)
{
parent::__construct($name);
}

public static function create(Finder $finder, string $name = 'default'): self
{
$config = new self($name);
public static function create(Finder $finder, string $name = 'default'): self
{
$config = new self($name);

$config->setFinder($finder);
$config->setDefaultRules();
$config->setFinder($finder);
$config->setDefaultRules();

return $config;
}
return $config;
}

public function setDefaultRules(): self
{

$this->setRules($this->configRule('rules', []))
->setLineEnding($this->configRule('line_ending', "\n"))
->setRiskyAllowed($this->configRule('risky_allowed', true))
public function setDefaultRules(): self
{
$this->setRules($this->configRule('rules', []))
->setLineEnding($this->configRule('line_ending', "\n"))
->setRiskyAllowed($this->configRule('risky_allowed', true))
->setIndent($this->configRule('set_indent', "\t"));

return $this;
}
return $this;
}

public function mergeRules(array $rules): self
{
$this->setRules(\Ckr\Util\ArrayMerger::doMerge($this->getRules(), $rules));
public function mergeRules(array $rules): self
{
$this->setRules(\Ckr\Util\ArrayMerger::doMerge($this->getRules(), $rules));

return $this;
}
return $this;
}

public function removeRules(array $rulesKeys): self
{
$rules = $this->getRules();
public function removeRules(array $rulesKeys): self
{
$rules = $this->getRules();

$this->setRules(array_diff_key($rules, array_flip($rulesKeys)));
$this->setRules(array_diff_key($rules, array_flip($rulesKeys)));

return $this;
}
return $this;
}

public function removeRule(string $ruleKey): self
{
return $this->removeRules([$ruleKey]);
}
public function removeRule(string $ruleKey): self
{
return $this->removeRules([$ruleKey]);
}
}
58 changes: 29 additions & 29 deletions src/Interfaces/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@

interface ConfigInterface extends \PhpCsFixer\ConfigInterface
{
/**
* Creates default PHP CS fixer config. Calls setDefaultSettings()
*/
public static function create(Finder $finder, string $name = 'default'): self;

/**
* Sets rules, line ending and risky allowed
*/
public function setDefaultRules(): self;

/**
* Recursively merges provided rules with current rules.
* Allows default rules to be overridden.
*
* @param array<string, array<string, mixed>|bool> $rules
*/
public function mergeRules(array $rules): self;

/**
* Unset matching rules
*
* @param array<int, string> $rulesKeys
*/
public function removeRules(array $rulesKeys): self;

/**
* Removes rule name
*/
public function removeRule(string $ruleKey): self;
/**
* Creates default PHP CS fixer config. Calls setDefaultSettings()
*/
public static function create(Finder $finder, string $name = 'default'): self;

/**
* Sets rules, line ending and risky allowed
*/
public function setDefaultRules(): self;

/**
* Recursively merges provided rules with current rules.
* Allows default rules to be overridden.
*
* @param array<string, array<string, mixed>|bool> $rules
*/
public function mergeRules(array $rules): self;

/**
* Unset matching rules
*
* @param array<int, string> $rulesKeys
*/
public function removeRules(array $rulesKeys): self;

/**
* Removes rule name
*/
public function removeRule(string $ruleKey): self;
}
52 changes: 26 additions & 26 deletions src/Traits/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@

trait Helpers
{
/**
* Get specified configuration value.
*
* @param string $configFile filename of config file
* @param string $key key of config array
*/
public function config(string $configFile, string $key, mixed $default = null): mixed
{
$path = __DIR__ . "/../../config/{$configFile}.php";

Assert::fileExists($path, 'provided config file does not exist');

$config = require $path;

return $config[$key] ?? $default;
}

/**
* Get specified rule from configuration.
*
* @param string $key key of config array
*/
public function configRule(string $key, mixed $default = null): mixed
{
return $this->config('rules', $key, $default);
}
/**
* Get specified configuration value.
*
* @param string $configFile filename of config file
* @param string $key key of config array
*/
public function config(string $configFile, string $key, mixed $default = null): mixed
{
$path = __DIR__ . "/../../config/{$configFile}.php";

Assert::fileExists($path, 'provided config file does not exist');

$config = require $path;

return $config[$key] ?? $default;
}

/**
* Get specified rule from configuration.
*
* @param string $key key of config array
*/
public function configRule(string $key, mixed $default = null): mixed
{
return $this->config('rules', $key, $default);
}
}
Loading

0 comments on commit 18ef20e

Please sign in to comment.