<commit_before><?php

final class PhabricatorManiphestTaskTestDataGenerator
  extends PhabricatorTestDataGenerator {

  public function generate() {
    return id(new ManiphestTask())
      ->setStatus($this->generateTaskStatus())
      ->setPriority($this->generateTaskPriority())
      ->setSubPriority($this->generateTaskSubPriority())
      ->setAuthorPHID($this->loadAuthorPHID())
      ->setTitle($this->generateTitle())
      ->setDescription($this->generateDescription())
      ->setOwnerPHID($this->loadOwnerPHID())
      ->save();
  }

  private function loadPhabrictorUserPHID() {
    return $this->loadOneRandom("PhabricatorUser")->getPHID();
  }

  public function loadAuthorPHID() {
    return $this->loadPhabrictorUserPHID();
  }

  public function loadOwnerPHID() {
    if (rand(0, 3) == 0) {<commit_msg>Task Generation with Transactions, Auxiliary Fields, and Projects<commit_after><?php

final class PhabricatorManiphestTaskTestDataGenerator
  extends PhabricatorTestDataGenerator {

  public function generate() {
    $authorPHID = $this->loadAuthorPHID();
    $author = id(new PhabricatorUser())
          ->loadOneWhere('phid = %s', $authorPHID);
    $task = id(new ManiphestTask())
      ->setSubPriority($this->generateTaskSubPriority())
      ->setAuthorPHID($authorPHID)
      ->setTitle($this->generateTitle());
    $content_source = PhabricatorContentSource::newForSource(
      PhabricatorContentSource::SOURCE_UNKNOWN,
      array());
    $template = id(new ManiphestTransaction())
      ->setAuthorPHID($authorPHID)
      ->setContentSource($content_source);
    // Accumulate Transactions
    $changes = array();
    $changes[ManiphestTransactionType::TYPE_TITLE] =
      $this->generateTitle();
    $changes[ManiphestTransactionType::TYPE_DESCRIPTION] =
      $this->generateDescription();
    $changes[ManiphestTransactionType::TYPE_OWNER] =
      $this->loadOwnerPHID();
    $changes[ManiphestTransactionType::TYPE_STATUS] =
      $this->generateTaskStatus();
    $changes[ManiphestTransactionType::TYPE_PRIORITY] =
      $this->generateTaskPriority();
    $changes[ManiphestTransactionType::TYPE_CCS] =
      $this->getCCPHIDs();
    $changes[ManiphestTransactionType::TYPE_PROJECTS] =
      $this->getProjectPHIDs();
    $transactions = array();
    foreach ($changes as $type => $value) {
      $transaction = clone $template;
      $transaction->setTransactionType($type);
      $transaction->setNewValue($value);
      $transactions[] = $transaction;
    }
    // Accumulate Auxiliary Transactions
    $aux_fields = id(ManiphestTaskExtensions::newExtensions())
      ->loadFields($task, $author);
    if ($aux_fields) {
      foreach ($aux_fields as $aux_field) {
        $transaction = clone $template;
        $transaction->setTransactionType(
          ManiphestTransactionType::TYPE_AUXILIARY);
        $aux_key = $aux_field->getAuxiliaryKey();
        $transaction->setMetadataValue('aux:key', $aux_key);
        $transaction->setNewValue($aux_field->getValueForStorage());
        $transactions[] = $transaction;
      }
    }
    // Apply Transactions
    $editor = id(new ManiphestTransactionEditor())
      ->setActor($author)
      ->applyTransactions($task, $transactions);
    return $task->save();
  }

  public function getCCPHIDs() {
    $ccs = array();
    for ($i = 0; $i < rand(1, 4);$i++) {
      $ccs[] = $this->loadPhabrictorUserPHID();
    }
    return $ccs;
  }

  public function getProjectPHIDs() {
    $projects = array();
    for ($i = 0; $i < rand(1, 4);$i++) {
      $projects[] = $this->loadOneRandom("PhabricatorProject")->getPHID();
    }
    return $projects;
  }

  private function loadPhabrictorUserPHID() {
    return $this->loadOneRandom("PhabricatorUser")->getPHID();
  }

  public function loadAuthorPHID() {
    return $this->loadPhabrictorUserPHID();
  }

  public function loadOwnerPHID() {
    if (rand(0, 3) == 0) {
{'fraction_non_alphanumeric': 0.14490895101308027, 'fraction_numerical': 0.00307771223390613, 'mean_word_length': 3.949238578680203, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 55, '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': '4444746', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1184, 'n_words': 190}