#!/usr/bin/env php
<?php

/**
 * @author Interactiv4 Team
 * @copyright Copyright © Interactiv4 (https://www.interactiv4.com)
 */

use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use Symfony\Component\Finder\Finder;

$finder = Finder::create();

$finder->files()
    ->name('*.php')
    ->exclude('vendor');

$includeDirs = [
    'magento/app/code/Interactiv4',
    'magento/app/design/frontend/Interactiv4',
    'magento/app/design/adminhtml/Interactiv4',
    'magento/lib/Interactiv4',
];

foreach ($includeDirs as $includeDir) {
    if (\file_exists($includeDir) && \is_dir($includeDir)) {
        $finder->in($includeDir);
    }
}

return PhpCsFixer\Config::create()
    ->setFinder($finder)
    ->setCacheFile(__FILE__ . '.cache')
    ->setRules([
        '@PSR12' => true,
        // Skip risky for now
        // '@PSR12:risky' => true,
        '@PHP71Migration' => true,
        // Skip risky for now
        // '@PHP71Migration:risky' => true,
        '@PhpCsFixer' => true,
        // Skip risky for now
        // '@PhpCsFixer:risky' => true,
        '@Symfony' => true,
        // Skip risky for now
        // '@Symfony:risky' => true,
        '@PHPUnit60Migration:risky' => true,
        // Redefine native function invocations to be prefixed
        'native_function_invocation' => [
            'include' => [NativeFunctionInvocationFixer::SET_INTERNAL],
            'scope' => 'all',
            'strict' => true,
        ],
        // Avoid remove params from phpdoc
        'no_superfluous_phpdoc_tags' => false,
        'concat_space' => ['spacing' => 'one'],
        'php_unit_test_class_requires_covers' => false,
        'final_internal_class' => false,
        'class_definition' => ['single_line' => false],
        'single_space_after_construct' => false,
        'phpdoc_no_empty_return' => false,
        // Avoid break docblock templates like /**#@+*/ /**#@-*/
        'multiline_comment_opening_closing' => false,
        // Add manually some risky rules
        // Master functions shall be used instead of aliases.
        'no_alias_functions' => true,
        // A single space or none should be between cast and variable.
        'cast_spaces' => true,
        // Cast should be written in lower case.
        'lowercase_cast' => true,
        // Replaces ``intval``, ``floatval``, ``doubleval``, ``strval`` and ``boolval`` function calls with according type casting operator.
        'modernize_types_casting' => true,
        // Short cast ``bool`` using double exclamation mark should not be used.
        'no_short_bool_cast' => true,
        // Variables must be set ``null`` instead of using ``(unset)`` casting.
        'no_unset_cast' => true,
        // Cast ``(boolean)`` and ``(integer)`` should be written as ``(bool)`` and ``(int)``, ``(double)`` and ``(real)`` as ``(float)``, ``(binary)`` as ``(string)``.
        'short_scalar_cast' => true,
    ]);
