<commit_before><?php

namespace ETS\DocumentStorage\Client;

use Aws\S3\S3Client;

use ETS\DocumentStorage\Exception\DocumentNotFoundException;
use ETS\DocumentStorage\Exception\DocumentNotUploadedException;

class S3 implements ClientInterface
{
    /**
     * @var Aws\S3\S3Client
     */
    private $s3Client;

    /**
     * @var string
     */
    private $bucket;

    /**
     * @param Aws\S3\S3Client $s3Client
     * @param string          $bucket
     */
    public function __construct(S3Client $s3Client, $bucket)
    {
        $this->s3Client = $s3Client;
        $this->bucket = $bucket;
    }

    /**
     * @see DocumentStorage::upload
     */
    public function upload($pathOrBody, $docName = null, $oldDocKey = null)
    {
        try {
            $result = $this->s3Client->upload(
                $this->bucket,
                $docName,
                $pathOrBody
            );
        } catch (\Exception $e) {
            throw new DocumentNotUploadedException(
                sprintf('There was an error uploading the file [%s]', $e->getMessage())
            );
        }

        // We can poll the object until it is accessible
        $this->s3Client->waitUntil('ObjectExists', array(
            'Bucket' => $this->bucket,
            'Key'    => $docName
        ));

        return $result['ObjectURL'];
    }

    /**
     * @see DocumentStorage::download
     */
    public function download($docKey)
    {
        $result = $this->s3Client->getObject(array(
            'Bucket' => $this->bucket,
            'Key'    => $docKey
        ));<commit_msg>fixed  not being converted to body for upload() call<commit_after><?php

namespace ETS\DocumentStorage\Client;

use Aws\S3\S3Client;

use ETS\DocumentStorage\Exception\DocumentNotFoundException;
use ETS\DocumentStorage\Exception\DocumentNotUploadedException;

class S3 implements ClientInterface
{
    /**
     * @var Aws\S3\S3Client
     */
    private $s3Client;

    /**
     * @var string
     */
    private $bucket;

    /**
     * @param Aws\S3\S3Client $s3Client
     * @param string          $bucket
     */
    public function __construct(S3Client $s3Client, $bucket)
    {
        $this->s3Client = $s3Client;
        $this->bucket = $bucket;
    }

    /**
     * @see DocumentStorage::upload
     */
    public function upload($pathOrBody, $docName = null, $oldDocKey = null)
    {
        try {
            $result = $this->s3Client->upload(
                $this->bucket,
                $docName,
                file_exists($pathOrBody) ? file_get_contents($pathOrBody) : $pathOrBody
            );
        } catch (\Exception $e) {
            throw new DocumentNotUploadedException(
                sprintf('There was an error uploading the file [%s]', $e->getMessage())
            );
        }

        // We can poll the object until it is accessible
        $this->s3Client->waitUntil('ObjectExists', array(
            'Bucket' => $this->bucket,
            'Key'    => $docName
        ));

        return $result['ObjectURL'];
    }

    /**
     * @see DocumentStorage::download
     */
    public function download($docKey)
    {
        $result = $this->s3Client->getObject(array(
            'Bucket' => $this->bucket,
            'Key'    => $docKey
        ));
{'fraction_non_alphanumeric': 0.1278538812785388, 'fraction_numerical': 0.009741248097412482, 'mean_word_length': 1.892605633802817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500807', 'n_tokens_mistral': 977, 'n_tokens_neox': 960, 'n_words': 198}