<commit_before><?php
/**
 * Implementation of the `phing\smartling\tasks\UploadTask` class.
 */
namespace phing\smartling\tasks;

use phing\smartling\FileType;
use Smartling\Exceptions\SmartlingApiException;
use Smartling\File\Params\UploadFileParameters;

/**
 * Uploads the message translations to the [Smartling](https://www.smartling.com) server.
 */
class UploadTask extends FileTask {

  /**
   * @var \PhingFile The path to the message source.
   */
  private $file;

  /**
   * @var string The file type.
   */
  private $fileType = '';

  /**
   * @var UploadFileParameters The upload parameters.
   */
  private $params;

  /**
   * Initializes a new instance of the class.
   */
  public function __construct() {
    $this->params = new UploadFileParameters();
  }

  /**
   * Gets a value indicating whether to return the original string or an empty string when no translation is available.
   * @return bool `true` to return the original string when no translation is available, otherwise `false`. Defaults to `false`.
   */
  public function getAuthorize(): bool {
    return $this->params->exportToArray()['authorize'] ?? false;
  }

  /**
   * Gets the path to the message source.
   * @return \PhingFile The path to the message source.
   */
  public function getFile(): \PhingFile {
    return $this->file;
  }

  /**
   * Gets a value that uniquely identifies the file.
   * @return string The current file type.
   */
  public function getFileType(): string {
    return $this->fileType;
  }

  /**
   * Initializes the instance.
   * @throws \BuildException The requirements are not met.
   */
  public function init() {
    parent::init();

    $fileType = $this->getFileType();
    if(mb_strlen($fileType) && !FileType::isDefined($fileType)) throw new \BuildException('File type not supported.');

    $file = $this->getFile();
    if(!$file || !is_file($file->getAbsolutePath())) throw new \BuildException('Unable to find the message source.');
  }

  /**
   * The task entry point.
   */
  public function main() {
    $fileType = $this->getFileType();
    $fileUri = $this->getFileUri();

    try {
      $this->createFileApi()->uploadFile(
        $this->getFile()->getAbsolutePath(),
        $fileUri,
        mb_strlen($fileType) ? $fileType : static::getFileTypeFromUri($fileUri),
        $this->params
      );
    }

    catch(SmartlingApiException $e) {
      throw new \BuildException($e);
    }
  }

  /**
   * Sets a value indicating whether to return the original string or an empty string when no translation is available.
   * @param bool $value `true` to return the original string when no translation is available, otherwise `false`.
   */
  public function setAuthorize(bool $value) {
    $this->params->setAuthorized($value);
  }

  /**
   * Sets the path to the message source.
   * @param \PhingFile $value The new path of the message source.
   */
  public function setFile(\PhingFile $value) {
    $this->file = $value;
  }

  /**
   * Sets a value that uniquely identifies the file.
   * @param string $value The new file type.
   */
  public function setFileType(string $value) {
    $this->fileType = $value;
  }
}<commit_msg>Added new properties to UploadTask class<commit_after><?php
/**
 * Implementation of the `phing\smartling\tasks\UploadTask` class.
 */
namespace phing\smartling\tasks;

use phing\smartling\FileType;
use Smartling\Exceptions\SmartlingApiException;
use Smartling\File\Params\UploadFileParameters;

/**
 * Uploads the message translations to the [Smartling](https://www.smartling.com) server.
 */
class UploadTask extends FileTask {

  /**
   * @var \PhingFile The path to the message source.
   */
  private $file;

  /**
   * @var string The file type.
   */
  private $fileType = '';

  /**
   * @var UploadFileParameters The upload parameters.
   */
  private $params;

  /**
   * Initializes a new instance of the class.
   */
  public function __construct() {
    $this->params = new UploadFileParameters();
  }

  /**
   * Gets a value indicating whether content in the file is authorized (available for translation) in all locales.
   * @return bool `true` to authorize the file content in all locales, otherwise `false`.
   */
  public function getAuthorize(): bool {
    return $this->params->exportToArray()['authorize'] ?? false;
  }

  /**
   * Gets the URL of the callback called when the file is 100% published for a locale.
   * @return string The callback URL.
   */
  public function getCallbackUrl(): string {
    return $this->params->exportToArray()['callbackUrl'] ?? '';
  }

  /**
   * Gets the path to the message source.
   * @return \PhingFile The path to the message source.
   */
  public function getFile(): \PhingFile {
    return $this->file;
  }

  /**
   * Gets a value that uniquely identifies the file.
   * @return string The current file type.
   */
  public function getFileType(): string {
    return $this->fileType;
  }

  /**
   * Gets the list of specific locales in which the file content is authorized (available for translation).
   * @return array The list of authorized locales.
   */
  public function getLocalesToAuthorize(): array {
    return $this->params->exportToArray()['localeIdsToAuthorize[]'] ?? [];
  }

  /**
   * Initializes the instance.
   * @throws \BuildException The requirements are not met.
   */
  public function init() {
    parent::init();

    $fileType = $this->getFileType();
    if(mb_strlen($fileType) && !FileType::isDefined($fileType)) throw new \BuildException('File type not supported.');

    $file = $this->getFile();
    if(!$file || !is_file($file->getAbsolutePath())) throw new \BuildException('Unable to find the message source.');
  }

  /**
   * The task entry point.
   */
  public function main() {
    $fileType = $this->getFileType();
    $fileUri = $this->getFileUri();

    try {
      $this->createFileApi()->uploadFile(
        $this->getFile()->getAbsolutePath(),
        $fileUri,
        mb_strlen($fileType) ? $fileType : static::getFileTypeFromUri($fileUri),
        $this->params
      );
    }

    catch(SmartlingApiException $e) {
      throw new \BuildException($e);
    }
  }

  /**
   * Sets a value indicating whether content in the file is authorized (available for translation) in all locales.
   * @param bool $value `true` to authorize the file content in all locales, otherwise `false`.
   */
  public function setAuthorize(bool $value) {
    $this->params->setAuthorized($value);
  }

  /**
   * Sets the URL of the callback called when the file is 100% published for a locale.
   * @param string $value The new callback URL.
   */
  public function setCallbackUrl(string $value) {
    $this->params->setCallbackUrl($value);
  }

  /**
   * Sets the path to the message source.
   * @param \PhingFile $value The new path of the message source.
   */
  public function setFile(\PhingFile $value) {
    $this->file = $value;
  }

  /**
   * Sets a value that uniquely identifies the file.
   * @param string $value The new file type.
   */
  public function setFileType(string $value) {
    $this->fileType = $value;
  }

  /**
   * Sets the list of specific locales for which the file content is authorized (available for translation).
   * @param array $values The new list of authorized locales.
   */
  public function setLocalesToAuthorize(array $values) {
    $this->params->setLocalesToApprove($values);
  }
}
{'fraction_non_alphanumeric': 0.1260129659643436, 'fraction_numerical': 0.0008103727714748784, 'mean_word_length': 3.1230512249443207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '1844582', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2135, 'n_words': 692}