<commit_before><?php

namespace Railken\Lem\Attributes;

use Closure;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Railken\Bag;
use Railken\Lem\Concerns;
use Railken\Lem\Contracts\AttributeContract;
use Railken\Lem\Contracts\EntityContract;
use Railken\Lem\Exceptions as Exceptions;
use Railken\Lem\Tokens;
use Respect\Validation\Validator as v;

abstract class BaseAttribute implements AttributeContract
{
    use Concerns\HasManager;
    use Concerns\HasPermissions;
    use Concerns\HasExceptions;

    /**
     * @var string
     */
    protected $name;

    /**
     * Is the attribute required
     * This will throw not_defined exception for non defined value and non existent model.
     *
     * @var bool
     */
    protected $required = false;

    /**
     * Is the attribute unique.
     *
     * @var bool
     */
    protected $unique = false;

    /**
     * Is the attribute fillable.
     *
     * @var bool
     */
    protected $fillable = false;

    /**
     * Is the attribute hidden.
     *
     * @var bool
     */
    protected $hidden = false;

    /**
     * A comment.
     *
     * @var string
     */
    protected $comment;

    /**
     * Default closure.
     *
     * @var Closure
     */
    protected $default;

    /**
     * Default value.
     *
     * @var mixed
     */
    protected $defaultValue = null;

    /**
     * Default value.
     *
     * @var Closure
     */
    protected $validator;

    /**
     * Schema of the attribute
     *
     * @var string
     */
    protected $schema = 'basic';

    /**
     * List of all exceptions used in validation.
     *
     * @var array
     */
    protected $exceptions = [
        Tokens::NOT_DEFINED    => Exceptions\AttributeNotDefinedException::class,
        Tokens::NOT_VALID      => Exceptions\AttributeNotValidException::class,
        Tokens::NOT_AUTHORIZED => Exceptions\AttributeNotAuthorizedException::class,
        Tokens::NOT_UNIQUE     => Exceptions\AttributeNotUniqueException::class,
    ];

    /**
     * List of all permissions.
     */
    protected $permissions = [
        Tokens::PERMISSION_WRITE => '%s.attributes.%s.write',
        Tokens::PERMISSION_READ => '%s.attributes.%s.read',
    ];

    /**
     * Create a new instance.
     *
     * @param string $name
     */
    public function __construct(string $name = null)
    {
        if ($name !== null) {
            $this->name = $name;
        }
    }

    /**
     * Create a new instance.
     */
    public static function make()
    {
        return new static(...func_get_args());
    }

    /**
     * Boot permissions.
     */
    public function bootPermissions()
    {
        $name = Str::kebab($this->getManager()->getName());
        $pName = Str::kebab($this->getName());

        foreach ($this->permissions as $token => $permission) {
            $this->permissions[$token] = sprintf($permission, $pName, $name);
        }
    }

    /**
     * Create a new instance of exception.
     *
     * @param string $code
     * @param mixed  $value
     * @param mixed $error<commit_msg>fix permissions<commit_after><?php

namespace Railken\Lem\Attributes;

use Closure;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Railken\Bag;
use Railken\Lem\Concerns;
use Railken\Lem\Contracts\AttributeContract;
use Railken\Lem\Contracts\EntityContract;
use Railken\Lem\Exceptions as Exceptions;
use Railken\Lem\Tokens;
use Respect\Validation\Validator as v;

abstract class BaseAttribute implements AttributeContract
{
    use Concerns\HasManager;
    use Concerns\HasPermissions;
    use Concerns\HasExceptions;

    /**
     * @var string
     */
    protected $name;

    /**
     * Is the attribute required
     * This will throw not_defined exception for non defined value and non existent model.
     *
     * @var bool
     */
    protected $required = false;

    /**
     * Is the attribute unique.
     *
     * @var bool
     */
    protected $unique = false;

    /**
     * Is the attribute fillable.
     *
     * @var bool
     */
    protected $fillable = false;

    /**
     * Is the attribute hidden.
     *
     * @var bool
     */
    protected $hidden = false;

    /**
     * A comment.
     *
     * @var string
     */
    protected $comment;

    /**
     * Default closure.
     *
     * @var Closure
     */
    protected $default;

    /**
     * Default value.
     *
     * @var mixed
     */
    protected $defaultValue = null;

    /**
     * Default value.
     *
     * @var Closure
     */
    protected $validator;

    /**
     * Schema of the attribute
     *
     * @var string
     */
    protected $schema = 'basic';

    /**
     * List of all exceptions used in validation.
     *
     * @var array
     */
    protected $exceptions = [
        Tokens::NOT_DEFINED    => Exceptions\AttributeNotDefinedException::class,
        Tokens::NOT_VALID      => Exceptions\AttributeNotValidException::class,
        Tokens::NOT_AUTHORIZED => Exceptions\AttributeNotAuthorizedException::class,
        Tokens::NOT_UNIQUE     => Exceptions\AttributeNotUniqueException::class,
    ];

    /**
     * List of all permissions.
     */
    protected $permissions = [
        Tokens::PERMISSION_WRITE => '%s.attributes.%s.write',
        Tokens::PERMISSION_READ => '%s.attributes.%s.read',
    ];

    /**
     * Create a new instance.
     *
     * @param string $name
     */
    public function __construct(string $name = null)
    {
        if ($name !== null) {
            $this->name = $name;
        }
    }

    /**
     * Create a new instance.
     */
    public static function make()
    {
        return new static(...func_get_args());
    }

    /**
     * Boot permissions.
     */
    public function bootPermissions()
    {
        $name = Str::kebab($this->getManager()->getName());
        $pName = Str::kebab($this->getName());

        foreach ($this->permissions as $token => $permission) {
            $this->permissions[$token] = sprintf($permission, $name, $pName);
        }
    }

    /**
     * Create a new instance of exception.
     *
     * @param string $code
     * @param mixed  $value
     * @param mixed $error
{'fraction_non_alphanumeric': 0.12274024738344434, 'fraction_numerical': 0.0, 'mean_word_length': 2.0351299326275263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '6518279', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1857, 'n_words': 438}