<commit_before><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Papi Page.
 *
 * @package Papi
 * @since 1.0.0
 */

class Papi_Page {

	/**
	 * The WordPress post id.
	 *
	 * @var int
	 * @since 1.0.0
	 */

	public $id;

	/**
	 * The WordPress post.
	 *
	 * @var object
	 * @since 1.0.0
	 */

	private $post;

	/**
	 * The Page type.
	 *
	 * @var object.
	 * @since 1.0.0
	 */

	private $page_type;

	/**
	 * Create a new instance of the class.
	 *
	 * @param int $post_id
	 *
	 * @since 1.0.0
	 */

	public function __construct( $post_id = 0 ) {
		$this->id   = $post_id;
		$this->post = get_post( $this->id );

		// Load page type object.
		$path            = papi_get_file_path( papi_get_page_type_meta_value( $this->id ) );
		$this->page_type = papi_get_page_type( $path );
	}

	/**
	 * Get Papi Property value.
	 *
	 * @param string $slug
	 * @param bool $admin
	 *
	 * @since 1.0.0
	 *
	 * @return mixed
	 */

	public function get_value( $slug, $admin = false ) {
		$property_value      = get_post_meta( $this->id, $slug, true );
		$property_type_key   = papi_f( papi_get_property_type_key( $slug ) );
		$property_type_value = get_post_meta( $this->id, $property_type_key, true );

		if ( papi_is_empty( $property_value ) || empty( $property_type_value ) ) {
			return null;
		}

		// The convert takes a array as argument so let's make one.
		$property_value = $this->convert( array(
			'admin' => $admin,
			'slug'  => $slug,
			'type'  => $property_type_value,
			'value' => $property_value
		) );

		if ( is_array( $property_value ) ) {
			$property_value = array_filter( $property_value );
		}

		return $property_value;
	}

	/**
	 * Convert property value with the property type converter.
	 *
	 * @param array $property
	 *
	 * @since 1.0.0
	 *
	 * @return mixed|null
	 */

	private function convert( $property ) {
		if ( !isset( $property['value'] ) || !isset( $property['type'] ) ) {
			return null;
		}

		$type          = strval( $property['type'] );
		$property_type = papi_get_property_type( $type );

		// If no property type is found, just return the value.
		if ( empty( $property_type ) ) {
			return $property['value'];
		}

		// Run a `load_value` right after the value has been loaded from the database.
		$property['value'] = $property_type->load_value( $property['value'], $property['slug'], $this->id );

		// Apply a filter so this can be changed from the theme for specified property type.
		$property['value'] = papi_filter_load_value( $type, $property['value'], $property['slug'], $this->id );

		// Format the value from the property class.
		$property['value'] = $property_type->format_value( $property['value'], $property['slug'], $this->id, $property['admin'] );

		// Apply a filter so this can be changed from the theme for specified property type.
		$property['value'] = papi_filter_format_value(  $type, $property['value'], $property['slug'], $this->id );

		return $property['value'];
	}

	/**
	 * Check if the page has the post object and that it's not null
	 *
	 * @since 1.0.0
	 *
	 * @return bool
	 */

	public function has_post() {
		return $this->post != null;
	}

	/**
	 * Get the page type object of the page.
	 *<commit_msg>Coding standard<commit_after><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Papi Page.
 *
 * @package Papi
 * @since 1.0.0
 */

class Papi_Page {

	/**
	 * The WordPress post id.
	 *
	 * @var int
	 * @since 1.0.0
	 */

	public $id;

	/**
	 * The WordPress post.
	 *
	 * @var object
	 * @since 1.0.0
	 */

	private $post;

	/**
	 * The Page type.
	 *
	 * @var object.
	 * @since 1.0.0
	 */

	private $page_type;

	/**
	 * Create a new instance of the class.
	 *
	 * @param int $post_id
	 *
	 * @since 1.0.0
	 */

	public function __construct( $post_id = 0 ) {
		$this->id   = $post_id;
		$this->post = get_post( $this->id );

		// Load page type object.
		$path            = papi_get_file_path( papi_get_page_type_meta_value( $this->id ) );
		$this->page_type = papi_get_page_type( $path );
	}

	/**
	 * Get Papi Property value.
	 *
	 * @param string $slug
	 * @param bool $admin
	 *
	 * @since 1.0.0
	 *
	 * @return mixed
	 */

	public function get_value( $slug, $admin = false ) {
		$property_value      = get_post_meta( $this->id, $slug, true );
		$property_type_key   = papi_f( papi_get_property_type_key( $slug ) );
		$property_type_value = get_post_meta( $this->id, $property_type_key, true );

		if ( papi_is_empty( $property_value ) || empty( $property_type_value ) ) {
			return null;
		}

		// The convert takes a array as argument so let's make one.
		$property_value = $this->convert( array(
			'admin' => $admin,
			'slug'  => $slug,
			'type'  => $property_type_value,
			'value' => $property_value
		) );

		if ( is_array( $property_value ) ) {
			$property_value = array_filter( $property_value );
		}

		return $property_value;
	}

	/**
	 * Convert property value with the property type converter.
	 *
	 * @param array $property
	 *
	 * @since 1.0.0
	 *
	 * @return mixed|null
	 */

	private function convert( $property ) {
		if ( ! isset( $property['value'] ) || ! isset( $property['type'] ) ) {
			return null;
		}

		$type          = strval( $property['type'] );
		$property_type = papi_get_property_type( $type );

		// If no property type is found, just return the value.
		if ( empty( $property_type ) ) {
			return $property['value'];
		}

		// Run a `load_value` right after the value has been loaded from the database.
		$property['value'] = $property_type->load_value( $property['value'], $property['slug'], $this->id );

		// Apply a filter so this can be changed from the theme for specified property type.
		$property['value'] = papi_filter_load_value( $type, $property['value'], $property['slug'], $this->id );

		// Format the value from the property class.
		$property['value'] = $property_type->format_value( $property['value'], $property['slug'], $this->id, $property['admin'] );

		// Apply a filter so this can be changed from the theme for specified property type.
		$property['value'] = papi_filter_format_value( $type, $property['value'], $property['slug'], $this->id );

		return $property['value'];
	}

	/**
	 * Check if the page has the post object and that it's not null
	 *
	 * @since 1.0.0
	 *
	 * @return bool
	 */

	public function has_post() {
		return $this->post != null;
	}

	/**
	 * Get the page type object of the page.
	 *
{'fraction_non_alphanumeric': 0.15805091363423396, 'fraction_numerical': 0.007808839606434484, 'mean_word_length': 3.0302076777847704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '5878619', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2185, 'n_words': 603}