Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
62bc7d8
Add coding standards
jcostaventureoak Jul 1, 2025
097ebe7
Remove commands and add to the script
jcostaventureoak Jul 1, 2025
263f253
Merge branch 'main' into KUNGBE-248
jcostaventureoak Jul 1, 2025
0a3c57f
Update the project root
jcostaventureoak Jul 1, 2025
cecaa2f
Merge branch 'KUNGBE-248' of github.com:kununu/code-tools into KUNGBE…
jcostaventureoak Jul 1, 2025
26c2902
Update the project root
jcostaventureoak Jul 1, 2025
870b6ff
Update PHP-CS-Fixer
jcostaventureoak Jul 1, 2025
801e87b
Update code-tools and README
jcostaventureoak Jul 1, 2025
9941e10
Change project to composer-plugin and add commands
jcostaventureoak Jul 2, 2025
fd552b8
Fix code errors
jcostaventureoak Jul 2, 2025
4c138d6
Fix phpstan error
jcostaventureoak Jul 2, 2025
c8c56ec
Update commands
jcostaventureoak Jul 2, 2025
676419d
Fix sonarqube error
jcostaventureoak Jul 2, 2025
ca0028f
Fix error
jcostaventureoak Jul 2, 2025
8580d5c
Update php cs fixer commands
jcostaventureoak Jul 2, 2025
1ed0435
Update args with constants
jcostaventureoak Jul 2, 2025
03efd0f
Fix phpstan
jcostaventureoak Jul 2, 2025
1b31376
Update README file
jcostaventureoak Jul 2, 2025
e7459e5
Update ruleset (from kununu-scripts master)
zibellino Jul 11, 2025
0a5089b
Add .editorconfig to code-tools
jcostaventureoak Jul 17, 2025
a538b8f
Merge branch 'KUNGBE-248' of github.com:kununu/code-tools into KUNGBE…
jcostaventureoak Jul 17, 2025
1f905d2
Add README files
jcostaventureoak Jul 25, 2025
adf7cd1
Merge branch 'main' into KUNGBE-248
jcostaventureoak Jul 25, 2025
016fd6b
Add command to php cs fixer config
jcostaventureoak Jul 25, 2025
9523e37
Remove command for php cs fixer config
jcostaventureoak Jul 25, 2025
bfe4f77
Fix pre-commit hook
jcostaventureoak Jul 25, 2025
d5e27b3
Make the php cs fixer config relative in the symlink
jcostaventureoak Jul 25, 2025
73556f7
Fix _data
jcostaventureoak Jul 28, 2025
381ef87
Fix phpstan suggestion
jcostaventureoak Aug 19, 2025
5a12a6d
improve git-pre-commit
pedropacheco-kununu Aug 19, 2025
ea38bbe
remove override consts
pedropacheco-kununu Aug 19, 2025
f6b709e
Add unit tests
jcostaventureoak Aug 19, 2025
560085b
Merge branch 'KUNGBE-248' of github.com:kununu/code-tools into KUNGBE…
jcostaventureoak Aug 19, 2025
cbf9c8b
Merge remote-tracking branch 'origin/KUNGBE-248' into KUNGBE-248
pedropacheco-kununu Aug 19, 2025
b484829
Revert "remove override consts"
pedropacheco-kununu Aug 19, 2025
c5601fa
Update test
jcostaventureoak Aug 20, 2025
63f63a3
Update test
jcostaventureoak Aug 20, 2025
c7cd106
Add tests
jcostaventureoak Aug 21, 2025
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
118 changes: 118 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
root=true
[*]
charset = utf-8
end_of_line = lf
ij_continuation_indent_size = 4
indent_size = 4
indent_style = space
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true

[{*.php}]
ij_php_align_key_value_pairs = true
ij_php_align_multiline_array_initializer_expression = true
ij_php_align_multiline_chained_methods = true
ij_php_align_multiline_parameters = true
ij_php_align_multiline_parameters_in_calls = true
ij_php_align_phpdoc_comments = true
ij_php_align_phpdoc_param_names = true
ij_php_anonymous_brace_style = end_of_line
ij_php_blank_lines_after_imports = 1
ij_php_blank_lines_after_opening_tag = 0
ij_php_blank_lines_after_package = 1
ij_php_blank_lines_around_method = 1
ij_php_blank_lines_before_method_body = 0
ij_php_blank_lines_before_package = 1
ij_php_blank_lines_before_return_statement = 1
ij_php_blank_lines_between_imports = 1
ij_php_block_brace_style = end_of_line
ij_php_catch_on_new_line = false
ij_php_class_brace_style = next_line
ij_php_comma_after_last_argument = true
ij_php_comma_after_last_argument_style = when_multiline
ij_php_comma_after_last_array_element = true
ij_php_comma_after_last_closure_use_var = true
ij_php_comma_after_last_closure_use_var_style = when_multiline
ij_php_comma_after_last_match_arm = true
ij_php_comma_after_last_parameter = true
ij_php_comma_after_last_parameter_style = when_multiline
ij_php_concat_spaces = true
ij_php_do_while_brace_force = always
ij_php_else_if_style = combine
ij_php_else_on_new_line = false
ij_php_extends_keyword_wrap = off
ij_php_extends_list_wrap = off
ij_php_finally_on_new_line = false
ij_php_for_brace_force = always
ij_php_force_empty_methods_in_one_line = true
ij_php_force_short_declaration_array_style = true
ij_php_if_brace_force = always
ij_php_keep_blank_lines_in_code = 1
ij_php_keep_blank_lines_in_declarations = 1
ij_php_lower_case_boolean_const = true
ij_php_lower_case_keywords = true
ij_php_lower_case_null_const = true
ij_php_method_brace_style = next_line
ij_php_new_line_after_php_opening_tag = true
ij_php_phpdoc_blank_line_before_tags = true
ij_php_phpdoc_blank_lines_around_parameters = true
ij_php_phpdoc_param_spaces_between_name_and_description = 1
ij_php_phpdoc_param_spaces_between_tag_and_type = 1
ij_php_phpdoc_param_spaces_between_type_and_name = 1
ij_php_sort_phpdoc_elements = true
ij_php_space_after_colon = true
ij_php_space_after_colon_in_enum_backed_type = true
ij_php_space_after_colon_in_named_argument = true
ij_php_space_after_colon_in_return_type = true
ij_php_space_after_comma = true
ij_php_space_after_for_semicolon = true
ij_php_space_after_quest = true
ij_php_space_after_type_cast = true
ij_php_space_after_unary_not = false
ij_php_space_before_catch_keyword = true
ij_php_space_before_catch_parentheses = true
ij_php_space_before_colon = true
ij_php_space_before_colon_in_enum_backed_type = false
ij_php_space_before_colon_in_named_argument = false
ij_php_space_before_colon_in_return_type = false
ij_php_space_before_comma = false
ij_php_space_before_else_keyword = true
ij_php_space_before_finally_keyword = true
ij_php_space_before_for_parentheses = true
ij_php_space_before_if_parentheses = true
ij_php_space_before_method_call_parentheses = false
ij_php_space_before_method_parentheses = false
ij_php_space_before_quest = true
ij_php_space_before_switch_parentheses = true
ij_php_space_before_while_keyword = true
ij_php_space_before_while_parentheses = true
ij_php_space_between_ternary_quest_and_colon = false
ij_php_spaces_around_additive_operators = true
ij_php_spaces_around_arrow = false
ij_php_spaces_around_assignment_in_declare = false
ij_php_spaces_around_assignment_operators = true
ij_php_spaces_around_bitwise_operators = true
ij_php_spaces_around_equality_operators = true
ij_php_spaces_around_logical_operators = true
ij_php_spaces_around_multiplicative_operators = true
ij_php_spaces_around_null_coalesce_operator = true
ij_php_spaces_around_pipe_in_union_type = false
ij_php_spaces_around_relational_operators = true
ij_php_spaces_around_shift_operators = true
ij_php_spaces_around_unary_operator = false
ij_php_spaces_around_var_within_brackets = false
ij_php_spaces_within_array_initializer_braces = false
ij_php_spaces_within_brackets = false
ij_php_spaces_within_catch_parentheses = false
ij_php_spaces_within_for_parentheses = false
ij_php_spaces_within_if_parentheses = false
ij_php_spaces_within_method_call_parentheses = false
ij_php_spaces_within_method_parentheses = false
ij_php_spaces_within_parentheses = false
ij_php_spaces_within_switch_parentheses = false
ij_php_spaces_within_while_parentheses = false
ij_php_upper_case_boolean_const = false
ij_php_upper_case_null_const = false
ij_php_while_brace_force = always
ij_php_while_on_new_line = false
144 changes: 144 additions & 0 deletions Kununu/CsFixer/Command/CsFixerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
declare(strict_types=1);

namespace Kununu\CsFixer\Command;

use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;
use Throwable;

final class CsFixerCommand extends BaseCommand
{
public const FAILURE = 1;
public const SUCCESS = 0;

private const ARGUMENT_FILES = 'files';
private const OPTION_CONFIG = 'config';
private const OPTION_EXTRA_ARGS = 'extra-args';

protected function configure(): void
{
$this
->setName('kununu:cs-fixer')
->setAliases(['cs-fixer'])
->setDescription('Applies PHP CS Fixer on specified files or directories.')
->addArgument(
self::ARGUMENT_FILES,
InputArgument::IS_ARRAY,
'Files or directories to fix'
)
->addOption(
self::OPTION_CONFIG,
'c',
InputOption::VALUE_OPTIONAL,
'Path to a PHP CS Fixer config file'
)
->addOption(
self::OPTION_EXTRA_ARGS,
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Additional arguments to pass to PHP CS Fixer'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$files = $input->getArgument(self::ARGUMENT_FILES);

if (empty($files)) {
$io->error('No files or directories were provided.');

return self::FAILURE;
}

$vendorDir = $this->getVendorDir();
if ($vendorDir === null) {
$io->error('Could not resolve the vendor directory.');

return self::FAILURE;
}

$phpCsFixerBinary = $vendorDir . '/bin/php-cs-fixer';

if (!is_file($phpCsFixerBinary) || !is_executable($phpCsFixerBinary)) {
$io->error(sprintf(
'PHP CS Fixer binary not found or not executable at "%s".',
$phpCsFixerBinary
));

return self::FAILURE;
}

$configSource = $input->getOption(self::OPTION_CONFIG) ?: __DIR__ . '/../../../php-cs-fixer.php';
$configPath = realpath($configSource);

if ($configPath === false || !is_file($configPath)) {
$io->error(sprintf('Config file "%s" not found.', $configSource));

return self::FAILURE;
}

$io->note(sprintf('Using config file: %s', $configPath));

$fixerArgs = $input->getOption(self::OPTION_EXTRA_ARGS) ?: [];

if (!empty($fixerArgs)) {
$io->note(sprintf(
'Passing additional fixer arguments: %s',
implode(' ', $fixerArgs)
));
}

$process = new Process(
array_merge(
[$phpCsFixerBinary, 'fix', '--config=' . $configPath],
$fixerArgs,
$files
)
);

$process->setTimeout(null);

$io->section('Running PHP CS Fixer...');

$process->run(static fn($type, $buffer) => $io->write($buffer));

if (!$process->isSuccessful()) {
$io->error('PHP CS Fixer encountered errors.');

return self::FAILURE;
}

$io->success('PHP CS Fixer completed successfully.');

return self::SUCCESS;
}

private function getVendorDir(): ?string
{
try {
$vendorDir = $this->requireComposer()->getConfig()->get('vendor-dir');

if (is_string($vendorDir) && is_dir($vendorDir)) {
$realPath = realpath($vendorDir);

return $realPath !== false ? $realPath : $vendorDir;
}
} catch (Throwable) {
}

$fallback = realpath(__DIR__ . '/../../../../../');
if ($fallback !== false && is_dir($fallback)) {
return $fallback;
}

return null;
}
}
Loading
Loading