<commit_before><?php

namespace Adldap\Models\Traits;

use Adldap\Models\Group;
use Adldap\Schemas\ActiveDirectory;

trait HasMemberOfTrait
{
    /**
     * {@inheritdoc}
     */
    public function getGroups()
    {
        return $this->getMemberOf();
    }

    /**
     * {@inheritdoc}
     */
    public function setGroups(array $groups)
    {
        return $this->setMemberOf($groups);
    }

    /**
     * Returns an array of groups the model is a member of.
     *
     * https://msdn.microsoft.com/en-us/library/ms677099(v=vs.85).aspx
     *
     * @return array
     */
    public function getMemberOf()
    {
        $groups = [];

        $dns = $this->getAttribute(ActiveDirectory::MEMBER_OF);

        if(is_array($dns)) {
            unset($dns['count']);

            foreach($dns as $key => $dn) {
                $groups[] = $this->getAdldap()->search()->findByDn($dn);
            }
        }

        return $groups;
    }

    /**
     * Sets the models's group DN's the entry is a member of.
     *
     * @param array $groups
     *
     * @return \Adldap\Models\Entry
     */
    public function setMemberOf(array $groups)
    {
        return $this->setAttribute(ActiveDirectory::MEMBER_OF, $groups);
    }

    /**
     * Returns true / false if the current user
     * is in the specified group.
     *
     * @param string|Group $group
     *
     * @return bool
     */
    public function inGroup($group)
    {
        $groups = $this->getGroups();

        if ($group instanceof Group) {
            if(in_array($group, $groups)) {
                return true;
            }
        } else if (is_string($group)) {
            foreach($groups as $model) {
                if($group == $model->getName()) {
                    return true;
                }
            }<commit_msg>Small doc tweak<commit_after><?php

namespace Adldap\Models\Traits;

use Adldap\Models\Group;
use Adldap\Schemas\ActiveDirectory;

trait HasMemberOfTrait
{
    /**
     * {@inheritdoc}
     */
    public function getGroups()
    {
        return $this->getMemberOf();
    }

    /**
     * {@inheritdoc}
     */
    public function setGroups(array $groups)
    {
        return $this->setMemberOf($groups);
    }

    /**
     * Returns an array of groups the model is a member of.
     *
     * https://msdn.microsoft.com/en-us/library/ms677099(v=vs.85).aspx
     *
     * @return array
     */
    public function getMemberOf()
    {
        $groups = [];

        $dns = $this->getAttribute(ActiveDirectory::MEMBER_OF);

        if(is_array($dns)) {
            unset($dns['count']);

            foreach($dns as $key => $dn) {
                $groups[] = $this->getAdldap()->search()->findByDn($dn);
            }
        }

        return $groups;
    }

    /**
     * Sets the models's group DN's the entry is a member of.
     *
     * @param array $groups
     *
     * @return \Adldap\Models\Entry
     */
    public function setMemberOf(array $groups)
    {
        return $this->setAttribute(ActiveDirectory::MEMBER_OF, $groups);
    }

    /**
     * Returns true / false if the current model
     * is in the specified group.
     *
     * @param string|Group $group
     *
     * @return bool
     */
    public function inGroup($group)
    {
        $groups = $this->getGroups();

        if ($group instanceof Group) {
            if(in_array($group, $groups)) {
                return true;
            }
        } else if (is_string($group)) {
            foreach($groups as $model) {
                if($group == $model->getName()) {
                    return true;
                }
            }
{'fraction_non_alphanumeric': 0.13652628681530415, 'fraction_numerical': 0.004404073768235618, 'mean_word_length': 1.689859363434493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '6525553', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1089, 'n_words': 232}