Enable some additional PHPStan rules and fix some type issues

This commit is contained in:
Alex Cabal 2025-03-01 13:39:57 -06:00
parent c9e5026cf4
commit a019d5e87c
8 changed files with 21 additions and 18 deletions

View file

@ -5,6 +5,9 @@ includes:
parameters:
level: 9
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
ignoreErrors:
# Ignore errors caused by `Template` static class reflection.

View file

@ -53,7 +53,7 @@ class AtomFeed extends Feed{
$currentEntries = [];
foreach($this->Entries as $entry){
$obj = new StdClass();
$obj = new stdClass();
if($entry instanceof Ebook){
if($entry->EbookUpdated !== null){
$obj->Updated = $entry->EbookUpdated->format(Enums\DateTimeFormat::Iso->value);
@ -75,7 +75,7 @@ class AtomFeed extends Feed{
$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($path)));
foreach($xml->xpath('/feed/entry') ?: [] as $entry){
$obj = new StdClass();
$obj = new stdClass();
$obj->Updated = $entry->updated;
$obj->Id = $entry->id;
$oldEntries[] = $obj;

View file

@ -315,7 +315,7 @@ class Db{
* @param string $sql The SQL query to execute.
* @param array<mixed> $params An array of parameters to bind to the SQL statement.
*
* @return \PdoStatement The `\PDOStatement` to be used to execute the query.
* @return \PDOStatement The `\PDOStatement` to be used to execute the query.
*
* @throws Exceptions\DatabaseQueryException When an error occurs during execution of the query.
*/
@ -360,7 +360,7 @@ class Db{
*
* @template T
*
* @param \PdoStatement $handle The PDO handle to execute.
* @param \PDOStatement $handle The PDO handle to execute.
* @param class-string<T> $class The type of object to return in the return array.
*
* @return array<T> An array of objects of type `$class`, or `stdClass` if `$class` is `null`.
@ -440,7 +440,7 @@ class Db{
*
* @template T
*
* @param \PdoStatement $handle The PDO handle to execute.
* @param \PDOStatement $handle The PDO handle to execute.
* @param class-string<T> $class The class to instantiate for each row, or `stdClass` to return an array of rows.
*
* @return array<T>|array<array<string, stdClass>> An array of `$class` if `$class` is not `stdClass`, otherwise an array of rows of the form `["LeftTableName" => $stdClass, "RightTableName" => $stdClass]`.

View file

@ -40,25 +40,25 @@ class Email{
$phpMailer = new PHPMailer(true);
try{
$phpMailer->SetFrom($this->From, $this->FromName);
$phpMailer->AddReplyTo($this->ReplyTo);
$phpMailer->AddAddress($this->To, $this->ToName);
$phpMailer->setFrom($this->From, $this->FromName);
$phpMailer->addReplyTo($this->ReplyTo);
$phpMailer->addAddress($this->To, $this->ToName);
$phpMailer->Subject = $this->Subject;
$phpMailer->CharSet = 'UTF-8';
if($this->TextBody != ''){
$phpMailer->IsHTML(true);
$phpMailer->isHTML(true);
$phpMailer->Body = $this->Body;
$phpMailer->AltBody = $this->TextBody;
}
else{
$phpMailer->MsgHTML($this->Body);
$phpMailer->msgHTML($this->Body);
}
foreach($this->Attachments as $attachment){
$phpMailer->addStringAttachment($attachment['contents'], $attachment['filename']);
}
$phpMailer->IsSMTP();
$phpMailer->isSMTP();
$phpMailer->SMTPAuth = true;
$phpMailer->SMTPSecure = 'tls';
$phpMailer->Port = 587;
@ -78,7 +78,7 @@ class Email{
$log->Write($this->TextBody);
}
else{
$phpMailer->Send();
$phpMailer->send();
}
}
catch(Exception $ex){

View file

@ -45,7 +45,7 @@ class RssFeed extends Feed{
$currentEntries = [];
foreach($this->Entries as $entry){
/** @var Ebook $entry */
$obj = new StdClass();
$obj = new stdClass();
$obj->Size = (string)filesize(WEB_ROOT . $entry->EpubUrl);
$obj->Id = preg_replace('/^url:/ius', '', $entry->Identifier);
$currentEntries[] = $obj;
@ -56,7 +56,7 @@ class RssFeed extends Feed{
$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($path)));
$xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
foreach($xml->xpath('/rss/channel/item') ?: [] as $entry){
$obj = new StdClass();
$obj = new stdClass();
foreach($entry->xpath('enclosure') ?: [] as $enclosure){
$obj->Size = (string)$enclosure['length'];
}

View file

@ -116,7 +116,7 @@ try{
// Check if we need to log in to FA.
// Wait until the <body> element is visible, then check the current URL.
$driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body')));
if(stripos($driver->getCurrentUrl(), 'auth0.com')){
if(stripos($driver->getCurrentURL(), 'auth0.com')){
$log->Write('Logging in to Fractured Atlas ...');
// We were redirected to the login page, so try to log in.

View file

@ -91,7 +91,7 @@ try{
// Check if we need to log in to FA.
// Wait until the <body> element is visible, then check the current URL.
$driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body')));
if(stripos($driver->getCurrentUrl(), 'auth0.com')){
if(stripos($driver->getCurrentURL(), 'auth0.com')){
$log->Write('Logging in to Fractured Atlas ...');
// We were redirected to the login page, so try to log in.

View file

@ -76,7 +76,7 @@ catch(Exceptions\InvalidPermissionsException){
</tr>
<tr>
<td>Created:</td>
<td><?= $user->Created->Format(Enums\DateTimeFormat::FullDateTime->value) ?></td>
<td><?= $user->Created->format(Enums\DateTimeFormat::FullDateTime->value) ?></td>
</tr>
</tbody>
</table>
@ -219,7 +219,7 @@ catch(Exceptions\InvalidPermissionsException){
<? foreach($user->Payments as $payment){ ?>
<tr>
<td>
<time datetime="<?= $payment->Created->format(Enums\DateTimeFormat::Html->value) ?>"><?= $payment->Created->Format(Enums\DateTimeFormat::FullDateTime->value) ?></time>
<time datetime="<?= $payment->Created->format(Enums\DateTimeFormat::Html->value) ?>"><?= $payment->Created->format(Enums\DateTimeFormat::FullDateTime->value) ?></time>
</td>
<td>
<? if($payment->IsRecurring){ ?>