<commit_before>/*
 * Copyright 2011-2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kstenschke.shifter.models.shiftertypes;

import com.kstenschke.shifter.utils.UtilsTextual;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * PHP Variable (word with $ prefix), includes array definition (toggle long versus shorthand syntax)
 */
public class PhpVariable {

	// Detected array? Shifts among long and shorthand than: array(...) <=> [...]
	private boolean isArray = false;

	private boolean isConventionalArray = false; // shorthand (since PHP5.4) or long syntax array?

	/**
	 * Constructor
	 */
	public PhpVariable() {

	}

	/**
	 * Check whether given string represents a PHP variable
	 *
	 * @param	str			String to be checked
	 * @return	boolean.
	 */
	public Boolean isPhpVariable(String str) {
			// Must begin with "$"
		if ( ! str.startsWith("$") ) {
			return false;
		}

		String identifier = str.substring(1);
			// Must contain a-z,A-Z or 0-9, _
		boolean isVariable = identifier.toLowerCase().matches("[a-zA-Z0-9_]+");

		if( ! isVariable ) {
			// Detect array definition
			this.isArray = this.isPhpArray(str);
			isVariable = this.isArray;
		}

		return isVariable;
	}

	/**
	 * @param	str
	 * @return	Boolean
	 */
	private Boolean isPhpArray(String str) {
		this.isConventionalArray =     str.matches("(array\\s*\\()((.|\\n|\\r|\\s)*)(\\)(;)*)");
		boolean isShorthandArray = ! this.isConventionalArray && str.matches("(\\[)((.|\\n|\\r|\\s)*)(\\])");

		return this.isConventionalArray || isShorthandArray;
	}

	/**
	 * Shift PX value up/down by 16px
	 *
	 * @param	variable		Variable name string
	 * @param	editorText		Text of edited document
	 * @param	isUp			Shift up or down?
	 * @param	moreCount		Current "more" count, starting with 1. If non-more shift: null
	 * @return	String<commit_msg>simplified statement<commit_after>/*
 * Copyright 2011-2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kstenschke.shifter.models.shiftertypes;

import com.kstenschke.shifter.utils.UtilsTextual;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * PHP Variable (word with $ prefix), includes array definition (toggle long versus shorthand syntax)
 */
public class PhpVariable {

	// Detected array? Shifts among long and shorthand than: array(...) <=> [...]
	private boolean isArray = false;

	private boolean isConventionalArray = false; // shorthand (since PHP5.4) or long syntax array?

	/**
	 * Constructor
	 */
	public PhpVariable() {

	}

	/**
	 * Check whether given string represents a PHP variable
	 *
	 * @param	str			String to be checked
	 * @return	boolean.
	 */
	public Boolean isPhpVariable(String str) {
			// Must begin with "$"
		if ( ! str.startsWith("$") ) {
			return false;
		}

		String identifier = str.substring(1);
			// Must contain a-z,A-Z or 0-9, _
		boolean isVariable = identifier.toLowerCase().matches("[a-zA-Z0-9_]+");

		if( ! isVariable ) {
			// Detect array definition
			this.isArray = this.isPhpArray(str);
		}

		return isVariable || this.isArray;
	}

	/**
	 * @param	str
	 * @return	Boolean
	 */
	private Boolean isPhpArray(String str) {
		this.isConventionalArray =     str.matches("(array\\s*\\()((.|\\n|\\r|\\s)*)(\\)(;)*)");
		boolean isShorthandArray = ! this.isConventionalArray && str.matches("(\\[)((.|\\n|\\r|\\s)*)(\\])");

		return this.isConventionalArray || isShorthandArray;
	}

	/**
	 * Shift PX value up/down by 16px
	 *
	 * @param	variable		Variable name string
	 * @param	editorText		Text of edited document
	 * @param	isUp			Shift up or down?
	 * @param	moreCount		Current "more" count, starting with 1. If non-more shift: null
	 * @return	String
{'fraction_non_alphanumeric': 0.1301944728761515, 'fraction_numerical': 0.009007164790174002, 'mean_word_length': 3.458029197080292, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4263475', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1487, 'n_words': 483}