<commit_before><?php
/**
 * Created by PhpStorm.
 * User: Nabeel
 * Date: 18-Jun-17
 * Time: 12:28 PM
 */

use EasyGit\Repository;

error_reporting( E_ALL );

// to load packages
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';

// command interface instance
$cmd = new \League\CLImate\CLImate();

// plugin info
$plugin_info = [
	'plugin_name'    => '*Plugin Name',
	'plugin_desc'    => 'Plugin Description',
	'plugin_slug'    => 'Plugin Slug (leave empty to generate from plugin\'s name)',
	'text_domain'    => 'Text Domain (leave empty use plugin\'s slug)',
	'naming_prefix'  => 'Naming Prefix (leave empty to generate from plugin\'s name)',
	'namespace'      => 'Namespace (leave empty to generate from plugin\'s name)',
	'author_name'    => 'Plugin Author Name',
	'author_email'   => 'Plugin Author Email',
	'author_website' => 'Plugin Author Website',
];

// default values
$plugin_defaults = [
	'author_name'    => '<NAME>',
	'author_email'   => '<EMAIL>',
	'author_website' => 'https://nabeel.molham.me/',
];

foreach ( $plugin_info as $info_key => $info_label )
{
	// check if input is required or not
	$is_required = 0 === strpos( $info_label, '*' );
	$info_label  = str_replace( '*', '', $info_label );

	// requires info
	$info_value = prompt_input( $info_label, $is_required, 'namespace' === $info_key ? '/^[a-zA-Z][a-zA-Z0-9_]+((\\[a-zA-Z][a-zA-Z0-9_]+)+)*/' : '' );

	if ( empty( $info_value ) && array_key_exists( $info_key, $plugin_defaults ) )
	{
		// use default value then
		$info_value = $plugin_defaults[ $info_key ];
	}

	switch ( $info_key )
	{
		case 'plugin_slug':
			if ( empty( $info_value ) )
			{
				// generate the slug from plugin's name
				$info_value = preg_replace( '/[^a-z0-9_\-]/', '', str_replace( ' ', '-', mb_strtolower( $plugin_info['plugin_name'] ) ) );
			}
			break;
		case 'text_domain':
			if ( empty( $info_value ) )
			{
				// use plugin's slug
				$info_value = $plugin_info['plugin_slug'];
			}
			break;
		case 'naming_prefix':
			if ( empty( $info_value ) )
			{
				// generate based on plugin's name
				preg_match_all( '/[A-Z]/', $plugin_info['plugin_name'], $matches );
				$info_value = mb_strtolower( implode( '', array_map( 'trim', $matches[0] ) ) ) . '_';
			}
			else
			{
				// sanitize
				$info_value = preg_replace( '/[^a-z_]/', '', mb_strtolower( preg_match( '/_$/', $info_value ) ? $info_value : $info_value . '_' ) );
			}<commit_msg>force ucwords and use recommended prefixes<commit_after><?php
/**
 * Created by PhpStorm.
 * User: Nabeel
 * Date: 18-Jun-17
 * Time: 12:28 PM
 */

use EasyGit\Repository;

error_reporting( E_ALL );

// to load packages
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor/autoload.php';

// command interface instance
$cmd = new \League\CLImate\CLImate();

// plugin info
$plugin_info = [
	'plugin_name'    => '*Plugin Name',
	'plugin_desc'    => 'Plugin Description',
	'plugin_slug'    => 'Plugin Slug (leave empty to generate from plugin\'s name)',
	'text_domain'    => 'Text Domain (leave empty use plugin\'s slug)',
	'naming_prefix'  => 'Naming Prefix (leave empty to generate from plugin\'s name)',
	'namespace'      => 'Namespace (leave empty to generate from plugin\'s name)',
	'author_name'    => 'Plugin Author Name',
	'author_email'   => 'Plugin Author Email',
	'author_website' => 'Plugin Author Website',
];

// default values
$plugin_defaults = [
	'author_name'    => '<NAME>',
	'author_email'   => '<EMAIL>',
	'author_website' => 'https://nabeel.molham.me/',
];

// list of recommended prefixed
$fixed_prefixes = [
	'woocommerce'                => 'wc',
	'buddypress'                 => 'bp',
	'gravityforms'               => 'gforms',
	'gravity forms'              => 'gforms',
	'easydigitaldownloads'       => 'eed',
	'easy digital downloads'     => 'eed',
	'contact form 7'             => 'cf7',
	'advanced custom fields'     => 'acf',
	'advanced custom fields pro' => 'acf_pro',
	'w3 total cache'             => 'w3tc',
	'ninja forms'                => 'nf',
	'mailchimp'                  => 'mc',
	'userpro'                    => 'userpro',
	'ultimate member'            => 'um',
	'badgeos'                    => 'badgeos',
	'wp job manager'             => 'wpjm',
	'listify'                    => 'listify',
	'visual composer'            => 'vc',
];

foreach ( $plugin_info as $info_key => $info_label )
{
	// check if input is required or not
	$is_required = 0 === strpos( $info_label, '*' );
	$info_label  = str_replace( '*', '', $info_label );

	// requires info
	$info_value = prompt_input( $info_label, $is_required, 'namespace' === $info_key ? '/^[a-zA-Z][a-zA-Z0-9_]+((\\[a-zA-Z][a-zA-Z0-9_]+)+)*/' : '' );

	if ( empty( $info_value ) && array_key_exists( $info_key, $plugin_defaults ) )
	{
		// use default value then
		$info_value = $plugin_defaults[ $info_key ];
	}

	switch ( $info_key )
	{
		case 'plugin_name':
			$info_value = ucwords( $info_value );
			break;
		case 'plugin_slug':
			if ( empty( $info_value ) )
			{
				// generate the slug from plugin's name
				$info_value = preg_replace( '/[^a-z0-9_\-]/', '', str_replace( ' ', '-', mb_strtolower( $plugin_info['plugin_name'] ) ) );
			}
			break;
		case 'text_domain':
			if ( empty( $info_value ) )
			{
				// use plugin's slug
				$info_value = $plugin_info['plugin_slug'];
			}
			break;
		case 'naming_prefix':
			if ( empty( $info_value ) )
			{
				$plugin_name = $plugin_info['plugin_name'];
				foreach ( $fixed_prefixes as $prefix_name => $prefix )
				{
					if ( false !== stripos( $plugin_name, $prefix_name ) )
					{
						// use recommended one
						$info_value  = $prefix . '_';
						$plugin_name = trim( str_ireplace( $prefix_name, '', $plugin_name ) );
						break;
					}
				}
				unset( $prefix_name, $prefix );

				// generate based on plugin's name
				preg_match_all( '/[A-Z]/', $plugin_name, $matches );
				$info_value .= mb_strtolower( implode( '', array_map( 'trim', $matches[0] ) ) ) . '_';
			}
			else
			{
				// sanitize
				$info_value = preg_replace( '/[^a-z_]/', '', mb_strtolower( preg_match( '/_$/', $info_value ) ? $info_value : $info_value . '_' ) );
			}
{'fraction_non_alphanumeric': 0.17949975478175575, 'fraction_numerical': 0.005885237861696911, 'mean_word_length': 2.9986928104575163, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 52, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5581136', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2171, 'n_words': 489}