<commit_before><?php

namespace Code16\Sharp\Form\Fields\Utils;

use Closure;

trait SharpFormFieldWithUpload
{
    protected ?float $maxFileSize = null;
    protected ?array $cropRatio = null;
    protected ?array $transformableFileTypes = null;
    protected string $storageDisk = 'local';
    protected string|Closure $storageBasePath = 'data';
    protected bool $transformable = true;
    protected ?bool $transformKeepOriginal = null;
    protected bool $compactThumbnail = false;
    protected bool $shouldOptimizeImage = false;
    protected string|array|null $fileFilter = null;

    public function setMaxFileSize(float $maxFileSizeInMB): self
    {
        $this->maxFileSize = $maxFileSizeInMB;

        return $this;
    }

    /**
     * @param  string  $ratio  16:9, 1:1, ...
     * @param  array|null  $transformableFileTypes
     * @return static
     */
    public function setCropRatio(string $ratio = null, array $transformableFileTypes = null): self
    {
        if ($ratio) {
            $this->cropRatio = explode(':', $ratio);

            $this->transformableFileTypes = $transformableFileTypes
                ? $this->formatFileExtension($transformableFileTypes)
                : null;
        } else {
            $this->cropRatio = null;
            $this->transformableFileTypes = null;
        }

        return $this;
    }

    public function shouldOptimizeImage(bool $shouldOptimizeImage = true): self
    {
        $this->shouldOptimizeImage = $shouldOptimizeImage;

        return $this;
    }

    public function isShouldOptimizeImage(): bool
    {
        return $this->shouldOptimizeImage;
    }

    public function setCompactThumbnail(bool $compactThumbnail = true): self
    {
        $this->compactThumbnail = $compactThumbnail;

        return $this;
    }

    /** @deprecated use setTransformable() */
    public function setCroppable(bool $croppable = true): self
    {
        return $this->setTransformable($croppable);
    }

    public function setTransformable(bool $transformable = true, ?bool $transformKeepOriginal = null): self
    {
        $this->transformable = $transformable;

        if ($transformable && ! is_null($transformKeepOriginal)) {
            $this->transformKeepOriginal = $transformKeepOriginal;
        }

        return $this;
    }

    public function isTransformOriginal(): bool
    {
        return $this->transformable && ! $this->transformKeepOriginal();
    }

    public function transformKeepOriginal(): bool
    {
        return $this->transformKeepOriginal ?? config('sharp.uploads.transform_keep_original_image', true);
    }

    public function setStorageDisk(string $storageDisk): self
    {
        $this->storageDisk = $storageDisk;

        return $this;
    }

    /**
     * @param  string|Closure  $storageBasePath
     * @return static
     */
    public function setStorageBasePath($storageBasePath): self
    {
        $this->storageBasePath = $storageBasePath;

        return $this;
    }<commit_msg>Set method to protected<commit_after><?php

namespace Code16\Sharp\Form\Fields\Utils;

use Closure;

trait SharpFormFieldWithUpload
{
    protected ?float $maxFileSize = null;
    protected ?array $cropRatio = null;
    protected ?array $transformableFileTypes = null;
    protected string $storageDisk = 'local';
    protected string|Closure $storageBasePath = 'data';
    protected bool $transformable = true;
    protected ?bool $transformKeepOriginal = null;
    protected bool $compactThumbnail = false;
    protected bool $shouldOptimizeImage = false;
    protected string|array|null $fileFilter = null;

    public function setMaxFileSize(float $maxFileSizeInMB): self
    {
        $this->maxFileSize = $maxFileSizeInMB;

        return $this;
    }

    /**
     * @param  string  $ratio  16:9, 1:1, ...
     * @param  array|null  $transformableFileTypes
     * @return static
     */
    public function setCropRatio(string $ratio = null, array $transformableFileTypes = null): self
    {
        if ($ratio) {
            $this->cropRatio = explode(':', $ratio);

            $this->transformableFileTypes = $transformableFileTypes
                ? $this->formatFileExtension($transformableFileTypes)
                : null;
        } else {
            $this->cropRatio = null;
            $this->transformableFileTypes = null;
        }

        return $this;
    }

    public function shouldOptimizeImage(bool $shouldOptimizeImage = true): self
    {
        $this->shouldOptimizeImage = $shouldOptimizeImage;

        return $this;
    }

    public function isShouldOptimizeImage(): bool
    {
        return $this->shouldOptimizeImage;
    }

    public function setCompactThumbnail(bool $compactThumbnail = true): self
    {
        $this->compactThumbnail = $compactThumbnail;

        return $this;
    }

    /** @deprecated use setTransformable() */
    public function setCroppable(bool $croppable = true): self
    {
        return $this->setTransformable($croppable);
    }

    public function setTransformable(bool $transformable = true, ?bool $transformKeepOriginal = null): self
    {
        $this->transformable = $transformable;

        if ($transformable && ! is_null($transformKeepOriginal)) {
            $this->transformKeepOriginal = $transformKeepOriginal;
        }

        return $this;
    }

    public function isTransformOriginal(): bool
    {
        return $this->transformable && ! $this->transformKeepOriginal();
    }

    protected function transformKeepOriginal(): bool
    {
        return $this->transformKeepOriginal ?? config('sharp.uploads.transform_keep_original_image', true);
    }

    public function setStorageDisk(string $storageDisk): self
    {
        $this->storageDisk = $storageDisk;

        return $this;
    }

    /**
     * @param  string|Closure  $storageBasePath
     * @return static
     */
    public function setStorageBasePath($storageBasePath): self
    {
        $this->storageBasePath = $storageBasePath;

        return $this;
    }
{'fraction_non_alphanumeric': 0.10416321114612705, 'fraction_numerical': 0.0023221098026206667, 'mean_word_length': 2.726823238566131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '3743281', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1638, 'n_words': 369}