<commit_before><?php
/*
 * This file is part of the Dive ORM framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @author <NAME> <<EMAIL>>
 * Date: 06.02.13
 */

namespace Dive\UnitOfWork;

use Dive\Record;

class ChangeSet implements ChangeSetInterface
{

    const SAVE = 'save';
    const DELETE = 'delete';

    private $mode = null;
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForInsert = array();
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForUpdate = array();
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForDelete = array();


    public function calculateSave(Record $record)
    {
        $this->mode = self::SAVE;
        $this->resetScheduled();
        $this->processGraph($record);
    }


    public function calculateDelete(Record $record)
    {
        $this->mode = self::DELETE;
        $this->resetScheduled();
        $this->processGraph($record);
    }


    public function isSave()
    {
        return $this->mode == self::SAVE;
    }


    public function isDelete()
    {
        return $this->mode == self::DELETE;
    }


    public function resetScheduled()
    {
        $this->scheduledForInsert = array();
        $this->scheduledForUpdate = array();
        $this->scheduledForDelete = array();
    }


    private function processGraph(Record $record)
    {
        $recordExists = $record->exists();
        if ($recordExists && $this->isDelete()) {
            $this->scheduledForDelete[] = $record;
            return;
        }
        if ($recordExists) {
            if (!$record->isModified()) {
                $this->scheduledForUpdate[] = $record;
            }
        }
        else {
            $this->scheduledForInsert[] = $record;
        }
    }


    /**
     * @return \Dive\Record[]
     */
    public function getScheduledForInsert()<commit_msg>fixed wrong checking if-clause that scheduled update on not modified records instead of modified<commit_after><?php
/*
 * This file is part of the Dive ORM framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
/**
 * @author <NAME> <<EMAIL>>
 * Date: 06.02.13
 */

namespace Dive\UnitOfWork;

use Dive\Record;

class ChangeSet implements ChangeSetInterface
{

    const SAVE = 'save';
    const DELETE = 'delete';

    private $mode = null;
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForInsert = array();
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForUpdate = array();
    /**
     * @var \Dive\Record[]
     */
    private $scheduledForDelete = array();


    public function calculateSave(Record $record)
    {
        $this->mode = self::SAVE;
        $this->resetScheduled();
        $this->processGraph($record);
    }


    public function calculateDelete(Record $record)
    {
        $this->mode = self::DELETE;
        $this->resetScheduled();
        $this->processGraph($record);
    }


    public function isSave()
    {
        return $this->mode == self::SAVE;
    }


    public function isDelete()
    {
        return $this->mode == self::DELETE;
    }


    public function resetScheduled()
    {
        $this->scheduledForInsert = array();
        $this->scheduledForUpdate = array();
        $this->scheduledForDelete = array();
    }


    private function processGraph(Record $record)
    {
        $recordExists = $record->exists();
        if ($recordExists && $this->isDelete()) {
            $this->scheduledForDelete[] = $record;
            return;
        }
        if ($recordExists) {
            if ($record->isModified()) {
                $this->scheduledForUpdate[] = $record;
            }
        }
        else {
            $this->scheduledForInsert[] = $record;
        }
    }


    /**
     * @return \Dive\Record[]
     */
    public function getScheduledForInsert()
{'fraction_non_alphanumeric': 0.14046328240512568, 'fraction_numerical': 0.002957121734844751, 'mean_word_length': 2.1343629343629344, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 49, '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': '3725379', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1167, 'n_words': 276}