for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Stu\Component\Player\Relation;
use Stu\Orm\Entity\UserInterface;
/**
* Some locations require to determine if a certain user is friendly towards the player
*/
final class PlayerRelationDeterminator implements PlayerRelationDeterminatorInterface
{
public function __construct(
private FriendDeterminator $friendDeterminator,
private EnemyDeterminator $enemyDeterminator
) {
}
public function isFriend(UserInterface $user, UserInterface $otherUser): bool
$friendRelation = $this->friendDeterminator->isFriend($user, $otherUser);
if ($friendRelation->isDominant()) {
return true;
$enemyRelation = $this->enemyDeterminator->isEnemy($user, $otherUser);
if ($enemyRelation->isDominant()) {
return false;
return $friendRelation !== PlayerRelationTypeEnum::NONE;
public function isEnemy(UserInterface $user, UserInterface $otherUser): bool
return $enemyRelation !== PlayerRelationTypeEnum::NONE;