<commit_before><?php

namespace Halfpastfour\PHPChartJS\Delegate;

use Zend\Json\Expr;

/**
 * Class ArraySerializable
 * @package Halfpastfour\PHPChartJS\Model
 */
trait ArraySerializable
{
	/**
	 * Will loop through class properties and try and assign their values to an array of data that will be returned.
	 *
	 * @return array
	 */
	public function getArrayCopy()
	{
		$data = [];

		$properties			= get_class_vars( self::class );
		$reflectionClass	= new \Zend_Reflection_Class( $this );
		foreach( $properties as $property => $value ) {
			// Skip property if it is not accessible
			if( !$reflectionClass->hasProperty( $property ) ) continue;

			// Only process properties that aren't null
			if( !is_null( $this->$property ) ) {
				// Gather phpdoc from property
				$phpDoc	= $reflectionClass->getProperty( $property )->getDocComment();
				$type	= $phpDoc->getTag( 'var' )->getDescription();
				$object	= false;

				// Prepend 'get' to the getter method.
				$getter = 'get' . ucfirst( $property );
				if( is_object( $this->$property ) && !$this->$property instanceof Expr ) $object = true;

				// Determine whether the getter method is equal to the property name or is prepended by 'is' or 'get'
				if( strcmp( $type, 'bool' ) === 0 || strcmp( $type, 'boolean' ) === 0 ) {
					// Prepend 'is' to the getter method
					$getter	= 'is' . ucfirst( $property );
				} else if ( method_exists( $this, $property ) && is_object( $this->$property ) ) {
					// The getter method is equal to the property name and the value is an actual object
					$getter	= $property;
					$object	= true;
				}

				// Abort if the method does not exist
				if( !method_exists( $this, $getter ) ) continue;

				// Assign the contents of the property to the data array
				$data[ $property ] = $object ? $this->$getter()->getArrayCopy() : $this->$getter();
			}
		}

		return $data;
	}
}<commit_msg>Fixes #45 and replaces get_class_vars with get_object_vars. Also reformatted.<commit_after><?php

namespace Halfpastfour\PHPChartJS\Delegate;

use Zend\Json\Expr;

/**
 * Class ArraySerializable
 * @package Halfpastfour\PHPChartJS\Model
 */
trait ArraySerializable
{
	/**
	 * Will loop through class properties and try and assign their values to an array of data that will be returned.
	 *
	 * @return array
	 */
	public function getArrayCopy()
	{
		$data            = [];
		$properties      = get_object_vars( $this );
		$reflectionClass = new \Zend_Reflection_Class( $this );
		foreach( $properties as $property => $value ) {
			// Skip property if it is not accessible
			if( !$reflectionClass->hasProperty( $property ) ) continue;

			// Only process properties that aren't null
			if( !is_null( $value ) ) {
				// Gather phpdoc from property
				$phpDoc = $reflectionClass->getProperty( $property )->getDocComment();
				$type   = $phpDoc->getTag( 'var' )->getDescription();
				$object = false;

				// Prepend 'get' to the getter method.
				$getter = 'get' . ucfirst( $property );
				if( is_object( $value ) && !$this->$property instanceof Expr ) $object = true;

				// Determine whether the getter method is equal to the property name or is prepended by 'is' or 'get'
				if( strcmp( $type, 'bool' ) === 0 || strcmp( $type, 'boolean' ) === 0 ) {
					// Prepend 'is' to the getter method
					$getter = 'is' . ucfirst( $property );
				} else if( method_exists( $this, $property ) && is_object( $value ) ) {
					// The getter method is equal to the property name and the value is an actual object
					$getter = $property;
					$object = true;
				}

				// Abort if the method does not exist
				if( !method_exists( $this, $getter ) ) continue;

				// Assign the contents of the property to the data array
				$data[ $property ] = $object ? $this->$getter()->getArrayCopy() : $this->$getter();
			}
		}

		return $data;
	}
}
{'fraction_non_alphanumeric': 0.13585397653194264, 'fraction_numerical': 0.0015645371577574967, 'mean_word_length': 3.1515151515151514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '5430883', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1191, 'n_words': 396}