<commit_before><?php
/**
 * Main Element Class
 *
 * @package    SVGCreator
 * @subpackage my-subpackage
 * @author     <NAME>
 * @version    1.0
 */

namespace SVGCreator;

/**
 * Main element class
 * 
 * @abstract
 */
abstract class Element {

	const CIRCLE = 'circle';
	const DEFS = 'defs';
	const GROUP = 'g';
	const LINE = 'line';
	const MARKER = 'marker';
	const PATH = 'path';
	const RECT = 'rect';
	const SVG = 'svg';
	const TEXT = 'text';
	const POLYGON = 'polygon';

	/**
	 * The array that holds all attributes
	 * @var array
	 */
	protected $attributes;

	/**
	 * The string that has all the element as a string
	 * @var string
	 */
	protected $elementString;

	/**
	 * Array with the child elements
	 * @var \SVGCreator\Element[]
	 */
	protected $childElements;

	/**
	 * Definitons array
	 * @var array
	 */
	private $defs;

	/**
	 * The text to put inside the element
	 * @var string
	 */
	private $text = null;

	public function __construct($attributes = array()) {

		// Setup the private variables
		$this->attributes = $attributes;
		$this->elementString = '';
		$this->childElements = array();
		$this->defs = array();
	}

	/**
	 * Returns the defs array for this element
	 * @return array
	 */
	protected function getDefs() {
		return $this->defs;
	}

	/**
	 * Set's the definition array
	 * @param array 
	 * @return \SVGCreator\Element
	 */
	protected function setDefs($defs = array()) {
		$this->defs = $defs;
		return $this;
	}

	/**
	 * Set's the attributes for this element
	 * @param array  	$attributes  	An array with the attributes
	 */
	public function setAttributes($attributes) {
		$this->attributes = $attributes;
	}

	/**
	 * Adds an def element to the element
	 * @param \SVGCreator\Element $def
	 * @return \SVGCreator\Element
	 */
	public function addDef(\SVGCreator\Element $def) {
		$this->defs[] = $def;
		return $def;
	}

	abstract protected function validateElementValues();

	private function validateElement() {
		$this->validateMandatoryAttribs();
		$this->validateElementValues();
	}

	protected function validateMandatoryAttribs() {
		// Iterate over all fields
    	foreach ( static::$mandatoryFields as $field ) {
    		// If the field does not exist then exit with exception
    		if ( !array_key_exists($field, $this->attributes) ) {
    			throw new \SVGCreator\SVGException("The field ".$field." does not exist for ".static::TYPE.".", 1);
    		}
    	}
	}

	/**
	 * Set's an attribute for the current element
	 * @param  mixed 	 $attrKey		The name of the attribute
	 * @param  string    $attrValue		The value of the attribute
	 * @return mixed 					Could be an \SVGCreator\Element or could be the value of the attribute, 
	 * this means that the second parameter wasn't passed
	 */
	public function attr($attrKey, $attrValue = null) {
		if ( $attrValue != null ) {
			if ( !is_array($this->attributes) ) {
				$this->attributes = array();
			}
			$this->attributes[$attrKey] = $attrValue;
			return $this;<commit_msg>fix: int value 0 is considered null with  expression !=<commit_after><?php
/**
 * Main Element Class
 *
 * @package    SVGCreator
 * @subpackage my-subpackage
 * @author     <NAME>
 * @version    1.0
 */

namespace SVGCreator;

/**
 * Main element class
 * 
 * @abstract
 */
abstract class Element {

	const CIRCLE = 'circle';
	const DEFS = 'defs';
	const GROUP = 'g';
	const LINE = 'line';
	const MARKER = 'marker';
	const PATH = 'path';
	const RECT = 'rect';
	const SVG = 'svg';
	const TEXT = 'text';
	const POLYGON = 'polygon';

	/**
	 * The array that holds all attributes
	 * @var array
	 */
	protected $attributes;

	/**
	 * The string that has all the element as a string
	 * @var string
	 */
	protected $elementString;

	/**
	 * Array with the child elements
	 * @var \SVGCreator\Element[]
	 */
	protected $childElements;

	/**
	 * Definitons array
	 * @var array
	 */
	private $defs;

	/**
	 * The text to put inside the element
	 * @var string
	 */
	private $text = null;

	public function __construct($attributes = array()) {

		// Setup the private variables
		$this->attributes = $attributes;
		$this->elementString = '';
		$this->childElements = array();
		$this->defs = array();
	}

	/**
	 * Returns the defs array for this element
	 * @return array
	 */
	protected function getDefs() {
		return $this->defs;
	}

	/**
	 * Set's the definition array
	 * @param array 
	 * @return \SVGCreator\Element
	 */
	protected function setDefs($defs = array()) {
		$this->defs = $defs;
		return $this;
	}

	/**
	 * Set's the attributes for this element
	 * @param array  	$attributes  	An array with the attributes
	 */
	public function setAttributes($attributes) {
		$this->attributes = $attributes;
	}

	/**
	 * Adds an def element to the element
	 * @param \SVGCreator\Element $def
	 * @return \SVGCreator\Element
	 */
	public function addDef(\SVGCreator\Element $def) {
		$this->defs[] = $def;
		return $def;
	}

	abstract protected function validateElementValues();

	private function validateElement() {
		$this->validateMandatoryAttribs();
		$this->validateElementValues();
	}

	protected function validateMandatoryAttribs() {
		// Iterate over all fields
    	foreach ( static::$mandatoryFields as $field ) {
    		// If the field does not exist then exit with exception
    		if ( !array_key_exists($field, $this->attributes) ) {
    			throw new \SVGCreator\SVGException("The field ".$field." does not exist for ".static::TYPE.".", 1);
    		}
    	}
	}

	/**
	 * Set's an attribute for the current element
	 * @param  mixed 	 $attrKey		The name of the attribute
	 * @param  string    $attrValue		The value of the attribute
	 * @return mixed 					Could be an \SVGCreator\Element or could be the value of the attribute, 
	 * this means that the second parameter wasn't passed
	 */
	public function attr($attrKey, $attrValue = null) {
		if ( $attrValue !== null ) {
			if ( !is_array($this->attributes) ) {
				$this->attributes = array();
			}
			$this->attributes[$attrKey] = $attrValue;
			return $this;
{'fraction_non_alphanumeric': 0.13186446336170923, 'fraction_numerical': 0.0011684192956100817, 'mean_word_length': 3.1069225496915696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '7190585', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1864, 'n_words': 590}