<commit_before><?php

namespace Jasny\DB\Entity\ChangeAware;

use SebastianBergmann\Comparator\Factory as ComparatorFactory,
    SebastianBergmann\Comparator\ComparisonFailure;

/**
 * Implementation for change aware entities.
 * 
 * @author  <NAME> <<EMAIL>>
 * @license https://raw.github.com/jasny/db-mongo/master/LICENSE MIT
 * @link    https://jasny.github.io/db-mongo
 */
trait Implementation
{
    /**
     * @var array
     */
    private $persistedData__;

    /**
     * Set the current data as persisted data
     */
    protected function markAsPersisted()
    {
        $this->persistedData__ = $this->toData();
    }
    
    
    /**
     * Check if the entity is new
     * 
     * @return boolean
     */
    public function isNew()
    {
        return !isset($this->persistedData__);
    }
    
    /**
     * Check if the entity is modified
     * 
     * @return boolean
     */
    public function isModified()
    {
        return $this->hasModified($this);
    }
    
    /**
     * Check if a property has changed
     * 
     * @param string $property
     * @return boolean
     */
    public function hasModified($property)
    {
        $data = $this->toData();
        
        if ($property === $this) {
            $original = $this->persistedData__;
            $current = $data;
        } else {
            $original = isset($this->persistedData__[$property]) ? $this->persistedData__[$property] : null;
            $current = isset($data[$property]) ? $data[$property] : null;
        }
        
        $factory = new ComparatorFactory();
        $comparator = $factory->getComparatorFor($original, $current);
        
        try {
            $comparator->assertEquals($original, $current);
        } catch (ComparisonFailure $failure) {
            return false;
        }
        
        return true;        
    }
}<commit_msg>Fix: result of hasModified() was inverted<commit_after><?php

namespace Jasny\DB\Entity\ChangeAware;

use SebastianBergmann\Comparator\Factory as ComparatorFactory,
    SebastianBergmann\Comparator\ComparisonFailure;

/**
 * Implementation for change aware entities.
 * 
 * @author  <NAME> <<EMAIL>>
 * @license https://raw.github.com/jasny/db-mongo/master/LICENSE MIT
 * @link    https://jasny.github.io/db-mongo
 */
trait Implementation
{
    /**
     * @var array
     */
    private $persistedData__;

    /**
     * Set the current data as persisted data
     */
    protected function markAsPersisted()
    {
        $this->persistedData__ = $this->toData();
    }
    
    
    /**
     * Check if the entity is new
     * 
     * @return boolean
     */
    public function isNew()
    {
        return !isset($this->persistedData__);
    }
    
    /**
     * Check if the entity is modified
     * 
     * @return boolean
     */
    public function isModified()
    {
        return $this->hasModified($this);
    }
    
    /**
     * Check if a property has changed
     * 
     * @param string $property
     * @return boolean
     */
    public function hasModified($property)
    {
        $data = $this->toData();
        
        if ($property === $this) {
            $original = $this->persistedData__;
            $current = $data;
        } else {
            $original = isset($this->persistedData__[$property]) ? $this->persistedData__[$property] : null;
            $current = isset($data[$property]) ? $data[$property] : null;
        }
        
        if ($original === $current) return false;
        
        $factory = new ComparatorFactory();
        $comparator = $factory->getComparatorFor($original, $current);
        
        try {
            $comparator->assertEquals($original, $current);
        } catch (ComparisonFailure $failure) {
            return true;
        }
        
        return false;        
    }
}
{'fraction_non_alphanumeric': 0.1267311209824928, 'fraction_numerical': 0.0, 'mean_word_length': 1.9423520368946965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 4, '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': '3738833', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1099, 'n_words': 236}