<commit_before><?php
namespace Ora\ReadModel;

use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Ora\User\User;

/**
 * @ORM\Entity @ORM\Table(name="accounts")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @author andreabandera
 *
 */
class Account extends EditableEntity {
	
	/**
	 * @ORM\Embedded(class="Ora\ReadModel\Balance")
	 * @var Balance
	 */
	protected $balance;
	/**
	 * @ORM\ManyToMany(targetEntity="Ora\User\User", cascade={"PERSIST", "REMOVE"}, indexBy="user_id")
	 * @ORM\JoinTable(name="account_holders", joinColumns={@ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE")},
	 * 		inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")}
	 * )
	 * @var User[]
	 */
	protected $holders;
	/**
	 * @ORM\OneToMany(targetEntity="Ora\ReadModel\AccountTransaction", mappedBy="account", cascade="persist", fetch="LAZY")
	 * @ORM\OrderBy({"createdAt" = "DESC"})
	 * @var AccountTransaction[]
	 */
	protected $transactions;
	
	/**
	 * @ORM\OneToOne(targetEntity="Organization")
	 * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", nullable=true)
	 * @var Organization
	 */
	protected $organization;
	
	public function __construct($id) {
		parent::__construct($id);
		$this->holders = new ArrayCollection();
		$this->transactions = new ArrayCollection();
	}
	
	public function setBalance(Balance $balance) {
		$this->balance = $balance;
		return $this;
	}
	
	public function getBalance() {
		return $this->balance;
	}
	
	public function getHolders() {
		return $this->holders;
	}
	
	public function addHolder(User $holder) {
		$this->holders->set($holder->getId(), $holder);
		return $this;
	}
	
	public function getTransactions() {
		return $this->transactions;
	}
	
	public function addTransaction(AccountTransaction $transaction) {
		$this->transactions->add($transaction);
		return $this;
	}
	
	public function isHeldBy(User $user) {
		return $this->holders->exists(function($key, $value) use ($user) {
			return $user->equals($value);
		});
	}
}<commit_msg>Fix isHeldBy bug related to wrong indexing of holders<commit_after><?php
namespace Ora\ReadModel;

use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Ora\User\User;

/**
 * @ORM\Entity @ORM\Table(name="accounts")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @author andreabandera
 *
 */
class Account extends EditableEntity {
	
	/**
	 * @ORM\Embedded(class="Ora\ReadModel\Balance")
	 * @var Balance
	 */
	protected $balance;
	/**
	 * @ORM\ManyToMany(targetEntity="Ora\User\User", cascade={"PERSIST", "REMOVE"}, indexBy="id")
	 * @ORM\JoinTable(name="account_holders", joinColumns={@ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE")},
	 * 		inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")}
	 * )
	 * @var User[]
	 */
	protected $holders;
	/**
	 * @ORM\OneToMany(targetEntity="Ora\ReadModel\AccountTransaction", mappedBy="account", cascade="persist", fetch="LAZY")
	 * @ORM\OrderBy({"createdAt" = "DESC"})
	 * @var AccountTransaction[]
	 */
	protected $transactions;
	
	/**
	 * @ORM\OneToOne(targetEntity="Organization")
	 * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", nullable=true)
	 * @var Organization
	 */
	protected $organization;
	
	public function __construct($id) {
		parent::__construct($id);
		$this->holders = new ArrayCollection();
		$this->transactions = new ArrayCollection();
	}
	
	public function setBalance(Balance $balance) {
		$this->balance = $balance;
		return $this;
	}
	
	public function getBalance() {
		return $this->balance;
	}
	
	public function getHolders() {
		return $this->holders;
	}
	
	public function addHolder(User $holder) {
		$this->holders->set($holder->getId(), $holder);
		return $this;
	}
	
	public function getTransactions() {
		return $this->transactions;
	}
	
	public function addTransaction(AccountTransaction $transaction) {
		$this->transactions->add($transaction);
		return $this;
	}
	
	public function isHeldBy(User $user) {
		return $this->holders->containsKey($user->getId());
	}
}
{'fraction_non_alphanumeric': 0.16725228390723823, 'fraction_numerical': 0.0, 'mean_word_length': 5.288659793814433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '3816128', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1361, 'n_words': 241}