<commit_before><?php

namespace KABBOUCHI\TableView;

class TableViewColumn
{
    protected $title;

    private $propertyName;

    private $customValue;

    private $cast = null;

    public function __construct($title, $value, $cast = null)
    {
        if (is_null($value)) {
            $value = $title;
            $title = '';
        }
        $this->title = ($title === false) ? '' : $title;

        if (is_string($value) && $cast == null) {
            $this->propertyName = $value;
        } else {
            $this->cast = $cast;
            $this->customValue = $value;
        }
    }

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

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

    public function rowValue($model)
    {
        if (! isset($this->customValue)) {
            if (str_contains($this->propertyName, '.')) {
                try {
                    $keys = explode('.', $this->propertyName);

                    $value = $model;

                    foreach ($keys as $key) {
                        $value = $value->{$key};
                    }

                    return $value;
                } catch (\Exception $exception) {
                    //
                }
            }

            if (is_array($model->{$this->propertyName})) {
                return implode(', ', $model->{$this->propertyName});
            }
            
            return $model->{$this->propertyName};
        } else {
            $closure = $this->customValue;

            return is_callable($closure) ? $closure($model) : self::getCastedValue($model->{$this->customValue});
        }
    }

    /**
     * @param mixed $value
     * @return string
     */
    public function getCastedValue($value)
    {
        $array = explode('|', $this->cast);

        $type = $array[0];

        $options = count($array) <= 1 ? [] : explode(',', $array[1]);<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace KABBOUCHI\TableView;

class TableViewColumn
{
    protected $title;

    private $propertyName;

    private $customValue;

    private $cast = null;

    public function __construct($title, $value, $cast = null)
    {
        if (is_null($value)) {
            $value = $title;
            $title = '';
        }
        $this->title = ($title === false) ? '' : $title;

        if (is_string($value) && $cast == null) {
            $this->propertyName = $value;
        } else {
            $this->cast = $cast;
            $this->customValue = $value;
        }
    }

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

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

    public function rowValue($model)
    {
        if (! isset($this->customValue)) {
            if (str_contains($this->propertyName, '.')) {
                try {
                    $keys = explode('.', $this->propertyName);

                    $value = $model;

                    foreach ($keys as $key) {
                        $value = $value->{$key};
                    }

                    return $value;
                } catch (\Exception $exception) {
                    //
                }
            }

            if (is_array($model->{$this->propertyName})) {
                return implode(', ', $model->{$this->propertyName});
            }

            return $model->{$this->propertyName};
        } else {
            $closure = $this->customValue;

            return is_callable($closure) ? $closure($model) : self::getCastedValue($model->{$this->customValue});
        }
    }

    /**
     * @param mixed $value
     * @return string
     */
    public function getCastedValue($value)
    {
        $array = explode('|', $this->cast);

        $type = $array[0];

        $options = count($array) <= 1 ? [] : explode(',', $array[1]);
{'fraction_non_alphanumeric': 0.15337265965632213, 'fraction_numerical': 0.001538856116953065, 'mean_word_length': 1.496798975672215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '4857538', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1062, 'n_words': 214}