diff options
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/API.php | 3 | ||||
| -rw-r--r-- | classes/Config.php | 10 | ||||
| -rw-r--r-- | classes/Db.php | 9 | ||||
| -rw-r--r-- | classes/DiskCache.php | 5 | ||||
| -rw-r--r-- | classes/FeedEnclosure.php | 26 | ||||
| -rw-r--r-- | classes/FeedItem_Atom.php | 10 | ||||
| -rw-r--r-- | classes/FeedItem_Common.php | 61 | ||||
| -rw-r--r-- | classes/FeedItem_RSS.php | 16 | ||||
| -rw-r--r-- | classes/FeedParser.php | 22 | ||||
| -rw-r--r-- | classes/Logger.php | 6 | ||||
| -rw-r--r-- | classes/Pref_Filters.php | 2 | ||||
| -rw-r--r-- | classes/Prefs.php | 8 |
12 files changed, 69 insertions, 109 deletions
diff --git a/classes/API.php b/classes/API.php index 31a3bec97..241663b3d 100644 --- a/classes/API.php +++ b/classes/API.php @@ -14,8 +14,7 @@ class API extends Handler { const E_OPERATION_FAILED = "E_OPERATION_FAILED"; const E_NOT_FOUND = "E_NOT_FOUND"; - /** @var int|null */ - private $seq; + private ?int $seq = null; /** * @param array<int|string, mixed> $reply diff --git a/classes/Config.php b/classes/Config.php index 9d671215a..356f81391 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -252,17 +252,15 @@ class Config { Config::HTTP_429_THROTTLE_INTERVAL => [ 3600, Config::T_INT ] ]; - /** @var Config|null */ - private static $instance; + private static ?Config $instance = null; /** @var array<string, array<bool|int|string>> */ - private $params = []; + private array $params = []; /** @var array<string, mixed> */ - private $version = []; + private array $version = []; - /** @var Db_Migrations|null $migrations */ - private $migrations; + private Db_Migrations $migrations; public static function get_instance() : Config { if (self::$instance == null) diff --git a/classes/Db.php b/classes/Db.php index 4331b662e..2d8511258 100644 --- a/classes/Db.php +++ b/classes/Db.php @@ -1,11 +1,8 @@ <?php -class Db -{ - /** @var Db $instance */ - private static $instance; +class Db { + private static ?Db $instance = null; - /** @var PDO|null $pdo */ - private $pdo; + private ?PDO $pdo = null; function __construct() { ORM::configure(self::get_dsn()); diff --git a/classes/DiskCache.php b/classes/DiskCache.php index c52759a75..70b8de173 100644 --- a/classes/DiskCache.php +++ b/classes/DiskCache.php @@ -1,10 +1,9 @@ <?php class DiskCache implements Cache_Adapter { - /** @var Cache_Adapter $adapter */ - private $adapter; + private Cache_Adapter $adapter; /** @var array<string, DiskCache> $instances */ - private static $instances = []; + private static array $instances = []; /** * https://stackoverflow.com/a/53662733 diff --git a/classes/FeedEnclosure.php b/classes/FeedEnclosure.php index b5f5cc411..6ef9bca5e 100644 --- a/classes/FeedEnclosure.php +++ b/classes/FeedEnclosure.php @@ -1,21 +1,11 @@ <?php class FeedEnclosure { - /** @var string */ - public $link; - - /** @var string */ - public $type; - - /** @var string */ - public $length; - - /** @var string */ - public $title; - - /** @var string */ - public $height; - - /** @var string */ - public $width; + function __construct( + public string $link = '', + public string $type = '', + public string $length = '', + public string $title = '', + public string $height = '', + public string $width = '', + ) {} } - diff --git a/classes/FeedItem_Atom.php b/classes/FeedItem_Atom.php index 234b96341..ad1bddc07 100644 --- a/classes/FeedItem_Atom.php +++ b/classes/FeedItem_Atom.php @@ -184,11 +184,11 @@ class FeedItem_Atom extends FeedItem_Common { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); if ($link->getAttribute("rel") == "enclosure") { - $enc = new FeedEnclosure(); - - $enc->type = clean($link->getAttribute("type")); - $enc->length = clean($link->getAttribute("length")); - $enc->link = clean($link->getAttribute("href")); + $enc = new FeedEnclosure( + type: clean($link->getAttribute('type')), + length: clean($link->getAttribute('length')), + link: clean($link->getAttribute('href')), + ); if (!empty($base)) { $enc->link = UrlHelper::rewrite_relative($base, $enc->link); diff --git a/classes/FeedItem_Common.php b/classes/FeedItem_Common.php index 1471dc3e3..5b30ab20c 100644 --- a/classes/FeedItem_Common.php +++ b/classes/FeedItem_Common.php @@ -1,19 +1,10 @@ <?php abstract class FeedItem_Common extends FeedItem { - /** @var DOMElement */ - protected $elem; - - /** @var DOMDocument */ - protected $doc; - - /** @var DOMXPath */ - protected $xpath; - - function __construct(DOMElement $elem, DOMDocument $doc, DOMXPath $xpath) { - $this->elem = $elem; - $this->xpath = $xpath; - $this->doc = $doc; - + function __construct( + protected readonly DOMElement $elem, + protected readonly DOMDocument $doc, + protected readonly DOMXPath $xpath, + ) { try { $source = $elem->getElementsByTagName("source")->item(0); @@ -97,13 +88,13 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:content", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = clean($enclosure->getAttribute("type")); - $enc->link = clean($enclosure->getAttribute("url")); - $enc->length = clean($enclosure->getAttribute("length")); - $enc->height = clean($enclosure->getAttribute("height")); - $enc->width = clean($enclosure->getAttribute("width")); + $enc = new FeedEnclosure( + type: clean($enclosure->getAttribute('type')), + link: clean($enclosure->getAttribute('url')), + length: clean($enclosure->getAttribute('length')), + height: clean($enclosure->getAttribute('height')), + width: clean($enclosure->getAttribute('width')), + ); $medium = clean($enclosure->getAttribute("medium")); if (!$enc->type && $medium) { @@ -119,17 +110,17 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:group", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - /** @var DOMElement|null */ $content = $this->xpath->query("media:content", $enclosure)->item(0); if ($content) { - $enc->type = clean($content->getAttribute("type")); - $enc->link = clean($content->getAttribute("url")); - $enc->length = clean($content->getAttribute("length")); - $enc->height = clean($content->getAttribute("height")); - $enc->width = clean($content->getAttribute("width")); + $enc = new FeedEnclosure( + type: clean($content->getAttribute('type')), + link: clean($content->getAttribute('url')), + length: clean($content->getAttribute('length')), + height: clean($content->getAttribute('height')), + width: clean($content->getAttribute('width')), + ); $medium = clean($content->getAttribute("medium")); if (!$enc->type && $medium) { @@ -151,14 +142,12 @@ abstract class FeedItem_Common extends FeedItem { $enclosures = $this->xpath->query("media:thumbnail", $this->elem); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = "image/generic"; - $enc->link = clean($enclosure->getAttribute("url")); - $enc->height = clean($enclosure->getAttribute("height")); - $enc->width = clean($enclosure->getAttribute("width")); - - array_push($encs, $enc); + $encs[] = new FeedEnclosure( + type: 'image/generic', + link: clean($enclosure->getAttribute('url')), + height: clean($enclosure->getAttribute('height')), + width: clean($enclosure->getAttribute('width')), + ); } return $encs; diff --git a/classes/FeedItem_RSS.php b/classes/FeedItem_RSS.php index ab1764577..2970e43bd 100644 --- a/classes/FeedItem_RSS.php +++ b/classes/FeedItem_RSS.php @@ -141,15 +141,13 @@ class FeedItem_RSS extends FeedItem_Common { $encs = array(); foreach ($enclosures as $enclosure) { - $enc = new FeedEnclosure(); - - $enc->type = clean($enclosure->getAttribute("type")); - $enc->link = clean($enclosure->getAttribute("url")); - $enc->length = clean($enclosure->getAttribute("length")); - $enc->height = clean($enclosure->getAttribute("height")); - $enc->width = clean($enclosure->getAttribute("width")); - - array_push($encs, $enc); + $encs[] = new FeedEnclosure( + type: clean($enclosure->getAttribute('type')), + link: clean($enclosure->getAttribute('url')), + length: clean($enclosure->getAttribute('length')), + height: clean($enclosure->getAttribute('height')), + width: clean($enclosure->getAttribute('width')), + ); } array_push($encs, ...parent::get_enclosures()); diff --git a/classes/FeedParser.php b/classes/FeedParser.php index c288ffc91..fd26226ae 100644 --- a/classes/FeedParser.php +++ b/classes/FeedParser.php @@ -1,29 +1,23 @@ <?php class FeedParser { + private DOMDocument $doc; - /** @var DOMDocument */ - private $doc; - - /** @var string|null */ - private $error = null; + private ?string $error = null; /** @var array<string> */ - private $libxml_errors = []; + private array $libxml_errors = []; /** @var array<FeedItem> */ - private $items = []; + private array $items = []; - /** @var string|null */ - private $link; + private ?string $link = null; - /** @var string|null */ - private $title; + private ?string $title = null; /** @var FeedParser::FEED_*|null */ - private $type; + private ?int $type = null; - /** @var DOMXPath|null */ - private $xpath; + private ?DOMXPath $xpath = null; const FEED_UNKNOWN = -1; const FEED_RDF = 0; diff --git a/classes/Logger.php b/classes/Logger.php index 049b63d5e..05a117a0b 100644 --- a/classes/Logger.php +++ b/classes/Logger.php @@ -1,10 +1,8 @@ <?php class Logger { - /** @var Logger|null */ - private static $instance; + private static ?Logger $instance = null; - /** @var Logger_Adapter|null */ - private $adapter; + private ?Logger_Adapter $adapter = null; const LOG_DEST_SQL = "sql"; const LOG_DEST_STDOUT = "stdout"; diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 46180e0cb..c73de05f0 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -13,7 +13,7 @@ class Pref_Filters extends Handler_Protected { const MAX_ACTIONS_TO_DISPLAY = 3; /** @var array<int,array<mixed>> $action_descriptions */ - private $action_descriptions = []; + private array $action_descriptions = []; function before(string $method) : bool { diff --git a/classes/Prefs.php b/classes/Prefs.php index f7e6e39c0..08f402d40 100644 --- a/classes/Prefs.php +++ b/classes/Prefs.php @@ -144,14 +144,12 @@ class Prefs { Prefs::_PREFS_MIGRATED ]; - /** @var Prefs|null */ - private static $instance; + private static ?Prefs $instance = null; /** @var array<string, bool|int|string> */ - private $cache = []; + private array $cache = []; - /** @var PDO */ - private $pdo; + private ?PDO $pdo = null; public static function get_instance() : Prefs { if (self::$instance == null) |