Add type hints for remaining classes

This commit is contained in:
Alex Cabal 2024-01-08 14:11:53 -06:00
parent d7718218ad
commit 783c09864f
35 changed files with 212 additions and 210 deletions

View file

@ -128,8 +128,6 @@ Before submitting design contributions, please discuss them with the Standard Eb
### Main website ### Main website
- Add type hints for class variables.
- Convert ebooks from being stored in an APCu cache to our MariaDB database. (This is a big project!) - Convert ebooks from being stored in an APCu cache to our MariaDB database. (This is a big project!)
- Creating a search bar for the SE Manual of Style. - Creating a search bar for the SE Manual of Style.
@ -186,7 +184,7 @@ Before submitting design contributions, please discuss them with the Standard Eb
- Check for `null` using `===` and `!==`. - Check for `null` using `===` and `!==`.
- Where possible, include type hints for functions. Due to PHP limitations this may not always be possible, for example in cases where `null` may be passed or returned. - Where possible, include type hints for class properties and all functions.
- If using regex to parse HTML, use `|` as the regex delimiter instead of `/`. - If using regex to parse HTML, use `|` as the regex delimiter instead of `/`.

View file

@ -1,5 +1,4 @@
<? <?
class ArtworkTag extends Tag{ class ArtworkTag extends Tag{
// ******* // *******
// GETTERS // GETTERS
@ -19,11 +18,11 @@ class ArtworkTag extends Tag{
protected function Validate(): void{ protected function Validate(): void{
$error = new Exceptions\ValidationException(); $error = new Exceptions\ValidationException();
if($this->Name === null || strlen($this->Name) === 0){ if(strlen($this->Name) == 0){
$error->Add(new Exceptions\InvalidArtworkTagException()); $error->Add(new Exceptions\InvalidArtworkTagException());
} }
if($this->Url === null || strlen($this->Url) === 0){ if($this->Url === null || strlen($this->Url) == 0){
$error->Add(new Exceptions\InvalidArtworkTagException()); $error->Add(new Exceptions\InvalidArtworkTagException());
} }

View file

@ -1,16 +1,11 @@
<? <?
use Safe\DateTime; use Safe\DateTime;
use function Safe\file_get_contents; use function Safe\file_get_contents;
use function Safe\file_put_contents;
use function Safe\preg_replace;
use function Safe\rename;
use function Safe\tempnam;
use function Safe\unlink;
class AtomFeed extends Feed{ class AtomFeed extends Feed{
public $Id; public string $Id;
public $Updated = null; public ?DateTime $Updated = null;
public $Subtitle = null; public ?string $Subtitle = null;
/** /**
* @param string $title * @param string $title
@ -26,7 +21,6 @@ class AtomFeed extends Feed{
$this->Stylesheet = SITE_URL . '/feeds/atom/style'; $this->Stylesheet = SITE_URL . '/feeds/atom/style';
} }
// ******* // *******
// METHODS // METHODS
// ******* // *******

View file

@ -1,8 +1,8 @@
<? <?
class Benefits{ class Benefits{
public $CanAccessFeeds = false; public bool $CanAccessFeeds = false;
public $CanVote = false; public bool $CanVote = false;
public $CanBulkDownload = false; public bool $CanBulkDownload = false;
public $CanUploadArtwork = false; public bool $CanUploadArtwork = false;
public $CanReviewArtwork = false; public bool $CanReviewArtwork = false;
} }

View file

@ -1,12 +1,11 @@
<? <?
use function Safe\preg_replace; use function Safe\preg_replace;
class Collection{ class Collection{
public $Name; public string $Name;
public $Url; public string $Url;
public $SequenceNumber = null; public ?int $SequenceNumber = null;
public $Type = null; public ?string $Type = null;
public function __construct(string $name){ public function __construct(string $name){
$this->Name = $name; $this->Name = $name;

View file

@ -1,12 +1,12 @@
<? <?
class Contributor{ class Contributor{
public $Name; public string $Name;
public $UrlName; public string $UrlName;
public $SortName; public ?string $SortName;
public $WikipediaUrl; public ?string $WikipediaUrl;
public $MarcRole; public ?string $MarcRole;
public $FullName; public ?string $FullName;
public $NacoafUrl; public ?string $NacoafUrl;
public function __construct(string $name, string $sortName = null, string $fullName = null, string $wikipediaUrl = null, string $marcRole = null, string $nacoafUrl = null){ public function __construct(string $name, string $sortName = null, string $fullName = null, string $wikipediaUrl = null, string $marcRole = null, string $nacoafUrl = null){
$this->Name = str_replace('\'', '', $name); $this->Name = str_replace('\'', '', $name);

View file

@ -1,5 +1,4 @@
<? <?
class Db{ class Db{
public static function GetLastInsertedId(): int{ public static function GetLastInsertedId(): int{
return $GLOBALS['DbConnection']->GetLastInsertedId(); return $GLOBALS['DbConnection']->GetLastInsertedId();

View file

@ -4,10 +4,9 @@ use function Safe\preg_match;
use function Safe\posix_getpwuid; use function Safe\posix_getpwuid;
class DbConnection{ class DbConnection{
private $_link = null; private ?\PDO $_link = null;
public $IsConnected = false; public int $QueryCount = 0;
public $QueryCount = 0; public int $LastQueryAffectedRowCount = 0;
public $LastQueryAffectedRowCount = 0;
public function __construct(?string $defaultDatabase = null, string $host = 'localhost', ?string $user = null, string$password = '', bool $forceUtf8 = true, bool $require = true){ public function __construct(?string $defaultDatabase = null, string $host = 'localhost', ?string $user = null, string$password = '', bool $forceUtf8 = true, bool $require = true){
if($user === null){ if($user === null){
@ -51,8 +50,6 @@ class DbConnection{
// We can't use persistent connections (connection pooling) because we would have race condition problems with last_insert_id() // We can't use persistent connections (connection pooling) because we would have race condition problems with last_insert_id()
$this->_link = new \PDO($connectionString, $user, $password, $params); $this->_link = new \PDO($connectionString, $user, $password, $params);
$this->IsConnected = true;
} }
catch(Exception $ex){ catch(Exception $ex){
if(SITE_STATUS == SITE_STATUS_DEV){ if(SITE_STATUS == SITE_STATUS_DEV){
@ -79,7 +76,7 @@ class DbConnection{
* @return Array<mixed> * @return Array<mixed>
*/ */
public function Query(string $sql, array $params = [], string $class = 'stdClass'): array{ public function Query(string $sql, array $params = [], string $class = 'stdClass'): array{
if(!$this->IsConnected){ if($this->_link === null){
return []; return [];
} }
@ -245,8 +242,19 @@ class DbConnection{
// Gets the last auto-increment id // Gets the last auto-increment id
public function GetLastInsertedId(): ?int{ public function GetLastInsertedId(): ?int{
if($this->_link === null){
return null;
}
$id = $this->_link->lastInsertId(); $id = $this->_link->lastInsertId();
if($id === false){
return null;
}
else{
$id = (int)$id;
}
if($id == 0){ if($id == 0){
return null; return null;
} }

View file

@ -10,58 +10,70 @@ use function Safe\sprintf;
use function Safe\shell_exec; use function Safe\shell_exec;
use function Safe\substr; use function Safe\substr;
/**
* @property array<GitCommit> $GitCommits
* @property array<EbookTag> $EbookTags
* @property array<string> $LocTags
* @property array<Collection> $Collections
* @property array<EbookSource> $Sources
* @property array<Contributor> $Authors
* @property array<Contributor> $Illustrators
* @property array<Contributor> $Translators
* @property array<Contributor> $Contributors
* @property ?array<string> $TocEntries
*/
class Ebook{ class Ebook{
public $WwwFilesystemPath; public string $WwwFilesystemPath;
public $RepoFilesystemPath; public string $RepoFilesystemPath;
public $Url; public string $Url;
public $KindleCoverUrl; public string $KindleCoverUrl;
public $EpubUrl; public string $EpubUrl;
public $AdvancedEpubUrl; public string $AdvancedEpubUrl;
public $KepubUrl; public string $KepubUrl;
public $Azw3Url; public string $Azw3Url;
public $HasDownloads; public bool $HasDownloads;
public $GitCommits = []; public $GitCommits = [];
public $Tags = []; public $Tags = [];
public $LocTags = []; public $LocTags = [];
public $Collections = []; public $Collections = [];
public $Identifier; public string $Identifier;
public $UrlSafeIdentifier; public string $UrlSafeIdentifier;
public $HeroImageUrl; public string $HeroImageUrl;
public $HeroImageAvifUrl; public string $HeroImageAvifUrl;
public $HeroImage2xUrl; public string $HeroImage2xUrl;
public $HeroImage2xAvifUrl; public string $HeroImage2xAvifUrl;
public $CoverImageUrl; public string $CoverImageUrl;
public $CoverImageAvifUrl; public string $CoverImageAvifUrl;
public $CoverImage2xUrl; public string $CoverImage2xUrl;
public $CoverImage2xAvifUrl; public string $CoverImage2xAvifUrl;
public $DistCoverUrl; public string $DistCoverUrl;
public $Title; public ?string $Title = null;
public $FullTitle; public ?string $FullTitle = null;
public $AlternateTitle; public ?string $AlternateTitle = null;
public $Description; public ?string $Description = null;
public $LongDescription; public ?string $LongDescription = null;
public $Language; public ?string $Language = null;
public $WordCount; public int $WordCount;
public $ReadingEase; public float $ReadingEase;
public $ReadingEaseDescription; public string $ReadingEaseDescription;
public $ReadingTime; public string $ReadingTime;
public $GitHubUrl; public ?string $GitHubUrl = null;
public $WikipediaUrl; public ?string $WikipediaUrl = null;
public $Sources = []; public $Sources = [];
public $Authors = []; // Array of Contributors public $Authors = [];
public $AuthorsHtml; public string $AuthorsHtml;
public $AuthorsUrl; // This is a single URL even if there are multiple authors; for example, /ebooks/karl-marx_friedrich-engels/ public string $AuthorsUrl; // This is a single URL even if there are multiple authors; for example, /ebooks/karl-marx_friedrich-engels/
public $Illustrators = []; // Array of Contributors public $Illustrators = [];
public $Translators = []; // Array of Contributors public $Translators = [];
public $Contributors = []; // Array of Contributors public $Contributors = [];
public $ContributorsHtml; public ?string $ContributorsHtml = null;
public $TitleWithCreditsHtml = ''; public string $TitleWithCreditsHtml = '';
public $Created; public DateTime $Created;
public $Updated; public DateTime $Updated;
public $TextUrl; public string $TextUrl;
public $TextSinglePageUrl; public string $TextSinglePageUrl;
public $TextSinglePageSizeNumber = null; public ?string $TextSinglePageSizeNumber = null;
public $TextSinglePageSizeUnit = null; public ?string $TextSinglePageSizeUnit = null;
public $TocEntries = null; // A list of non-Roman ToC entries ONLY IF the work has the 'se:is-a-collection' metadata element, null otherwise public $TocEntries = null; // A list of non-Roman ToC entries ONLY IF the work has the 'se:is-a-collection' metadata element, null otherwise
public function __construct(?string $wwwFilesystemPath = null){ public function __construct(?string $wwwFilesystemPath = null){
@ -384,7 +396,7 @@ class Ebook{
// Figure out the reading time. // Figure out the reading time.
$readingTime = ceil($this->WordCount / AVERAGE_READING_WORDS_PER_MINUTE); $readingTime = ceil($this->WordCount / AVERAGE_READING_WORDS_PER_MINUTE);
$this->ReadingTime = $readingTime; $this->ReadingTime = (string)$readingTime;
if($readingTime < 60){ if($readingTime < 60){
$this->ReadingTime .= ' minute'; $this->ReadingTime .= ' minute';

View file

@ -1,7 +1,7 @@
<? <?
class EbookSource{ class EbookSource{
public $Type; public int $Type;
public $Url; public string $Url;
public function __construct(int $type, string $url){ public function __construct(int $type, string $url){
$this->Type = $type; $this->Type = $type;

View file

@ -6,7 +6,6 @@ class EbookTag extends Tag{
$this->_Url = '/subjects/' . $this->UrlName; $this->_Url = '/subjects/' . $this->UrlName;
} }
// ******* // *******
// GETTERS // GETTERS
// ******* // *******

View file

@ -2,20 +2,20 @@
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\Exception;
use function Safe\define; /**
use function Safe\file_get_contents; * @property array<array<string>> $Attachments
*/
class Email{ class Email{
public $To = ''; public string $To = '';
public $ToName = ''; public string $ToName = '';
public $From = ''; public string $From = '';
public $FromName = ''; public string $FromName = '';
public $ReplyTo = ''; public string $ReplyTo = '';
public $Subject = ''; public string $Subject = '';
public $Body = ''; public string $Body = '';
public $TextBody = ''; public string $TextBody = '';
public $Attachments = []; public $Attachments = [];
public $PostmarkStream = null; public ?string $PostmarkStream = null;
public function __construct(bool $isNoReplyEmail = false){ public function __construct(bool $isNoReplyEmail = false){
if($isNoReplyEmail){ if($isNoReplyEmail){
@ -35,7 +35,7 @@ class Email{
$this->ReplyTo = $this->From; $this->ReplyTo = $this->From;
} }
if($this->To === null || $this->To == ''){ if($this->To == ''){
return false; return false;
} }

View file

@ -1,18 +1,20 @@
<? <?
use Safe\DateTime;
use function Safe\exec; use function Safe\exec;
use function Safe\file_get_contents; use function Safe\file_get_contents;
use function Safe\file_put_contents; use function Safe\file_put_contents;
use function Safe\tempnam; use function Safe\tempnam;
use function Safe\unlink; use function Safe\unlink;
/**
* @param array<string> $Entries
*/
class Feed{ class Feed{
public $Url; public string $Url;
public $Title; public string $Title;
public $Entries = []; public $Entries = [];
public $Path = null; public string $Path;
public $Stylesheet = null; public ?string $Stylesheet = null;
protected $XmlString = null; protected ?string $XmlString = null;
/** /**
* @param string $title * @param string $title

View file

@ -2,9 +2,9 @@
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
class GitCommit{ class GitCommit{
public $Created; public DateTimeImmutable $Created;
public $Message; public string $Message;
public $Hash; public string $Hash;
public function __construct(string $unixTimestamp, string $hash, string $message){ public function __construct(string $unixTimestamp, string $hash, string $message){
$this->Created = new DateTimeImmutable('@' . $unixTimestamp); $this->Created = new DateTimeImmutable('@' . $unixTimestamp);

View file

@ -7,8 +7,8 @@ use function Safe\getimagesize;
use function Safe\unlink; use function Safe\unlink;
class Image{ class Image{
public $Path; public string $Path;
public $MimeType; public ?ImageMimeType $MimeType;
public function __construct(string $path){ public function __construct(string $path){
$this->Path = $path; $this->Path = $path;

View file

@ -7,14 +7,11 @@ use function Safe\filesize;
use function Safe\glob; use function Safe\glob;
use function Safe\gmdate; use function Safe\gmdate;
use function Safe\ksort; use function Safe\ksort;
use function Safe\preg_match;
use function Safe\preg_replace; use function Safe\preg_replace;
use function Safe\shell_exec; use function Safe\shell_exec;
use function Safe\sleep; use function Safe\sleep;
use function Safe\sort;
use function Safe\usort; use function Safe\usort;
class Library{ class Library{
/** /**
* @param string $query * @param string $query

View file

@ -7,8 +7,8 @@ use function Safe\gmdate;
use function Safe\substr; use function Safe\substr;
class Log{ class Log{
private $RequestId = null; private string $RequestId;
private $LogFilePath = null; private ?string $LogFilePath = null;
public function __construct(?string $logFilePath){ public function __construct(?string $logFilePath){
// Get a semi-random ID to identify this request within the log. // Get a semi-random ID to identify this request within the log.

View file

@ -1,9 +1,8 @@
<? <?
class Museum extends PropertiesBase{ class Museum extends PropertiesBase{
public $MuseumId; public int $MuseumId;
public $Name; public string $Name;
public $Domain; public string $Domain;
public static function GetByUrl(?string $url): Museum{ public static function GetByUrl(?string $url): Museum{
if($url === null){ if($url === null){

View file

@ -6,12 +6,12 @@ use Safe\DateTime;
* @property string $Url * @property string $Url
*/ */
class NewsletterSubscription extends PropertiesBase{ class NewsletterSubscription extends PropertiesBase{
public $IsConfirmed = false; public bool $IsConfirmed = false;
public $IsSubscribedToSummary; public bool $IsSubscribedToSummary;
public $IsSubscribedToNewsletter; public bool $IsSubscribedToNewsletter;
public $UserId; public int $UserId;
public DateTime $Created;
protected $_User; protected $_User;
public $Created;
protected $_Url = null; protected $_Url = null;
// ******* // *******
@ -85,8 +85,8 @@ class NewsletterSubscription extends PropertiesBase{
public function SendConfirmationEmail(): void{ public function SendConfirmationEmail(): void{
$em = new Email(true); $em = new Email(true);
$em->PostmarkStream = EMAIL_POSTMARK_STREAM_BROADCAST; $em->PostmarkStream = EMAIL_POSTMARK_STREAM_BROADCAST;
$em->To = $this->User->Email; $em->To = $this->User->Email ?? '';
if($this->User->Name != ''){ if($this->User->Name !== null && $this->User->Name != ''){
$em->ToName = $this->User->Name; $em->ToName = $this->User->Name;
} }
$em->Subject = 'Action required: confirm your newsletter subscription'; $em->Subject = 'Action required: confirm your newsletter subscription';

View file

@ -2,7 +2,7 @@
use Safe\DateTime; use Safe\DateTime;
class OpdsAcquisitionFeed extends OpdsFeed{ class OpdsAcquisitionFeed extends OpdsFeed{
public $IsCrawlable; public bool $IsCrawlable;
public function __construct(string $title, string $subtitle, string $url, string $path, array $entries, ?OpdsNavigationFeed $parent, bool $isCrawlable = false){ public function __construct(string $title, string $subtitle, string $url, string $path, array $entries, ?OpdsNavigationFeed $parent, bool $isCrawlable = false){
parent::__construct($title, $subtitle, $url, $path, $entries, $parent); parent::__construct($title, $subtitle, $url, $path, $entries, $parent);

View file

@ -3,7 +3,7 @@ use Safe\DateTime;
use function Safe\file_put_contents; use function Safe\file_put_contents;
class OpdsFeed extends AtomFeed{ class OpdsFeed extends AtomFeed{
public $Parent = null; // OpdsNavigationFeed class public ?OpdsNavigationFeed $Parent = null;
/** /**
* @param string $title * @param string $title

View file

@ -1,13 +1,13 @@
<? <?
class OpdsNavigationEntry{ class OpdsNavigationEntry{
public $Id; public string $Id;
public $Url; public string $Url;
public $Rel; public string $Rel;
public $Type; public string $Type;
public $Updated; public ?DateTime $Updated;
public $Description; public string $Description;
public $Title; public string $Title;
public $SortTitle; public string $SortTitle;
public function __construct(string $title, string $description, string $url, ?DateTime $updated, string $rel, string $type){ public function __construct(string $title, string $description, string $url, ?DateTime $updated, string $rel, string $type){
$this->Id = SITE_URL . $url; $this->Id = SITE_URL . $url;

View file

@ -1,6 +1,5 @@
<? <?
use Safe\DateTime; use Safe\DateTime;
use function Safe\file_get_contents; use function Safe\file_get_contents;
class OpdsNavigationFeed extends OpdsFeed{ class OpdsNavigationFeed extends OpdsFeed{

View file

@ -5,13 +5,13 @@ use Safe\DateTime;
* @property User $User * @property User $User
*/ */
class Patron extends PropertiesBase{ class Patron extends PropertiesBase{
public $UserId = null; public ?int $UserId = null;
protected $_User = null; protected $_User = null;
public $IsAnonymous; public bool $IsAnonymous;
public $AlternateName; public ?string $AlternateName;
public $IsSubscribedToEmails; public bool $IsSubscribedToEmails;
public $Created = null; public ?DateTime $Created = null;
public $Ended = null; public ?DateTime $Ended = null;
// ******* // *******
@ -54,8 +54,8 @@ class Patron extends PropertiesBase{
private function SendWelcomeEmail(bool $isReturning): void{ private function SendWelcomeEmail(bool $isReturning): void{
if($this->User !== null){ if($this->User !== null){
$em = new Email(); $em = new Email();
$em->To = $this->User->Email; $em->To = $this->User->Email ?? '';
$em->ToName = $this->User->Name; $em->ToName = $this->User->Name ?? '';
$em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS; $em->From = EDITOR_IN_CHIEF_EMAIL_ADDRESS;
$em->FromName = EDITOR_IN_CHIEF_NAME; $em->FromName = EDITOR_IN_CHIEF_NAME;
$em->Subject = 'Thank you for supporting Standard Ebooks!'; $em->Subject = 'Thank you for supporting Standard Ebooks!';

View file

@ -1,19 +1,18 @@
<? <?
/** /**
* @property User $User * @property User $User
*/ */
class Payment extends PropertiesBase{ class Payment extends PropertiesBase{
public $PaymentId; public int $PaymentId;
public $UserId = null; public ?int $UserId = null;
protected $_User = null; public DateTime $Created;
public $Created; public int $ChannelId;
public $ChannelId; public string $TransactionId;
public $TransactionId; public float $Amount;
public $Amount; public float $Fee;
public $Fee; public bool $IsRecurring;
public $IsRecurring; public bool $IsMatchingDonation = false;
public $IsMatchingDonation = false; protected ?User $_User = null;
// ******* // *******

View file

@ -3,23 +3,25 @@ use Safe\DateTime;
use function Safe\usort; use function Safe\usort;
/** /**
* @property ?array<PollItem> $_PollItems
* @property ?array<PollItem> $_PollItemsByWinner
* @property string $Url * @property string $Url
* @property array<PollItem> $PollItems * @property array<PollItem> $PollItems
* @property array<PollItem> $PollItemsByWinner * @property array<PollItem> $PollItemsByWinner
* @property int $VoteCount * @property int $VoteCount
*/ */
class Poll extends PropertiesBase{ class Poll extends PropertiesBase{
public $PollId; public int $PollId;
public $Name; public string $Name;
public $UrlName; public string $UrlName;
public $Description; public string $Description;
public $Created; public DateTime $Created;
public $Start; public DateTime $Start;
public $End; public DateTime $End;
protected $_Url = null; protected ?string $_Url = null;
protected $_PollItems = null; protected $_PollItems = null;
protected $_PollItemsByWinner = null; protected $_PollItemsByWinner = null;
protected $_VoteCount = null; protected ?int $_VoteCount = null;
// ******* // *******
@ -71,7 +73,7 @@ class Poll extends PropertiesBase{
$this->_PollItemsByWinner = $this->PollItems; $this->_PollItemsByWinner = $this->PollItems;
usort($this->_PollItemsByWinner, function(PollItem $a, PollItem $b){ return $a->VoteCount <=> $b->VoteCount; }); usort($this->_PollItemsByWinner, function(PollItem $a, PollItem $b){ return $a->VoteCount <=> $b->VoteCount; });
$this->_PollItemsByWinner = array_reverse($this->_PollItemsByWinner); $this->_PollItemsByWinner = array_reverse($this->_PollItemsByWinner ?? []);
} }
return $this->_PollItemsByWinner; return $this->_PollItemsByWinner;

View file

@ -1,16 +1,15 @@
<? <?
/** /**
* @property int $VoteCount * @property int $VoteCount
* @property Poll $Poll * @property Poll $Poll
*/ */
class PollItem extends PropertiesBase{ class PollItem extends PropertiesBase{
public $PollItemId; public int $PollItemId;
public $PollId; public int $PollId;
public $Name; public string $Name;
public $Description; public string $Description;
protected $_VoteCount = null; protected ?int $_VoteCount = null;
protected $_Poll = null; protected ?Poll $_Poll = null;
// ******* // *******

View file

@ -7,12 +7,12 @@ use Safe\DateTime;
* @property string $Url * @property string $Url
*/ */
class PollVote extends PropertiesBase{ class PollVote extends PropertiesBase{
public $UserId; public int $UserId;
protected $_User = null; public DateTime $Created;
public $Created; public ?int $PollItemId = null;
public $PollItemId; protected ?User $_User = null;
protected $_PollItem = null; protected ?PollItem $_PollItem = null;
protected $_Url = null; protected ?string $_Url = null;
// ******* // *******
@ -35,7 +35,7 @@ class PollVote extends PropertiesBase{
protected function Validate(): void{ protected function Validate(): void{
$error = new Exceptions\ValidationException(); $error = new Exceptions\ValidationException();
if($this->UserId === null || $this->User === null){ if($this->User === null){
$error->Add(new Exceptions\InvalidUserException()); $error->Add(new Exceptions\InvalidUserException());
} }

View file

@ -1,6 +1,4 @@
<? <?
use function Safe\substr;
abstract class PropertiesBase{ abstract class PropertiesBase{
/** /**
* @return mixed * @return mixed

View file

@ -5,7 +5,7 @@ use function Safe\filesize;
use function Safe\preg_replace; use function Safe\preg_replace;
class RssFeed extends Feed{ class RssFeed extends Feed{
public $Description; public string $Description;
/** /**
* @param string $title * @param string $title

View file

@ -8,11 +8,11 @@ use function Safe\strtotime;
* @property string $Url * @property string $Url
*/ */
class Session extends PropertiesBase{ class Session extends PropertiesBase{
public $UserId; public int $UserId;
protected $_User = null; protected ?User $_User = null;
public $Created; public DateTime $Created;
public $SessionId; public string $SessionId;
public $_Url; public ?string $_Url = null;
// ******* // *******

View file

@ -1,11 +1,10 @@
<? <?
/** /**
* @property string $Url * @property string $Url
*/ */
class Tag extends PropertiesBase{ class Tag extends PropertiesBase{
public $TagId; public int $TagId;
public $Name; public string $Name;
public $UrlName; public string $UrlName;
protected $_Url; protected ?string $_Url;
} }

View file

@ -4,19 +4,20 @@ use Safe\DateTime;
/** /**
* @property Array<Payment> $Payments * @property Array<Payment> $Payments
* @property ?bool $IsRegistered
* @property Benefits $Benefits * @property Benefits $Benefits
* @property ?array<Payment> $_Payments
*/ */
class User extends PropertiesBase{ class User extends PropertiesBase{
public $UserId; public int $UserId;
public $Name; public ?string $Name;
public $Email; public ?string $Email;
public $Created; public DateTime $Created;
public $Uuid; public string $Uuid;
public $PasswordHash; public ?string $PasswordHash;
protected $_IsRegistered = null; protected ?bool $_IsRegistered = null;
protected $_Payments = null; protected $_Payments = null;
protected $_Benefits = null; protected ?Benefits $_Benefits = null;
// ******* // *******
// GETTERS // GETTERS
@ -59,7 +60,7 @@ class User extends PropertiesBase{
return $this->_Benefits; return $this->_Benefits;
} }
protected function GetIsRegistered(): bool{ protected function GetIsRegistered(): ?bool{
if($this->_IsRegistered === null){ if($this->_IsRegistered === null){
// A user is "registered" if they have a benefits entry in the table. // A user is "registered" if they have a benefits entry in the table.
// This function will fill it out for us. // This function will fill it out for us.

View file

@ -35,8 +35,8 @@ if(HttpInput::Str(POST, 'automationtest', false)){
try{ try{
$subscription->User = new User(); $subscription->User = new User();
$subscription->User->Email = HttpInput::Str(POST, 'email', false); $subscription->User->Email = HttpInput::Str(POST, 'email', false);
$subscription->IsSubscribedToNewsletter = HttpInput::Bool(POST, 'issubscribedtonewsletter', false); $subscription->IsSubscribedToNewsletter = HttpInput::Bool(POST, 'issubscribedtonewsletter') ?? false;
$subscription->IsSubscribedToSummary = HttpInput::Bool(POST, 'issubscribedtosummary', false); $subscription->IsSubscribedToSummary = HttpInput::Bool(POST, 'issubscribedtosummary') ?? false;
$captcha = HttpInput::Str(SESSION, 'captcha', false) ?? ''; $captcha = HttpInput::Str(SESSION, 'captcha', false) ?? '';

View file

@ -1,5 +1,4 @@
<? <?
use function Safe\preg_match;
use function Safe\session_unset; use function Safe\session_unset;
if(HttpInput::RequestMethod() != HTTP_POST){ if(HttpInput::RequestMethod() != HTTP_POST){