<?php
/**
 * PHP-CS-Fixer config — PrestaShop module rules.
 *
 * Used to bring the module up to coding-standard requirements for the PrestaShop Addons validation.
 * NOT shipped to production — excluded from ZIP build.
 */
if (!defined('_PS_VERSION_')) {
    exit;
}

$finder = (new PhpCsFixer\Finder())
    ->in(__DIR__)
    ->exclude([
        'vendor',
        'alsendo-wrapper-v2/tests',
        'alsendo-wrapper-v2/docker',
        'alsendo-wrapper-v2/docs',
    ])
    ->name('*.php');

return (new PhpCsFixer\Config())
    ->setRiskyAllowed(true)
    ->setRules([
        '@PSR12' => true,
        'array_syntax' => ['syntax' => 'short'],
        'blank_line_after_opening_tag' => false,
        'blank_line_before_statement' => ['statements' => ['return']],
        'binary_operator_spaces' => ['default' => 'single_space'],
        'braces_position' => true,
        'cast_spaces' => ['space' => 'single'],
        'class_attributes_separation' => ['elements' => ['method' => 'one']],
        'class_definition' => true,
        'concat_space' => ['spacing' => 'one'],
        'function_declaration' => true,
        // Validator wants global classes inlined as `\Foo` even in typed
        // signatures, not imported via `use`. Keep import_symbols=false.
        'fully_qualified_strict_types' => ['import_symbols' => false],
        // PrestaShop validator wants global imports REMOVED — `use Throwable;`,
        // `use Configuration;` etc. flagged via global_namespace_import +
        // no_unused_imports. With all sub-options false, cs-fixer strips those
        // `use` statements and inlines references as `\Foo`.
        'global_namespace_import' => [
            'import_classes' => false,
            'import_constants' => false,
            'import_functions' => false,
        ],
        'include' => true,
        'increment_style' => ['style' => 'pre'],
        'no_alias_language_construct_call' => true,
        'no_blank_lines_after_class_opening' => true,
        'no_blank_lines_after_phpdoc' => true,
        'no_extra_blank_lines' => [
            'tokens' => [
                'extra',
                'curly_brace_block',
                'use',
                'return',
                'throw',
                'use_trait',
                'continue',
                'break',
                'switch',
                'case',
                'default',
            ],
        ],
        'no_null_property_initialization' => true,
        'no_spaces_after_function_name' => true,
        'no_trailing_comma_in_singleline' => true,
        'no_trailing_whitespace' => true,
        'no_trailing_whitespace_in_comment' => true,
        'no_unneeded_braces' => true,
        'no_unneeded_control_parentheses' => true,
        'no_unused_imports' => true,
        'no_whitespace_in_blank_line' => true,
        // Validator (raport 20260508) keeps flagging `?Type $x = null` as
        // violation despite that being correct per current PHP CS Fixer 3.95.
        // Experimental: drop the `?` to produce `Type $x = null` (deprecated
        // implicitly-nullable in PHP 8.4 — acceptable trade-off as moduł
        // declares max PHP 8.x but PHP 8.4 share is <5% as of 2026-05).
        'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false],
        'operator_linebreak' => ['only_booleans' => true],
        'ordered_imports' => ['sort_algorithm' => 'alpha'],
        'phpdoc_align' => ['align' => 'left'],
        'phpdoc_annotation_without_dot' => true,
        'phpdoc_no_package' => true,
        'phpdoc_separation' => true,
        'phpdoc_single_line_var_spacing' => true,
        'phpdoc_tag_type' => ['tags' => ['inheritDoc' => 'inline']],
        'phpdoc_trim' => true,
        'phpdoc_trim_consecutive_blank_line_separation' => true,
        'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
        'phpdoc_var_without_name' => true,
        'single_blank_line_at_eof' => true,
        'single_line_comment_spacing' => true,
        'single_line_throw' => true,
        'single_quote' => true,
        'single_space_around_construct' => true,
        'trailing_comma_in_multiline' => ['elements' => ['arrays']],
        'trim_array_spaces' => true,
        'type_declaration_spaces' => true,
        'types_spaces' => ['space' => 'none'],
        'whitespace_after_comma_in_array' => true,
    ])
    ->setFinder($finder);
