<commit_before><?php namespace vendocrat\Followers\Traits;

use vendocrat\Followers\Exceptions\AlreadyFollowingException;
use vendocrat\Followers\Exceptions\CannotBeFollowedException;
use vendocrat\Followers\Exceptions\FollowerNotFoundException;
use vendocrat\Followers\Models\Followable;

use Illuminate\Database\Eloquent\Model;

/**
 * Class CanFollowTrait
 * @package vendocrat\Followers\Traits
 */
trait CanFollowTrait
{
	/**
	 * Get all followable items this model morphs to as a follower
	 *
	 * @return \Illuminate\Database\Eloquent\Relations\MorphMany
	 */
	public function followables()
	{
		return $this->morphMany(Followable::class, 'follower');
	}

	/**
	 * @param $query
	 * @return mixed
	 */
	public function scopeFollows( $query )
	{
		$model = $this;
		return $query->whereHas('followables', function($q) use($model) {
			$q->where('follower_id',   $model->id);
			$q->where('follower_type', get_class($model));
		});
	}

	/**
	 * Follow method
	 *
	 * @param Model $followable
	 * @return mixed
	 * @throws AlreadyFollowingException
	 * @throws CannotBeFollowedException
	 */
	public function follow( Model $followable )
	{
		if ( $isFollower = $this->isFollowing($followable) !== false )
		{
			throw new AlreadyFollowingException( get_class($this) .'::'. $this->id .' is already following '. get_class($followable) .'::'. $followable->id );
		}

		if ( $followable->follower() )
		{
			return Followable::create([
				'follower_id'     => $this->id,
				'follower_type'   => get_class($this),
				'followable_id'   => $followable->id,
				'followable_type' => get_class($followable),
			]);
		}

		throw new CannotBeFollowedException( get_class($followable) .'::'. $followable->id .' cannot be followed.' );
	}

	/**
	 * Unfollow method
	 *
	 * @param Model $followable
	 * @return mixed
	 * @throws FollowerNotFoundException
	 */
	public function unfollow( Model $followable )
	{
		if ( $isFollower = $this->isFollowing($followable) === true )
		{
			return Followable::
				  following( $followable )
				->followedBy( $this )
				->delete();
		}

		throw new FollowerNotFoundException( get_class($this) .'::'. $this->id .' is not following '. get_class($followable) .'::'. $followable->id );
	}

	/**
	 * @param $followable
	 * @return bool
	 */
	public function isFollowing( $followable )
	{
		$query = Followable::
			  following( $followable )
			->followedBy( $this );

		return $query->count() > 0;
	}

	/**
	 * @return mixed
	 */
	public function getFollowingCount( $type = '' )
	{
		$followables = Followable::
		      where('follower_id',   $this->id)
			->where('follower_type', get_class($this))
			//	->where( 'followable_type', 'like', '%'. $type .'%' );
			->get();

		return $followables->count();
	}

	/**
	 * @param  int    $limit
	 * @param  string $type
	 * @return mixed
	 */
	public function getFollowing( $limit = 0, $type = '' )
	{
		if ( $type ) {
			$followables = $this->followables()->where('followable_type', $type)->get();
		} else {
			$followables = $this->followables()->get();
		}

		$return = array();
		foreach ( $followables as $followable )
		{
			$return[] = $followable->followable()->first();
		}

		$collection = collect($return)->shuffle();

		if ( $limit == 0 )
			return $collection;

		return $collection->take($limit);
	}

	/**
	 * @param int $limit
	 * @param string $type
	 * @return mixed
	 */
	public function getFollowingSuggests( $limit = 5, $type = '' )
	{
		if ( $type ) {
			$followables = Followable::
				  where('follower_id',     '<>', $this->id)
				->where('follower_type',   get_class($this))
				->where('followable_type', 'like', '%'. $type .'%')
				->orderBy(\DB::raw('RAND()'))
				->take($limit)
				->get();
		} else {
			$followables = Followable::
				  where('follower_id',   '<>', $this->id)
				->where('follower_type', get_class($this))
				->orderBy(\DB::raw('RAND()'))
				->take($limit)
				->get();
		}

		$return = array();
		foreach ( $followables as $followable )
		{
			$followable = $followable->followable()->first();

			if ( $this->isFollowing($followable) )
				continue;

			$return[] = $followable;
		}

		$collection = collect(array_unique($return))->shuffle();

		if ( $limit == 0 )
			return $collection;

		return $collection->take($limit);
	}
}<commit_msg>Remove suggest function<commit_after><?php namespace vendocrat\Followers\Traits;

use vendocrat\Followers\Exceptions\AlreadyFollowingException;
use vendocrat\Followers\Exceptions\CannotBeFollowedException;
use vendocrat\Followers\Exceptions\FollowerNotFoundException;
use vendocrat\Followers\Models\Followable;

use Illuminate\Database\Eloquent\Model;

/**
 * Class CanFollowTrait
 * @package vendocrat\Followers\Traits
 */
trait CanFollowTrait
{
	/**
	 * Get all followable items this model morphs to as a follower
	 *
	 * @return \Illuminate\Database\Eloquent\Relations\MorphMany
	 */
	public function followables()
	{
		return $this->morphMany(Followable::class, 'follower');
	}

	/**
	 * @param $query
	 * @return mixed
	 */
	public function scopeFollows( $query )
	{
		$model = $this;
		return $query->whereHas('followables', function($q) use($model) {
			$q->where('follower_id',   $model->id);
			$q->where('follower_type', get_class($model));
		});
	}

	/**
	 * Follow method
	 *
	 * @param Model $followable
	 * @return mixed
	 * @throws AlreadyFollowingException
	 * @throws CannotBeFollowedException
	 */
	public function follow( Model $followable )
	{
		if ( $isFollower = $this->isFollowing($followable) !== false )
		{
			throw new AlreadyFollowingException( get_class($this) .'::'. $this->id .' is already following '. get_class($followable) .'::'. $followable->id );
		}

		if ( $followable->follower() )
		{
			return Followable::create([
				'follower_id'     => $this->id,
				'follower_type'   => get_class($this),
				'followable_id'   => $followable->id,
				'followable_type' => get_class($followable),
			]);
		}

		throw new CannotBeFollowedException( get_class($followable) .'::'. $followable->id .' cannot be followed.' );
	}

	/**
	 * Unfollow method
	 *
	 * @param Model $followable
	 * @return mixed
	 * @throws FollowerNotFoundException
	 */
	public function unfollow( Model $followable )
	{
		if ( $isFollower = $this->isFollowing($followable) === true )
		{
			return Followable::
				  following( $followable )
				->followedBy( $this )
				->delete();
		}

		throw new FollowerNotFoundException( get_class($this) .'::'. $this->id .' is not following '. get_class($followable) .'::'. $followable->id );
	}

	/**
	 * @param $followable
	 * @return bool
	 */
	public function isFollowing( $followable )
	{
		$query = Followable::
			  following( $followable )
			->followedBy( $this );

		return $query->count() > 0;
	}

	/**
	 * @return mixed
	 */
	public function getFollowingCount( $type = '' )
	{
		$followables = Followable::
		      where('follower_id',   $this->id)
			->where('follower_type', get_class($this))
			//	->where( 'followable_type', 'like', '%'. $type .'%' );
			->get();

		return $followables->count();
	}

	/**
	 * @param  int    $limit
	 * @param  string $type
	 * @return mixed
	 */
	public function getFollowing( $limit = 0, $type = '' )
	{
		if ( $type ) {
			$followables = $this->followables()->where('followable_type', $type)->get();
		} else {
			$followables = $this->followables()->get();
		}

		$return = [];
		foreach ( $followables as $followable )
		{
			$return[] = $followable->followable()->first();
		}

		$collection = collect($return)->shuffle();

		if ( $limit == 0 )
			return $collection;

		return $collection->take($limit);
	}
}
{'fraction_non_alphanumeric': 0.1759662313678934, 'fraction_numerical': 0.001055269753330695, 'mean_word_length': 3.5840386940749696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 97, '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': '6117921', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2487, 'n_words': 495}