<commit_before><?php

namespace DRI\SugarCRM\Console\Generator;
use Symfony\Component\Filesystem\Filesystem;

/**
 * This file is part of the DRI Sugar CRM Module Creator library
 *
 * Copyright (c) 2013 <NAME>, DRI Nordic
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license MIT
 *   See LICENSE shipped with this library.
 */
class ModuleCreator
{
    /**
     * @var array
     */
    private static $arguments = array (
        'assignable' => false,
        'team_security' => false,
        'force' => false,
        'help' => false,
        'audited' => false,
        'dry' => false,
        'importable' => false,
        'template' => 'basic',
        'template_class_name' => 'Basic',
        'templates' => array ('basic'),
        'defined_fields' => array (),
        'object_name' => null,
        'module_name' => null,
        'table_name' => null,
        'object_name_auc' => null,
        'module_name_auc' => null,
    );

    /**
     *
     * @param array $args
     * @return array
     * @throws \Exception
     * @throws \InvalidArgumentException
     */
    public static function parseArgs(array $args)
    {
        global $sugar_flavor;

        $arguments = array_merge(self::$arguments, $args);

        if (empty($arguments['module_name']))
        {
            $arguments['module_name'] = $arguments['object_name'] . 's';
        }

        if (empty($arguments['table_name']))
        {
            $arguments['table_name'] = strtolower($arguments['module_name']);
        }

        $arguments['object_name_auc'] = strtoupper($arguments['object_name']);
        $arguments['module_name_auc'] = strtoupper($arguments['module_name']);
        $arguments['template_class_name'] = ucfirst($arguments['template']);

        $arguments['team_security'] = !empty($arguments['team_security']) && $sugar_flavor !== 'CE';

        if ($arguments['template'] !== 'basic')
        {
            $arguments['templates'][] = $arguments['template'];
        }

        if ($arguments['team_security'])
        {
            $arguments['templates'][] = 'team_security';
        }

        if ($arguments['assignable'])
        {
            $arguments['templates'][] = 'assignable';
        }

        if (empty($arguments['translation_plural'])) {
            $arguments['translation_plural'] = self::translate($arguments['module_name']);
        }

        if (empty($arguments['translation_singular'])) {
            $arguments['translation_singular'] = self::translate($arguments['object_name']);
        }

        return $arguments;
    }

    /**
     * @param string $module
     * @return string
     */
    public static function translate($module)
    {
        $module = str_replace('DRI_', '', $module);
        $module = preg_replace('/([a-z]{1})([A-Z]{1})/', '$1 $2', $module);
        return $module;
    }

    /**
     * @var \Twig_Environment
     */
    private $twig;

    /**
     * @var Filesystem
     */
    private $filesystem;

    /**
     * @var string
     */
    private $templatePath;

    /**<commit_msg>Added support for modules with prefix ARK_<commit_after><?php

namespace DRI\SugarCRM\Console\Generator;
use Symfony\Component\Filesystem\Filesystem;

/**
 * This file is part of the DRI Sugar CRM Module Creator library
 *
 * Copyright (c) 2013 <NAME>, DRI Nordic
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license MIT
 *   See LICENSE shipped with this library.
 */
class ModuleCreator
{
    /**
     * @var array
     */
    private static $arguments = array (
        'assignable' => false,
        'team_security' => false,
        'force' => false,
        'help' => false,
        'audited' => false,
        'dry' => false,
        'importable' => false,
        'template' => 'basic',
        'template_class_name' => 'Basic',
        'templates' => array ('basic'),
        'defined_fields' => array (),
        'object_name' => null,
        'module_name' => null,
        'table_name' => null,
        'object_name_auc' => null,
        'module_name_auc' => null,
    );

    /**
     *
     * @param array $args
     * @return array
     * @throws \Exception
     * @throws \InvalidArgumentException
     */
    public static function parseArgs(array $args)
    {
        global $sugar_flavor;

        $arguments = array_merge(self::$arguments, $args);

        if (empty($arguments['module_name']))
        {
            $arguments['module_name'] = $arguments['object_name'] . 's';
        }

        if (empty($arguments['table_name']))
        {
            $arguments['table_name'] = strtolower($arguments['module_name']);
        }

        $arguments['object_name_auc'] = strtoupper($arguments['object_name']);
        $arguments['module_name_auc'] = strtoupper($arguments['module_name']);
        $arguments['template_class_name'] = ucfirst($arguments['template']);

        $arguments['team_security'] = !empty($arguments['team_security']) && $sugar_flavor !== 'CE';

        if ($arguments['template'] !== 'basic')
        {
            $arguments['templates'][] = $arguments['template'];
        }

        if ($arguments['team_security'])
        {
            $arguments['templates'][] = 'team_security';
        }

        if ($arguments['assignable'])
        {
            $arguments['templates'][] = 'assignable';
        }

        if (empty($arguments['translation_plural'])) {
            $arguments['translation_plural'] = self::translate($arguments['module_name']);
        }

        if (empty($arguments['translation_singular'])) {
            $arguments['translation_singular'] = self::translate($arguments['object_name']);
        }

        return $arguments;
    }

    /**
     * @param string $module
     * @return string
     */
    public static function translate($module)
    {
        $module = str_replace('ARK_', '', $module);
        $module = str_replace('DRI_', '', $module);
        $module = preg_replace('/([a-z]{1})([A-Z]{1})/', '$1 $2', $module);
        return $module;
    }

    /**
     * @var \Twig_Environment
     */
    private $twig;

    /**
     * @var Filesystem
     */
    private $filesystem;

    /**
     * @var string
     */
    private $templatePath;

    /**
{'fraction_non_alphanumeric': 0.15953612286475474, 'fraction_numerical': 0.0025074439742986993, 'mean_word_length': 2.3660337552742616, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934774', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1812, 'n_words': 375}