<commit_before><?php
namespace Opg\Lpa\DataModel\User;

use Opg\Lpa\DataModel\AbstractData;
use Respect\Validation\Rules;
use Opg\Lpa\DataModel\Validator\Validator;

/**
 * Represents a user of the LPA platform.
 *
 * Class User
 */
class User extends AbstractData {

    /**
     * @var string The user's internal ID.
     */
    protected $id;

    /**
     * @var Name Their name.
     */
    protected $name;

    /**
     * @var Address Their postal address.
     */
    protected $address;

    /**
     * @var Dob Their date of birth.
     */
    protected $dob;

    /**
     * @var EmailAddress Their email address.
     */
    protected $email;

    //------------------------------------------------

    public function __construct( $data = null ){

        //-----------------------------------------------------
        // Type mappers

        $this->typeMap['name'] = function($v){
            return ($v instanceof Name || is_null($v)) ? $v : new Name( $v );
        };

        $this->typeMap['address'] = function($v){
            return ($v instanceof Address || is_null($v)) ? $v : new Address( $v );
        };

        $this->typeMap['dob'] = function($v){
            return ($v instanceof Dob || is_null($v)) ? $v : new Dob( $v );
        };

        $this->typeMap['email'] = function($v){
            return ($v instanceof EmailAddress || is_null($v)) ? $v : new EmailAddress( $v );
        };

        //-----------------------------------------------------
        // Validators (wrapped in Closures for lazy loading)

        $this->validators['id'] = function(){
            return (new Validator)->addRules([
                new Rules\NotEmpty,
                new Rules\Xdigit,
                new Rules\Length( 32, 32, true ),
            ]);
        };

        $this->validators['name'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Name' ),
            ]);
        };

        $this->validators['address'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Address' ),
            ]);
        };

        $this->validators['dob'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Dob' ),
            ]);
        };

        $this->validators['email'] = function(){
            return (new Validator)->addRule((new Rules\OneOf)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\EmailAddress' ),
                new Rules\NullValue,
            ]));
        };

        //---

        parent::__construct( $data );

    } // function

} // class
<commit_msg>Added dates to the User model<commit_after><?php
namespace Opg\Lpa\DataModel\User;

use DateTime;

use Opg\Lpa\DataModel\AbstractData;
use Respect\Validation\Rules;
use Opg\Lpa\DataModel\Validator\Validator;

/**
 * Represents a user of the LPA platform.
 *
 * Class User
 */
class User extends AbstractData {

    /**
     * @var string The user's internal ID.
     */
    protected $id;

    /**
     * @var DateTime the user was created.
     */
    protected $createdAt;

    /**
     * @var DateTime the user was last updated.
     */
    protected $updatedAt;

    /**
     * @var Name Their name.
     */
    protected $name;

    /**
     * @var Address Their postal address.
     */
    protected $address;

    /**
     * @var Dob Their date of birth.
     */
    protected $dob;

    /**
     * @var EmailAddress Their email address.
     */
    protected $email;

    //------------------------------------------------

    public function __construct( $data = null ){

        //-----------------------------------------------------
        // Type mappers

        $this->typeMap['updatedAt'] = $this->typeMap['createdAt'] = function($v){
            return ($v instanceof DateTime) ? $v : new DateTime( $v );
        };

        $this->typeMap['name'] = function($v){
            return ($v instanceof Name || is_null($v)) ? $v : new Name( $v );
        };

        $this->typeMap['address'] = function($v){
            return ($v instanceof Address || is_null($v)) ? $v : new Address( $v );
        };

        $this->typeMap['dob'] = function($v){
            return ($v instanceof Dob || is_null($v)) ? $v : new Dob( $v );
        };

        $this->typeMap['email'] = function($v){
            return ($v instanceof EmailAddress || is_null($v)) ? $v : new EmailAddress( $v );
        };

        //-----------------------------------------------------
        // Validators (wrapped in Closures for lazy loading)

        $this->validators['id'] = function(){
            return (new Validator)->addRules([
                new Rules\NotEmpty,
                new Rules\Xdigit,
                new Rules\Length( 32, 32, true ),
            ]);
        };

        $this->validators['createdAt'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'DateTime' ),
                new Rules\Call(function($input){
                    return ( $input instanceof \DateTime ) ? $input->gettimezone()->getName() : 'UTC';
                }),
            ]);
        };

        $this->validators['updatedAt'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'DateTime' ),
                new Rules\Call(function($input){
                    return ( $input instanceof \DateTime ) ? $input->gettimezone()->getName() : 'UTC';
                }),
            ]);
        };

        $this->validators['name'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Name' ),
            ]);
        };

        $this->validators['address'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Address' ),
            ]);
        };

        $this->validators['dob'] = function(){
            return (new Validator)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\Dob' ),
            ]);
        };

        $this->validators['email'] = function(){
            return (new Validator)->addRule((new Rules\OneOf)->addRules([
                new Rules\Instance( 'Opg\Lpa\DataModel\User\EmailAddress' ),
                new Rules\NullValue,
            ]));
        };

        //---

        parent::__construct( $data );

    } // function

} // class

{'fraction_non_alphanumeric': 0.1947972456006121, 'fraction_numerical': 0.001224177505738332, 'mean_word_length': 1.4927536231884058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '2119698', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1736, 'n_words': 405}