<commit_before><?php namespace Orchestra\Authorization;

use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Fluent
{
    /**
     * Collection name.
     *
     * @var string
     */
    protected $name;

    /**
     * Collection of this instance.
     *
     * @var array
     */
    protected $items = [];

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

    /**
     * Add a key to collection.
     *
     * @param  string  $key
     *
     * @return bool
     *
     * @throws \InvalidArgumentException
     */
    public function add($key)
    {
        if (is_null($key)) {
            throw new InvalidArgumentException("Can't add NULL {$this->name}.");
        }

        // Type-hint the attribute value of an Eloquent result, if it was
        // given instead of a string.
        if ($key instanceof Eloquent) {
            $key = $key->getAttribute('name');
        }

        if ($this->has($key)) {
            return false;
        }

        array_push($this->items, $this->getSlugFromName($key));

        return true;
    }

    /**
     * Add multiple key to collection.
     *
     * @param  array  $keys
     *
     * @return bool
     */
    public function attach(array $keys)
    {
        foreach ($keys as $key) {
            $this->add($key);
        }

        return true;
    }

    /**
     * Remove multiple key to collection.
     *
     * @param  array  $keys
     *
     * @return bool
     */
    public function detach(array $keys)
    {
        foreach ($keys as $key) {
            $this->remove($key);
        }

        return true;
    }

    /**
     * Check if an id is set in the collection.
     *
     * @param  int  $id
     *
     * @return bool
     */
    public function exist($id)
    {
        is_string($id) && $id = $this->getSlugFromName($id);

        return isset($this->items[$id]);
    }

    /**
     * Filter request.
     *
     * @param  string|array  $request
     *
     * @return array
     */
    public function filter($request)
    {
        if (is_array($request)) {
            return $request;
        } elseif ($request === '*') {
            return $this->get();
        } elseif ($request[0] === '!') {
            return array_diff($this->get(), [substr($request, 1)]);
        }

        return [$request];
    }

    /**
     * Find collection key from a name.
     *
     * @param  mixed  $name
     *
     * @return int|null
     */
    public function findKey($name)
    {
        if (! (is_numeric($name) && $this->exist($name))) {
            $name = $this->search($name);
        }

        return $name;
    }

    /**
     * Get the items.
     *
     * @return array
     */
    public function get()
    {
        return $this->items;
    }

    /**
     * Determine whether a key exists in collection.
     *
     * @param  string  $key
     *
     * @return bool
     */
    public function has($key)
    {
        $key = strval($key);
        $key = $this->getSlugFromName($key);

        return (! empty($key) && in_array($key, $this->items));
    }

    /**
     * Remove a key from collection.
     *
     * @param  string  $key
     *
     * @return bool
     *
     * @throws \InvalidArgumentException
     */
    public function remove($key)
    {
        if (is_null($key)) {
            throw new InvalidArgumentException("Can't add NULL {$this->name}.");
        }<commit_msg>Fixes wording when throwing exceptions.<commit_after><?php namespace Orchestra\Authorization;

use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Database\Eloquent\Model as Eloquent;

class Fluent
{
    /**
     * Collection name.
     *
     * @var string
     */
    protected $name;

    /**
     * Collection of this instance.
     *
     * @var array
     */
    protected $items = [];

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

    /**
     * Add a key to collection.
     *
     * @param  string  $key
     *
     * @return bool
     *
     * @throws \InvalidArgumentException
     */
    public function add($key)
    {
        if (is_null($key)) {
            throw new InvalidArgumentException("Can't add NULL to {$this->name}.");
        }

        // Type-hint the attribute value of an Eloquent result, if it was
        // given instead of a string.
        if ($key instanceof Eloquent) {
            $key = $key->getAttribute('name');
        }

        if ($this->has($key)) {
            return false;
        }

        array_push($this->items, $this->getSlugFromName($key));

        return true;
    }

    /**
     * Add multiple key to collection.
     *
     * @param  array  $keys
     *
     * @return bool
     */
    public function attach(array $keys)
    {
        foreach ($keys as $key) {
            $this->add($key);
        }

        return true;
    }

    /**
     * Remove multiple key to collection.
     *
     * @param  array  $keys
     *
     * @return bool
     */
    public function detach(array $keys)
    {
        foreach ($keys as $key) {
            $this->remove($key);
        }

        return true;
    }

    /**
     * Check if an id is set in the collection.
     *
     * @param  int  $id
     *
     * @return bool
     */
    public function exist($id)
    {
        is_string($id) && $id = $this->getSlugFromName($id);

        return isset($this->items[$id]);
    }

    /**
     * Filter request.
     *
     * @param  string|array  $request
     *
     * @return array
     */
    public function filter($request)
    {
        if (is_array($request)) {
            return $request;
        } elseif ($request === '*') {
            return $this->get();
        } elseif ($request[0] === '!') {
            return array_diff($this->get(), [substr($request, 1)]);
        }

        return [$request];
    }

    /**
     * Find collection key from a name.
     *
     * @param  mixed  $name
     *
     * @return int|null
     */
    public function findKey($name)
    {
        if (! (is_numeric($name) && $this->exist($name))) {
            $name = $this->search($name);
        }

        return $name;
    }

    /**
     * Get the items.
     *
     * @return array
     */
    public function get()
    {
        return $this->items;
    }

    /**
     * Determine whether a key exists in collection.
     *
     * @param  string  $key
     *
     * @return bool
     */
    public function has($key)
    {
        $key = strval($key);
        $key = $this->getSlugFromName($key);

        return (! empty($key) && in_array($key, $this->items));
    }

    /**
     * Remove a key from collection.
     *
     * @param  string  $key
     *
     * @return bool
     *
     * @throws \InvalidArgumentException
     */
    public function remove($key)
    {
        if (is_null($key)) {
            throw new InvalidArgumentException("Can't remove NULL from {$this->name}.");
        }
{'fraction_non_alphanumeric': 0.13914863921842288, 'fraction_numerical': 0.0005582693649685974, 'mean_word_length': 1.5447443181818181, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '2947520', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2138, 'n_words': 524}