diff --git a/lib/Artist.php b/lib/Artist.php
index dfef6164..735f4988 100644
--- a/lib/Artist.php
+++ b/lib/Artist.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\date;
/**
@@ -12,8 +12,8 @@ use function Safe\date;
class Artist extends Accessor{
public ?int $ArtistId = null;
public ?string $Name = null;
- public ?datetime $Created = null;
- public ?datetime $Updated = null;
+ public ?DateTimeImmutable $Created = null;
+ public ?DateTimeImmutable $Updated = null;
protected ?int $_DeathYear = null;
protected ?string $_UrlName = null;
protected ?string $_Url = null;
@@ -82,7 +82,7 @@ class Artist extends Accessor{
// *******
public function Validate(): void{
- $now = new DateTime('now', new DateTimeZone('UTC'));
+ $now = new DateTimeImmutable();
$thisYear = intval($now->format('Y'));
$error = new Exceptions\ValidationException();
diff --git a/lib/Artwork.php b/lib/Artwork.php
index e3cdc4e8..dd9f6853 100644
--- a/lib/Artwork.php
+++ b/lib/Artwork.php
@@ -1,7 +1,7 @@
use Exceptions\InvalidUrlException;
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\apcu_cache_info;
use function Safe\copy;
@@ -40,8 +40,8 @@ class Artwork extends Accessor{
public ?int $ArtistId = null;
public ?int $CompletedYear = null;
public bool $CompletedYearIsCirca = false;
- public ?DateTime $Created = null;
- public ?DateTime $Updated = null;
+ public ?DateTimeImmutable $Created = null;
+ public ?DateTimeImmutable $Updated = null;
public ?string $EbookUrl = null;
public ?int $SubmitterUserId = null;
public ?int $ReviewerUserId = null;
@@ -356,7 +356,7 @@ class Artwork extends Accessor{
}
}
- $now = new DateTime('now', new DateTimeZone('UTC'));
+ $now = new DateTimeImmutable();
$thisYear = intval($now->format('Y'));
$error = new Exceptions\ValidationException();
@@ -680,7 +680,7 @@ class Artwork extends Accessor{
$this->Validate($imagePath, true);
- $this->Created = new DateTime();
+ $this->Created = new DateTimeImmutable();
$tags = [];
foreach($this->Tags as $artworkTag){
@@ -745,7 +745,7 @@ class Artwork extends Accessor{
// Manually set the updated timestamp, because if we only update the image and nothing else, the row's
// updated timestamp won't change automatically.
- $this->Updated = new DateTime('now', new DateTimeZone('UTC'));
+ $this->Updated = new DateTimeImmutable();
$this->_ImageUrl = null;
$this->_ThumbUrl = null;
$this->_Thumb2xUrl = null;
diff --git a/lib/AtomFeed.php b/lib/AtomFeed.php
index 28d2845f..d6b73fcb 100644
--- a/lib/AtomFeed.php
+++ b/lib/AtomFeed.php
@@ -1,10 +1,10 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
class AtomFeed extends Feed{
public string $Id;
- public ?DateTime $Updated = null;
+ public ?DateTimeImmutable $Updated = null;
public ?string $Subtitle = null;
/**
@@ -39,7 +39,7 @@ class AtomFeed extends Feed{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file
- $this->Updated = new DateTime();
+ $this->Updated = new DateTimeImmutable();
$this->Save();
return true;
}
diff --git a/lib/Constants.php b/lib/Constants.php
index a1d22428..c2575377 100644
--- a/lib/Constants.php
+++ b/lib/Constants.php
@@ -1,10 +1,10 @@
// Auto-included by Composer in composer.json to satisfy PHPStan
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\define;
-$now = new DateTime('now', new DateTimeZone('UTC'));
-$nowPd = new DateTime('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
+$now = new DateTimeImmutable();
+$nowPd = new DateTimeImmutable('now', new DateTimeZone('America/Juneau')); // Latest continental US time zone
const SITE_STATUS_LIVE = 'live';
const SITE_STATUS_DEV = 'dev';
@@ -94,7 +94,7 @@ const ARTWORK_UPLOADS_LOG_FILE_PATH = '/var/log/local/artwork-uploads.log'; // M
define('PD_YEAR', intval($nowPd->format('Y')) - 96);
define('PD_STRING', 'January 1, ' . (PD_YEAR + 1));
-define('DONATION_HOLIDAY_ALERT_ON', $now > new DateTime('November 15, ' . $now->format('Y'), new DateTimeZone('UTC')) || $now < new DateTime('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y'), new DateTimeZone('UTC')));
+define('DONATION_HOLIDAY_ALERT_ON', $now > new DateTimeImmutable('November 15, ' . $now->format('Y')) || $now < new DateTimeImmutable('January 7, ' . $now->add(new DateInterval('P1Y'))->format('Y')));
define('DONATION_ALERT_ON', DONATION_HOLIDAY_ALERT_ON || rand(1, 4) == 2);
// Controls the progress bar donation dialog
diff --git a/lib/DbConnection.php b/lib/DbConnection.php
index 1c4fd68e..9e12b7c7 100644
--- a/lib/DbConnection.php
+++ b/lib/DbConnection.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\preg_match;
use function Safe\posix_getpwuid;
@@ -199,7 +199,7 @@ class DbConnection{
switch($metadata[$i]['native_type'] ?? null){
case 'DATETIME':
case 'TIMESTAMP':
- $object->{$metadata[$i]['name']} = new DateTime($row[$i], new DateTimeZone('UTC'));
+ $object->{$metadata[$i]['name']} = new DateTimeImmutable($row[$i], new DateTimeZone('UTC'));
break;
case 'LONG':
diff --git a/lib/Ebook.php b/lib/Ebook.php
index bc8cf929..6b185d11 100644
--- a/lib/Ebook.php
+++ b/lib/Ebook.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\filesize;
use function Safe\json_encode;
@@ -67,8 +67,8 @@ class Ebook{
public $Contributors = [];
public ?string $ContributorsHtml = null;
public string $TitleWithCreditsHtml = '';
- public DateTime $Created;
- public DateTime $Updated;
+ public DateTimeImmutable $Created;
+ public DateTimeImmutable $Updated;
public string $TextUrl;
public string $TextSinglePageUrl;
public ?string $TextSinglePageSizeNumber = null;
@@ -222,12 +222,12 @@ class Ebook{
$date = $xml->xpath('/package/metadata/dc:date') ?: [];
if($date !== false && sizeof($date) > 0){
- $this->Created = new DateTime((string)$date[0]);
+ $this->Created = new DateTimeImmutable((string)$date[0]);
}
$modifiedDate = $xml->xpath('/package/metadata/meta[@property="dcterms:modified"]') ?: [];
if($modifiedDate !== false && sizeof($modifiedDate) > 0){
- $this->Updated = new DateTime((string)$modifiedDate[0]);
+ $this->Updated = new DateTimeImmutable((string)$modifiedDate[0]);
}
// Get SE tags
diff --git a/lib/Exceptions/ValidationException.php b/lib/Exceptions/ValidationException.php
index 8762c51d..16ffdba1 100644
--- a/lib/Exceptions/ValidationException.php
+++ b/lib/Exceptions/ValidationException.php
@@ -22,7 +22,7 @@ class ValidationException extends AppException{
public function Add(\Exception $exception, bool $isFatal = false): void{
if(is_a($exception, static::class)){
// Type hint for linter
- /** @var ValidationException $exception */
+ /** @var ValidationException $childException */
foreach($exception->Exceptions as $childException){
$this->Add($childException);
}
diff --git a/lib/Library.php b/lib/Library.php
index cc9117a4..2b9f9cd7 100644
--- a/lib/Library.php
+++ b/lib/Library.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\apcu_fetch;
use function Safe\exec;
use function Safe\filemtime;
@@ -432,7 +432,7 @@ class Library{
private static function FillBulkDownloadObject(string $dir, string $downloadType, string $urlRoot): stdClass{
$obj = new stdClass();
- $now = new DateTime('now', new DateTimeZone('UTC'));
+ $now = new DateTimeImmutable();
// The count of ebooks in each file is stored as a filesystem attribute
$obj->EbookCount = exec('attr -g se-ebook-count ' . escapeshellarg($dir)) ?: null;
@@ -479,7 +479,7 @@ class Library{
$obj->ZipFiles[] = $zipFile;
}
- $obj->Updated = new DateTime('@' . filemtime($files[0]));
+ $obj->Updated = new DateTimeImmutable('@' . filemtime($files[0]));
$obj->UpdatedString = $obj->Updated->format('M j');
// Add a period to the abbreviated month, but not if it's May (the only 3-letter month)
$obj->UpdatedString = preg_replace('/^(.+?)(?UpdatedString);
@@ -546,7 +546,7 @@ class Library{
foreach($dirs as $dir){
$obj = self::FillBulkDownloadObject($dir, 'months', '/months');
- $date = new DateTime($obj->Label . '-01');
+ $date = new DateTimeImmutable($obj->Label . '-01');
$year = $date->format('Y');
$month = $date->format('F');
diff --git a/lib/Log.php b/lib/Log.php
index 6aa11194..ad55a2c9 100644
--- a/lib/Log.php
+++ b/lib/Log.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\fopen;
use function Safe\fwrite;
use function Safe\fclose;
@@ -33,7 +33,7 @@ class Log{
return;
}
- $now = new DateTime('now', new DateTimeZone('UTC'));
+ $now = new DateTimeImmutable();
fwrite($fp, $now->format('Y-m-d H:i:s') . "\t" . $this->RequestId . "\t" . $text . "\n");
fclose($fp);
diff --git a/lib/NewsletterSubscription.php b/lib/NewsletterSubscription.php
index 277bd3fe..4679273e 100644
--- a/lib/NewsletterSubscription.php
+++ b/lib/NewsletterSubscription.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
/**
* @property User $User
@@ -10,7 +10,7 @@ class NewsletterSubscription extends Accessor{
public bool $IsSubscribedToSummary = false;
public bool $IsSubscribedToNewsletter = false;
public ?int $UserId = null;
- public DateTime $Created;
+ public DateTimeImmutable $Created;
protected $_User;
protected $_Url = null;
@@ -44,7 +44,7 @@ class NewsletterSubscription extends Accessor{
}
$this->UserId = $this->User->UserId;
- $this->Created = new DateTime();
+ $this->Created = new DateTimeImmutable();
try{
Db::Query('
diff --git a/lib/OpdsAcquisitionFeed.php b/lib/OpdsAcquisitionFeed.php
index 9089c3ed..ac4c79fa 100644
--- a/lib/OpdsAcquisitionFeed.php
+++ b/lib/OpdsAcquisitionFeed.php
@@ -1,6 +1,4 @@
-use Safe\DateTime;
-
class OpdsAcquisitionFeed extends OpdsFeed{
public bool $IsCrawlable;
diff --git a/lib/OpdsFeed.php b/lib/OpdsFeed.php
index ffa9012d..f4d5ba8c 100644
--- a/lib/OpdsFeed.php
+++ b/lib/OpdsFeed.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\file_put_contents;
class OpdsFeed extends AtomFeed{
@@ -24,7 +24,7 @@ class OpdsFeed extends AtomFeed{
// METHODS
// *******
- protected function SaveUpdated(string $entryId, DateTime $updated): void{
+ protected function SaveUpdated(string $entryId, DateTimeImmutable $updated): void{
// Only save the updated timestamp for the given entry ID in this file
foreach($this->Entries as $entry){
if($entry instanceof OpdsNavigationEntry){
@@ -50,7 +50,7 @@ class OpdsFeed extends AtomFeed{
if($this->HasChanged($this->Path)){
// Files don't match, save the file and update the parent navigation feed with the last updated timestamp
- $this->Updated = new DateTime();
+ $this->Updated = new DateTimeImmutable();
if($this->Parent !== null){
$this->Parent->SaveUpdated($this->Id, $this->Updated);
diff --git a/lib/OpdsNavigationEntry.php b/lib/OpdsNavigationEntry.php
index 4f671c4c..44ccea13 100644
--- a/lib/OpdsNavigationEntry.php
+++ b/lib/OpdsNavigationEntry.php
@@ -1,15 +1,17 @@
+use Safe\DateTimeImmutable;
+
class OpdsNavigationEntry{
public string $Id;
public string $Url;
public string $Rel;
public string $Type;
- public ?DateTime $Updated = null;
+ public ?DateTimeImmutable $Updated = null;
public string $Description;
public string $Title;
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, ?DateTimeImmutable $updated, string $rel, string $type){
$this->Id = SITE_URL . $url;
$this->Url = $url;
$this->Rel = $rel;
diff --git a/lib/OpdsNavigationFeed.php b/lib/OpdsNavigationFeed.php
index 128c11fe..894e8417 100644
--- a/lib/OpdsNavigationFeed.php
+++ b/lib/OpdsNavigationFeed.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
class OpdsNavigationFeed extends OpdsFeed{
@@ -25,7 +25,7 @@ class OpdsNavigationFeed extends OpdsFeed{
foreach($xml->xpath('//entry') ?: [] as $existingEntry){
foreach($this->Entries as $entry){
if($entry->Id == $existingEntry->id){
- $entry->Updated = new DateTime($existingEntry->updated);
+ $entry->Updated = new DateTimeImmutable($existingEntry->updated);
}
}
}
diff --git a/lib/Patron.php b/lib/Patron.php
index 6a788b70..1344a949 100644
--- a/lib/Patron.php
+++ b/lib/Patron.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
/**
* @property User $User
@@ -10,8 +10,8 @@ class Patron extends Accessor{
public bool $IsAnonymous;
public ?string $AlternateName = null;
public bool $IsSubscribedToEmails;
- public ?DateTime $Created = null;
- public ?DateTime $Ended = null;
+ public ?DateTimeImmutable $Created = null;
+ public ?DateTimeImmutable $Ended = null;
// *******
@@ -19,7 +19,7 @@ class Patron extends Accessor{
// *******
public function Create(): void{
- $this->Created = new DateTime();
+ $this->Created = new DateTimeImmutable();
Db::Query('
INSERT into Patrons (Created, UserId, IsAnonymous, AlternateName, IsSubscribedToEmails)
values(?,
diff --git a/lib/Payment.php b/lib/Payment.php
index de1eb7d5..bc70ab42 100644
--- a/lib/Payment.php
+++ b/lib/Payment.php
@@ -1,11 +1,13 @@
+use Safe\DateTimeImmutable;
+
/**
* @property User $User
*/
class Payment extends Accessor{
public int $PaymentId;
public ?int $UserId = null;
- public DateTime $Created;
+ public DateTimeImmutable $Created;
public int $ChannelId;
public string $TransactionId;
public float $Amount;
diff --git a/lib/Poll.php b/lib/Poll.php
index 46a766df..06ccf5b6 100644
--- a/lib/Poll.php
+++ b/lib/Poll.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\usort;
/**
@@ -15,9 +15,9 @@ class Poll extends Accessor{
public string $Name;
public string $UrlName;
public string $Description;
- public DateTime $Created;
- public DateTime $Start;
- public DateTime $End;
+ public DateTimeImmutable $Created;
+ public DateTimeImmutable $Start;
+ public DateTimeImmutable $End;
protected ?string $_Url = null;
protected $_PollItems = null;
protected $_PollItemsByWinner = null;
@@ -85,7 +85,7 @@ class Poll extends Accessor{
// *******
public function IsActive(): bool{
- $now = new DateTime();
+ $now = new DateTimeImmutable();
if( ($this->Start !== null && $this->Start > $now) || ($this->End !== null && $this->End < $now)){
return false;
}
diff --git a/lib/PollVote.php b/lib/PollVote.php
index 4d905a74..ed2fda4b 100644
--- a/lib/PollVote.php
+++ b/lib/PollVote.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
/**
* @property User $User
@@ -8,7 +8,7 @@ use Safe\DateTime;
*/
class PollVote extends Accessor{
public int $UserId;
- public DateTime $Created;
+ public DateTimeImmutable $Created;
public ?int $PollItemId = null;
protected ?User $_User = null;
protected ?PollItem $_PollItem = null;
@@ -98,7 +98,7 @@ class PollVote extends Accessor{
}
$this->Validate();
- $this->Created = new DateTime();
+ $this->Created = new DateTimeImmutable();
Db::Query('
INSERT into PollVotes (UserId, PollItemId, Created)
values (?,
diff --git a/lib/RssFeed.php b/lib/RssFeed.php
index b59507eb..8960944c 100644
--- a/lib/RssFeed.php
+++ b/lib/RssFeed.php
@@ -1,5 +1,5 @@
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\file_get_contents;
use function Safe\filesize;
use function Safe\preg_replace;
@@ -27,7 +27,7 @@ class RssFeed extends Feed{
protected function GetXmlString(): string{
if($this->XmlString === null){
- $feed = Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => (new DateTime())->format('r')]);
+ $feed = Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => (new DateTimeImmutable())->format('r')]);
$this->XmlString = $this->CleanXmlString($feed);
}
diff --git a/lib/Session.php b/lib/Session.php
index 3efca7eb..9072ab54 100644
--- a/lib/Session.php
+++ b/lib/Session.php
@@ -2,7 +2,7 @@
use Exceptions\InvalidLoginException;
use Ramsey\Uuid\Uuid;
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
use function Safe\strtotime;
/**
@@ -12,7 +12,7 @@ use function Safe\strtotime;
class Session extends Accessor{
public int $UserId;
protected ?User $_User = null;
- public DateTime $Created;
+ public DateTimeImmutable $Created;
public string $SessionId;
public ?string $_Url = null;
@@ -53,7 +53,7 @@ class Session extends Accessor{
else{
$uuid = Uuid::uuid4();
$this->SessionId = $uuid->toString();
- $this->Created = new DateTime();
+ $this->Created = new DateTimeImmutable();
Db::Query('
INSERT into Sessions (UserId, SessionId, Created)
values (?,
diff --git a/lib/User.php b/lib/User.php
index b196b341..7c993a50 100644
--- a/lib/User.php
+++ b/lib/User.php
@@ -1,6 +1,6 @@
use Ramsey\Uuid\Uuid;
-use Safe\DateTime;
+use Safe\DateTimeImmutable;
/**
* @property Array
This poll opens on = $poll->Start->format('F j, Y g:i a') ?>.
}else{ ?>This poll closed on = $poll->End->format('F j, Y g:i a') ?>.
diff --git a/www/webhooks/zoho.php b/www/webhooks/zoho.php index 8279d765..b73eba1d 100644 --- a/www/webhooks/zoho.php +++ b/www/webhooks/zoho.php @@ -1,5 +1,5 @@ -use Safe\DateTime; +use Safe\DateTimeImmutable; use function Safe\file_get_contents; use function Safe\preg_match; use function Safe\preg_replace;