<commit_before><?php namespace Esensi\Model\Traits;

use \Illuminate\Support\Facades\Crypt;
use \Illuminate\Encryption\Encrypter;
use \Illuminate\Encryption\DecryptException;

/**
 * Trait that implements the Encrypting Model Interface
 *
 * @package Esensi\Model
 * @author <NAME> <<EMAIL>>
 * @copyright 2014 Emerson Media LP
 * @license https://github.com/esensi/model/blob/master/LICENSE.txt MIT License
 * @link http://www.emersonmedia.com
 *
 * @see \Esensi\Model\Contracts\EncryptionModelInterface
 */
trait EncryptingModelTrait {

    /**
     * Whether the model is encrypting or not.
     *
     * @var boolean
     */
    protected $encrypting = true;

    /**
     * The Encrypter to use for encryption.
     *
     * @var \Illuminate\Encryption\Encrypter
     */
    protected $encrypter;

    /**
     * Dynamically retrieve attributes.
     *
     * @param  string $key
     * @return mixed
     */
    public function __get( $key )
    {
        // Dynamically retrieve the encrypted attribute
        if( $attribute = $this->getDynamicEncrypted( $key ) )
        {
            return $attribute;
        }

        // Default Eloquent dynamic getter
        return parent::__get( $key );
    }

    /**
     * Dynamically set attributes.
     *
     * @param  string $key
     * @param  mixed $value
     * @return void
     */
    public function __set( $key, $value )
    {
        // Dynamically set the encryptable attribute
        if( $this->setDynamicEncryptable( $key, $value ) )
        {
            return;
        }

        // Default Eloquent dynamic setter
        return parent::__set( $key, $value );
    }

    /**
     * Get an encrypted attribute dynamically.
     *
     * @param  string $attribute<commit_msg>Fixed magic getter for empty string encryption.<commit_after><?php namespace Esensi\Model\Traits;

use \Illuminate\Support\Facades\Crypt;
use \Illuminate\Encryption\Encrypter;
use \Illuminate\Encryption\DecryptException;

/**
 * Trait that implements the Encrypting Model Interface
 *
 * @package Esensi\Model
 * @author <NAME> <<EMAIL>>
 * @copyright 2014 Emerson Media LP
 * @license https://github.com/esensi/model/blob/master/LICENSE.txt MIT License
 * @link http://www.emersonmedia.com
 *
 * @see \Esensi\Model\Contracts\EncryptionModelInterface
 */
trait EncryptingModelTrait {

    /**
     * Whether the model is encrypting or not.
     *
     * @var boolean
     */
    protected $encrypting = true;

    /**
     * The Encrypter to use for encryption.
     *
     * @var \Illuminate\Encryption\Encrypter
     */
    protected $encrypter;

    /**
     * Dynamically retrieve attributes.
     *
     * @param  string $key
     * @return mixed
     */
    public function __get( $key )
    {
        // Dynamically retrieve the encrypted attribute
        $value = $this->getDynamicEncrypted( $key );
        if( ! is_null($value) || is_string($value) )
        {
            return $value;
        }

        // Default Eloquent dynamic getter
        return parent::__get( $key );
    }

    /**
     * Dynamically set attributes.
     *
     * @param  string $key
     * @param  mixed $value
     * @return void
     */
    public function __set( $key, $value )
    {
        // Dynamically set the encryptable attribute
        if( $this->setDynamicEncryptable( $key, $value ) )
        {
            return;
        }

        // Default Eloquent dynamic setter
        return parent::__set( $key, $value );
    }

    /**
     * Get an encrypted attribute dynamically.
     *
     * @param  string $attribute
{'fraction_non_alphanumeric': 0.1123249299719888, 'fraction_numerical': 0.002240896358543417, 'mean_word_length': 2.1657801418439715, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '1866559', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1065, 'n_words': 267}