<?php

declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
    ->in(__DIR__)
    ->exclude('var')
    ->exclude('vendor')
    // Fichiers auto-générés par Symfony/Doctrine
    ->notPath('config/bundles.php')
    ->notPath('config/preload.php')
    ->notPath('config/reference.php')
    ->notPath('src/DataFixtures/AppFixtures.php')
    // Exclusions spécifiques
    ->notPath('src/Shared/Domain/AggregateRoot.php')
    ->notPath('src/Shared/Domain/EntityId.php')
    // Classes that need to be mocked in tests (cannot be final)
    ->notPath('src/Shared/Infrastructure/Tenant/TenantResolver.php')
    // Domain TenantId needs to be extended by Infrastructure alias during migration
    ->notPath('src/Shared/Domain/Tenant/TenantId.php')
;

return (new PhpCsFixer\Config())
    ->setRules([
        '@Symfony' => true,
        '@Symfony:risky' => true,
        'declare_strict_types' => true,
        'strict_param' => true,
        'array_syntax' => ['syntax' => 'short'],
        'ordered_imports' => ['sort_algorithm' => 'alpha'],
        'no_unused_imports' => true,
        'not_operator_with_successor_space' => false,
        'trailing_comma_in_multiline' => true,
        'phpdoc_order' => true,
        'phpdoc_separation' => true,
        'phpdoc_no_empty_return' => true,
        'native_function_invocation' => [
            'include' => ['@compiler_optimized'],
            'scope' => 'namespaced',
            'strict' => true,
        ],
        'native_constant_invocation' => true,
        'global_namespace_import' => [
            'import_classes' => true,
            'import_constants' => true,
            'import_functions' => true,
        ],
        'final_class' => true,
        'class_definition' => [
            'single_line' => true,
        ],
        'concat_space' => [
            'spacing' => 'one',
        ],
        'single_line_throw' => false,
        // NO Yoda conditions
        'yoda_style' => false,
        'blank_line_before_statement' => [
            'statements' => ['return', 'throw', 'try'],
        ],
    ])
    ->setRiskyAllowed(true)
    ->setFinder($finder)
;
