[ENTITY][Actor][DOC] Add explanation in Actor::__call

This commit is contained in:
Hugo Sales 2021-12-23 17:06:11 +00:00 committed by Diogo Peralta Cordeiro
parent be197bc82b
commit 59abffe744
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

View File

@ -28,7 +28,6 @@ use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\Event;
use App\Core\Router\Router;
use App\Core\UserRoles;
use App\Util\Exception\BugFoundException;
use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\NicknameException;
@ -290,21 +289,6 @@ class Actor extends Entity
}
}
public function __call(string $name, array $arguments): mixed
{
if (Formatting::startsWith($name, 'is')) {
$type = Formatting::removePrefix($name, 'is');
$const = self::class . '::' . mb_strtoupper($type);
if (\defined($const)) {
return $this->type === \constant($const);
} else {
throw new BugFoundException("Actor cannot be a '{$type}', check your spelling");
}
} else {
return parent::__call($name, $arguments);
}
}
public function getAvatarUrl(string $size = 'full')
{
return Avatar::getUrl($this->getId(), $size);
@ -423,11 +407,6 @@ class Actor extends Entity
return $this->getSubCount(which: 'subscribed', column: 'subscriber');
}
public function isPerson(): bool
{
return ($this->roles & UserRoles::BOT) === 0;
}
/**
* Resolve an ambiguous nickname reference, checking in following order:
* - Actors that $sender subscribes to
@ -588,6 +567,28 @@ class Actor extends Entity
}
}
/**
* @method bool isPerson()
* @method bool isGroup()
* @method bool isOrganization()
* @method bool isBusiness()
* @method bool isBot()
*/
public function __call(string $name, array $arguments): mixed
{
if (Formatting::startsWith($name, 'is')) {
$type = Formatting::removePrefix($name, 'is');
$const = self::class . '::' . mb_strtoupper($type);
if (\defined($const)) {
return $this->type === \constant($const);
} else {
throw new BugFoundException("Actor cannot be a '{$type}', check your spelling");
}
} else {
return parent::__call($name, $arguments);
}
}
public static function schemaDef(): array
{
return [