Improve type hints

This commit is contained in:
Alex Cabal 2025-03-27 16:46:05 -05:00
parent f21783d1f8
commit fbcafb8f1d
17 changed files with 45 additions and 45 deletions

View file

@ -3,11 +3,11 @@ use Safe\DateTimeImmutable;
/** /**
* @property ?int $DeathYear * @property ?int $DeathYear
* @property ?string $UrlName * @property string $UrlName
* @property ?string $Url * @property-read string $Url
* @property string $DeleteUrl * @property-read string $DeleteUrl
* @property array<string> $AlternateNames * @property array<string> $AlternateNames
* @property string $AlternateNamesString * @property-read string $AlternateNamesString
*/ */
class Artist{ class Artist{
use Traits\Accessor; use Traits\Accessor;

View file

@ -12,8 +12,8 @@ use function Safe\unlink;
/** /**
* @property string $UrlName * @property string $UrlName
* @property string $Url * @property-read string $Url
* @property string $EditUrl * @property-read string $EditUrl
* @property-read array<ArtworkTag> $Tags * @property-read array<ArtworkTag> $Tags
* @property-write array<ArtworkTag>|string $Tags * @property-write array<ArtworkTag>|string $Tags
* @property Artist $Artist * @property Artist $Artist

View file

@ -1,7 +1,7 @@
<? <?
/** /**
* @property bool $HasBenefits Are any of the benefits in this object **`TRUE`**? * @property-read bool $HasBenefits Are any of the benefits in this object **`TRUE`**?
* @property bool $RequiresPassword Do any of the benefits in this object require the `User` to have a password set? * @property-read bool $RequiresPassword Do any of the benefits in this object require the `User` to have a password set?
*/ */
class Benefits{ class Benefits{
use Traits\Accessor; use Traits\Accessor;

View file

@ -2,7 +2,7 @@
use function Safe\preg_replace; use function Safe\preg_replace;
/** /**
* @property string $Url * @property-read string $Url
* @property array<Ebook> $Ebooks * @property array<Ebook> $Ebooks
*/ */
class Collection{ class Collection{

View file

@ -2,7 +2,7 @@
use function Safe\preg_match; use function Safe\preg_match;
/** /**
* @property ?string $Url The URL of this `Contributor` if their MARC role is `Enums\MarcRole::Author`, or **null** otherwise. * @property-read ?string $Url The URL of this `Contributor` if their MARC role is `Enums\MarcRole::Author`, or `null` otherwise.
*/ */
class Contributor{ class Contributor{
use Traits\Accessor; use Traits\Accessor;

View file

@ -2,10 +2,10 @@
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
/** /**
* @property int $DonationCount * @property-read int $DonationCount
* @property int $StretchDonationCount * @property-read int $StretchDonationCount
* @property bool $IsStretchEnabled * @property-read bool $IsStretchEnabled
* @property int $TargetDonationCount * @property-read int $TargetDonationCount
*/ */
class DonationDrive{ class DonationDrive{
use Traits\Accessor; use Traits\Accessor;

View file

@ -22,9 +22,9 @@ use function Safe\shell_exec;
* @property ?array<string> $TocEntries A list of non-Roman ToC entries *only if* the work has the `se:is-a-collection` metadata element; `null` otherwise. * @property ?array<string> $TocEntries A list of non-Roman ToC entries *only if* the work has the `se:is-a-collection` metadata element; `null` otherwise.
* @property string $Url The relative URL of this ebook, like `/ebooks/...`. * @property string $Url The relative URL of this ebook, like `/ebooks/...`.
* @property string $FullUrl The absolute URL of this ebook, like `https://standardebooks.org/ebooks/...`. * @property string $FullUrl The absolute URL of this ebook, like `https://standardebooks.org/ebooks/...`.
* @property string $EditUrl * @property-read string $EditUrl
* @property string $DeleteUrl * @property-read string $DeleteUrl
* @property bool $HasDownloads * @property-read bool $HasDownloads
* @property string $UrlSafeIdentifier * @property string $UrlSafeIdentifier
* @property string $HeroImageUrl * @property string $HeroImageUrl
* @property string $HeroImageAvifUrl * @property string $HeroImageAvifUrl
@ -45,10 +45,10 @@ use function Safe\shell_exec;
* @property string $TextSinglePageUrl * @property string $TextSinglePageUrl
* @property string $TextSinglePageSizeFormatted * @property string $TextSinglePageSizeFormatted
* @property ?EbookPlaceholder $EbookPlaceholder * @property ?EbookPlaceholder $EbookPlaceholder
* @property array<Project> $Projects * @property-read array<Project> $Projects
* @property array<Project> $PastProjects * @property-read array<Project> $PastProjects
* @property ?Project $ProjectInProgress * @property-read ?Project $ProjectInProgress
* @property ?Artwork $Artwork * @property-read ?Artwork $Artwork
*/ */
final class Ebook{ final class Ebook{
use Traits\Accessor; use Traits\Accessor;

View file

@ -1,8 +1,8 @@
<? <?
/** /**
* @property bool $IsPublicDomain * @property-read bool $IsPublicDomain
* @property string $TimeTillIsPublicDomain A string describing how much longer it will be before this work is in the U.S. public domain, like `3 months` or `20 years`. * @property-read string $TimeTillIsPublicDomain A string describing how much longer it will be before this work is in the U.S. public domain, like `3 months` or `20 years`.
*/ */
class EbookPlaceholder{ class EbookPlaceholder{
use Traits\Accessor; use Traits\Accessor;

View file

@ -3,7 +3,7 @@ use Safe\DateTimeImmutable;
/** /**
* @property User $User * @property User $User
* @property string $Url * @property-read string $Url
*/ */
class NewsletterSubscription{ class NewsletterSubscription{
use Traits\Accessor; use Traits\Accessor;

View file

@ -3,7 +3,7 @@ use Safe\DateTimeImmutable;
/** /**
* @property User $User * @property User $User
* @property ?Payment $LastPayment * @property-read ?Payment $LastPayment
*/ */
class Patron{ class Patron{
use Traits\Accessor; use Traits\Accessor;

View file

@ -2,10 +2,10 @@
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
/** /**
* @property string $Url * @property-read string $Url
* @property array<PollItem> $PollItems * @property array<PollItem> $PollItems
* @property array<PollItem> $PollItemsByWinner * @property array<PollItem> $PollItemsByWinner
* @property int $VoteCount * @property-read int $VoteCount
*/ */
class Poll{ class Poll{
use Traits\Accessor; use Traits\Accessor;

View file

@ -1,6 +1,6 @@
<? <?
/** /**
* @property int $VoteCount * @property-read int $VoteCount
* @property Poll $Poll * @property Poll $Poll
*/ */
class PollItem{ class PollItem{

View file

@ -4,7 +4,7 @@ use Safe\DateTimeImmutable;
/** /**
* @property User $User * @property User $User
* @property PollItem $PollItem * @property PollItem $PollItem
* @property string $Url * @property-read string $Url
*/ */
class PollVote{ class PollVote{
use Traits\Accessor; use Traits\Accessor;

View file

@ -16,12 +16,12 @@ use Safe\DateTimeImmutable;
* @property Ebook $Ebook * @property Ebook $Ebook
* @property User $Manager * @property User $Manager
* @property User $Reviewer * @property User $Reviewer
* @property string $Url * @property-read string $Url
* @property string $EditUrl * @property-read string $EditUrl
* @property DateTimeImmutable $LastActivityTimestamp The timestamp of the latest activity, whether it's a commit, a discussion post, or simply the started timestamp. * @property DateTimeImmutable $LastActivityTimestamp The timestamp of the latest activity, whether it's a commit, a discussion post, or simply the started timestamp.
* @property array<ProjectReminder> $Reminders * @property array<ProjectReminder> $Reminders
* @property ?string $VcsUrlDomain * @property-read ?string $VcsUrlDomain
* @property ?string $DiscussionUrlDomain * @property-read ?string $DiscussionUrlDomain
*/ */
final class Project{ final class Project{
use Traits\Accessor; use Traits\Accessor;

View file

@ -5,7 +5,7 @@ use Ramsey\Uuid\Uuid;
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
/** /**
* @property string $Url * @property-read string $Url
*/ */
class Session{ class Session{
use Traits\Accessor; use Traits\Accessor;

View file

@ -1,6 +1,6 @@
<? <?
/** /**
* @property string $Url * @property-read string $Url
*/ */
class Tag{ class Tag{
use Traits\Accessor; use Traits\Accessor;
@ -10,5 +10,5 @@ class Tag{
public string $UrlName; public string $UrlName;
public Enums\TagType $Type; public Enums\TagType $Type;
protected string $_Url; protected string $_Url; // For subclasses.
} }

View file

@ -6,15 +6,15 @@ use function Safe\preg_match;
/** /**
* @property array<Payment> $Payments * @property array<Payment> $Payments
* @property bool $IsRegistered A user is "registered" if they have an entry in the `Benefits` table; a password is required to log in. * @property-read bool $IsRegistered A user is "registered" if they have an entry in the `Benefits` table; a password is required to log in.
* @property Benefits $Benefits * @property Benefits $Benefits
* @property string $Url * @property-read string $Url
* @property string $EditUrl * @property-read string $EditUrl
* @property ?Patron $Patron * @property ?Patron $Patron
* @property ?NewsletterSubscription $NewsletterSubscription * @property ?NewsletterSubscription $NewsletterSubscription
* @property ?Payment $LastPayment * @property-read ?Payment $LastPayment
* @property string $DisplayName The `User`'s name, or email, or ID. * @property-read string $DisplayName The `User`'s name, or email, or ID.
* @property ?string $SortName The `User`'s name in an (attempted) sort order, or `null` if the `User` has no name. * @property-read ?string $SortName The `User`'s name in an (attempted) sort order, or `null` if the `User` has no name.
*/ */
class User{ class User{
use Traits\Accessor; use Traits\Accessor;
@ -50,7 +50,7 @@ class User{
if($this->Name !== null){ if($this->Name !== null){
preg_match('/\s(?:de |de la |di |van |von )?[^\s]+$/iu', $this->Name, $lastNameMatches); preg_match('/\s(?:de |de la |di |van |von )?[^\s]+$/iu', $this->Name, $lastNameMatches);
if(sizeof($lastNameMatches) == 0){ if(sizeof($lastNameMatches) == 0){
$this->SortName = $this->Name; $this->_SortName = $this->Name;
} }
else{ else{
$lastName = trim($lastNameMatches[0]); $lastName = trim($lastNameMatches[0]);
@ -58,7 +58,7 @@ class User{
preg_match('/^(.+)' . preg_quote($lastName, '/') . '$/u', $this->Name, $firstNameMatches); preg_match('/^(.+)' . preg_quote($lastName, '/') . '$/u', $this->Name, $firstNameMatches);
if(sizeof($firstNameMatches) == 0){ if(sizeof($firstNameMatches) == 0){
$this->SortName = $this->Name; $this->_SortName = $this->Name;
} }
else{ else{
$this->_SortName = $lastName . ', ' . trim($firstNameMatches[1]); $this->_SortName = $lastName . ', ' . trim($firstNameMatches[1]);
@ -289,7 +289,7 @@ class User{
elseif($this->Benefits->HasBenefits){ elseif($this->Benefits->HasBenefits){
$this->Benefits->UserId = $this->UserId; $this->Benefits->UserId = $this->UserId;
$this->Benefits->Create(); $this->Benefits->Create();
$this->IsRegistered = true; $this->_IsRegistered = true;
} }
} }
catch(Exceptions\DuplicateDatabaseKeyException){ catch(Exceptions\DuplicateDatabaseKeyException){