diff --git a/public/index.php b/public/index.php index eb7cae2..b4ff526 100644 --- a/public/index.php +++ b/public/index.php @@ -26,7 +26,7 @@ if(file_exists(MKI_ROOT . '/.migrating')) { exit; } -$makai->getCSRFP()->setInfo( +$makai->csrfp->setInfo( $cfg->getString('csrfp:secret', 'meow'), (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR') ); diff --git a/src/AssetsRoutes.php b/src/AssetsRoutes.php index b23471b..af1ee32 100644 --- a/src/AssetsRoutes.php +++ b/src/AssetsRoutes.php @@ -12,6 +12,6 @@ class AssetsRoutes implements RouteHandler { #[HttpGet('/header-bgs.json')] public function getHeaderImages(): array { - return $this->siteInfo->getHeaderImages(); + return $this->siteInfo->headerImages; } } diff --git a/src/Contacts/ContactInfo.php b/src/Contacts/ContactInfo.php index aa70fd9..54f99cf 100644 --- a/src/Contacts/ContactInfo.php +++ b/src/Contacts/ContactInfo.php @@ -5,75 +5,43 @@ use Index\Colour\{Colour,ColourRgb}; use Index\Db\DbResult; class ContactInfo { - private string $name; - private bool $homePage; - private int $order; - private string $title; - private string $icon; - private int $colour; - private string $display; - private ?string $link; + public function __construct( + public private(set) string $name, + public private(set) bool $homePage, + public private(set) int $order, + public private(set) string $title, + public private(set) string $icon, + public private(set) int $colourRaw, + public private(set) string $display, + public private(set) ?string $link, + ) {} - public function __construct(DbResult $result) { - $this->name = $result->getString(0); - $this->homePage = $result->getInteger(1) !== 0; - $this->order = $result->getInteger(2); - $this->title = $result->getString(3); - $this->icon = $result->getString(4); - $this->colour = $result->getInteger(5); - $this->display = $result->getString(6); - $this->link = $result->isNull(7) ? null : $result->getString(7); + public static function fromResult(DbResult $result): ContactInfo { + return new ContactInfo( + name: $result->getString(0), + homePage: $result->getBoolean(1), + order: $result->getInteger(2), + title: $result->getString(3), + icon: $result->getString(4), + colourRaw: $result->getInteger(5), + display: $result->getString(6), + link: $result->getStringOrNull(7), + ); } - public function getName(): string { - return $this->name; + public bool $iconIsDomain { + get => str_starts_with($this->icon, 'url:'); } - public function isHomePage(): bool { - return $this->homePage; + public bool $iconIsImage { + get => mb_strlen($this->icon) > 1; } - public function getOrder(): int { - return $this->order; + public string $iconDomain { + get => substr($this->icon, 4); } - public function getTitle(): string { - return $this->title; - } - - public function getIcon(): string { - return $this->icon; - } - - public function iconIsDomain(): bool { - return str_starts_with($this->icon, 'url:'); - } - - public function iconIsImage(): bool { - return mb_strlen($this->icon) > 1; - } - - public function getIconDomain(): string { - return substr($this->icon, 4); - } - - public function getColour(): Colour { - return ColourRgb::fromRawRgb($this->colour); - } - - public function getColourRaw(): int { - return $this->colour; - } - - public function getDisplay(): string { - return $this->display; - } - - public function hasLink(): bool { - return $this->link !== null; - } - - public function getLink(): ?string { - return $this->link; + public Colour $colour { + get => ColourRgb::fromRawRgb($this->colourRaw); } } diff --git a/src/Contacts/Contacts.php b/src/Contacts/Contacts.php index 622c790..7c115fe 100644 --- a/src/Contacts/Contacts.php +++ b/src/Contacts/Contacts.php @@ -13,7 +13,7 @@ class Contacts { public function getContacts( bool $featuredOnly = false, ?int $take = null - ): array { + ): iterable { $hasTake = $take !== null; $query = 'SELECT cont_name, cont_homepage, cont_order, cont_title, cont_icon, cont_colour, cont_display, cont_link FROM fm_contacts'; @@ -28,12 +28,6 @@ class Contacts { $stmt->addParameter(1, $take); $stmt->execute(); - $result = $stmt->getResult(); - $contacts = []; - - while($result->next()) - $contacts[] = new ContactInfo($result); - - return $contacts; + return $stmt->getResult()->getIterator(ContactInfo::fromResult(...)); } } diff --git a/src/DeveloperRoutes.php b/src/DeveloperRoutes.php index 585f61a..695f940 100644 --- a/src/DeveloperRoutes.php +++ b/src/DeveloperRoutes.php @@ -26,7 +26,7 @@ class DeveloperRoutes implements RouteHandler { foreach($projectInfos as $projectInfo) $projects[] = [ 'info' => $projectInfo, - 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), + 'colour' => $projectInfo->colourRaw !== null ? $projectInfo->colour : $this->projects->getProjectColour($projectInfo), ]; return $this->templating->render('dev/index', [ @@ -43,7 +43,7 @@ class DeveloperRoutes implements RouteHandler { $projects[] = [ 'info' => $projectInfo, 'langs' => $this->projects->getLanguages(projectInfo: $projectInfo), - 'colour' => $projectInfo->hasColour() ? $projectInfo->getColour() : $this->projects->getProjectColour($projectInfo), + 'colour' => $projectInfo->colourRaw !== null ? $projectInfo->colour : $this->projects->getProjectColour($projectInfo), ]; return $this->templating->render('dev/projects', [ diff --git a/src/MakaiContext.php b/src/MakaiContext.php index db96bf2..7214737 100644 --- a/src/MakaiContext.php +++ b/src/MakaiContext.php @@ -6,18 +6,18 @@ use Index\Db\Migration\{DbMigrationRepo,DbMigrationManager,FsDbMigrationRepo}; use Index\Templating\TplEnvironment; final class MakaiContext { - private DbConnection $dbConn; - private TplEnvironment $templating; - private CSRFPContainer $csrfp; + public private(set) TplEnvironment $templating; + public private(set) CSRFPContainer $csrfp; - private SiteInfo $siteInfo; + public private(set) SiteInfo $siteInfo; - private Contacts\Contacts $contacts; - private Projects\Projects $projects; - private SSHKeys\SSHKeys $sshKeys; + public private(set) Contacts\Contacts $contacts; + public private(set) Projects\Projects $projects; + public private(set) SSHKeys\SSHKeys $sshKeys; - public function __construct(DbConnection $dbConn) { - $this->dbConn = $dbConn; + public function __construct( + public private(set) DbConnection $dbConn + ) { $this->siteInfo = new SiteInfo; $this->csrfp = new CSRFPContainer; @@ -28,26 +28,6 @@ final class MakaiContext { $this->sshKeys = new SSHKeys\SSHKeys($dbConn); } - public function getSiteInfo(): SiteInfo { - return $this->siteInfo; - } - - public function getContacts(): Contacts\Contacts { - return $this->contacts; - } - - public function getProjects(): Projects\Projects { - return $this->projects; - } - - public function getSSHKeys(): SSHKeys\SSHKeys { - return $this->sshKeys; - } - - public function getDbConn(): DbConnection { - return $this->dbConn; - } - public function getDbQueryCount(): int { $result = $this->dbConn->query('SHOW SESSION STATUS LIKE "Questions"'); return $result->next() ? $result->getInteger(1) : 0; @@ -61,10 +41,6 @@ final class MakaiContext { return new FsDbMigrationRepo(MKI_DIR_MIGRATIONS); } - public function getTemplating(): TplEnvironment { - return $this->templating; - } - public function startTemplating(): void { $this->templating = new TplEnvironment( MKI_DIR_TEMPLATES, @@ -79,10 +55,6 @@ final class MakaiContext { ]); } - public function getCSRFP(): CSRFPContainer { - return $this->csrfp; - } - public function createRouting(): RoutingContext { $routingCtx = new RoutingContext; diff --git a/src/Projects/LanguageInfo.php b/src/Projects/LanguageInfo.php index 8a0f1af..c30a365 100644 --- a/src/Projects/LanguageInfo.php +++ b/src/Projects/LanguageInfo.php @@ -5,33 +5,21 @@ use Index\Colour\{Colour,ColourRgb}; use Index\Db\DbResult; class LanguageInfo { - private string $id; - private string $name; - private ?int $colour; + public function __construct( + public private(set) string $id, + public private(set) string $name, + public private(set) ?int $colourRaw, + ) {} - public function __construct(DbResult $result) { - $this->id = $result->getString(0); - $this->name = $result->getString(1); - $this->colour = $result->isNull(2) ? null : $result->getInteger(2); + public static function fromResult(DbResult $result): LanguageInfo { + return new LanguageInfo( + id: $result->getString(0), + name: $result->getString(1), + colourRaw: $result->getIntegerOrNull(2), + ); } - public function getId(): string { - return $this->id; - } - - public function getName(): string { - return $this->name; - } - - public function hasColour(): bool { - return $this->colour !== null; - } - - public function getColour(): Colour { - return $this->colour === null ? Colour::none() : ColourRgb::fromRawRGB($this->colour); - } - - public function getColourRaw(): ?int { - return $this->colour; + public Colour $colour { + get => $this->colourRaw === null ? Colour::none() : ColourRgb::fromRawRGB($this->colourRaw); } } diff --git a/src/Projects/ProjectInfo.php b/src/Projects/ProjectInfo.php index c1c09ba..24070bb 100644 --- a/src/Projects/ProjectInfo.php +++ b/src/Projects/ProjectInfo.php @@ -6,149 +6,65 @@ use Index\Colour\{Colour,ColourRgb}; use Index\Db\DbResult; class ProjectInfo { - private string $id; - private string $name; - private string $nameClean; - private ?string $summary; - private ?string $description; - private int $order; - private string $type; - private bool $featured; - private ?int $colour; - private ?string $homepage; - private ?string $source; - private ?string $discussion; - private int $createdAt; - private ?int $archivedAt; - private ?int $deletedAt; + public function __construct( + public private(set) string $id, + public private(set) string $name, + public private(set) string $nameClean, + public private(set) ?string $summary, + public private(set) ?string $description, + public private(set) int $order, + public private(set) string $type, + public private(set) bool $featured, + public private(set) ?int $colourRaw, + public private(set) ?string $homePageUrl, + public private(set) ?string $sourceUrl, + public private(set) ?string $discussionUrl, + public private(set) int $createdTime, + public private(set) ?int $archivedTime, + public private(set) ?int $deletedTime, + ) {} - public function __construct(DbResult $result) { - $this->id = $result->getString(0); - $this->name = $result->getString(1); - $this->nameClean = $result->getString(2); - $this->summary = $result->isNull(3) ? null : $result->getString(3); - $this->description = $result->isNull(4) ? null : $result->getString(4); - $this->order = $result->getInteger(5); - $this->type = $result->getString(6); - $this->featured = $result->getInteger(7) !== 0; - $this->colour = $result->isNull(8) ? null : $result->getInteger(8); - $this->homepage = $result->isNull(9) ? null : $result->getString(9); - $this->source = $result->isNull(10) ? null : $result->getString(10); - $this->discussion = $result->isNull(11) ? null : $result->getString(11); - $this->createdAt = $result->getInteger(12); - $this->archivedAt = $result->isNull(13) ? null : $result->getInteger(13); - $this->deletedAt = $result->isNull(14) ? null : $result->getInteger(14); + public static function fromResult(DbResult $result): ProjectInfo { + return new ProjectInfo( + id: $result->getString(0), + name: $result->getString(1), + nameClean: $result->getString(2), + summary: $result->getStringOrNull(3), + description: $result->getStringOrNull(4), + order: $result->getInteger(5), + type: $result->getString(6), + featured: $result->getBoolean(7), + colourRaw: $result->getIntegerOrNull(8), + homePageUrl: $result->getStringOrNull(9), + sourceUrl: $result->getStringOrNull(10), + discussionUrl: $result->getStringOrNull(11), + createdTime: $result->getInteger(12), + archivedTime: $result->getIntegerOrNull(13), + deletedTime: $result->getIntegerOrNull(14), + ); } - public function getId(): string { - return $this->id; + public Colour $colour { + get => $this->colourRaw === null ? Colour::none() : ColourRgb::fromRawRGB($this->colourRaw); } - public function getName(): string { - return $this->name; + public CarbonImmutable $createdAt { + get => CarbonImmutable::createFromTimestampUTC($this->createdTime); } - public function getCleanName(): string { - return $this->nameClean; + public ?CarbonImmutable $archivedAt { + get => $this->archivedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->archivedTime); } - public function hasSummary(): bool { - return $this->summary !== null; + public bool $archived { + get => $this->archivedTime !== null; } - public function getSummary(): ?string { - return $this->summary; + public ?CarbonImmutable $deletedAt { + get => $this->deletedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->deletedTime); } - public function hasDescription(): bool { - return $this->description !== null; - } - - public function getDescription(): ?string { - return $this->description; - } - - public function isFeatured(): bool { - return $this->featured; - } - - public function getOrder(): int { - return $this->order; - } - - public function hasColour(): bool { - return $this->colour !== null; - } - - public function getColour(): Colour { - return $this->colour === null ? Colour::none() : ColourRgb::fromRawRGB($this->colour); - } - - public function getColourRaw(): ?int { - return $this->colour; - } - - public function getProjectType(): string { - return $this->type; - } - - public function isTool(): bool { - return $this->getProjectType() === 'Tool'; - } - - public function hasHomePageUrl(): bool { - return $this->homepage !== null; - } - - public function getHomePageUrl(): ?string { - return $this->homepage; - } - - public function hasSourceUrl(): bool { - return $this->source !== null; - } - - public function getSourceUrl(): ?string { - return $this->source; - } - - public function hasDiscussionUrl(): bool { - return $this->discussion !== null; - } - - public function getDiscussionUrl(): ?string { - return $this->discussion; - } - - public function getCreatedTime(): int { - return $this->createdAt; - } - - public function getCreatedAt(): CarbonImmutable { - return CarbonImmutable::createFromTimestampUTC($this->createdAt); - } - - public function getArchivedTime(): ?int { - return $this->archivedAt; - } - - public function getArchivedAt(): ?CarbonImmutable { - return $this->archivedAt === null ? null : CarbonImmutable::createFromTimestampUTC($this->archivedAt); - } - - public function isArchived(): bool { - return $this->archivedAt !== null; - } - - public function getDeletedTime(): ?int { - return $this->deletedAt; - } - - public function getDeletedAt(): ?CarbonImmutable { - return $this->deletedAt === null ? null : CarbonImmutable::createFromTimestampUTC($this->deletedAt); - } - - public function isDeleted(): bool { - return $this->deletedAt !== null; + public bool $deleted { + get => $this->deletedTime !== null; } } diff --git a/src/Projects/Projects.php b/src/Projects/Projects.php index 9667cfb..3ec1e46 100644 --- a/src/Projects/Projects.php +++ b/src/Projects/Projects.php @@ -16,7 +16,7 @@ class Projects { ?bool $deleted = null, ?int $take = null, bool $random = false - ): array { + ): iterable { $hasDeleted = $deleted !== null; $hasTake = $take !== null; @@ -37,18 +37,12 @@ class Projects { $stmt->addParameter(1, $take); $stmt->execute(); - $result = $stmt->getResult(); - $projects = []; - - while($result->next()) - $projects[] = new ProjectInfo($result); - - return $projects; + return $stmt->getResult()->getIterator(ProjectInfo::fromResult(...)); } public function getLanguages( ProjectInfo|string|null $projectInfo = null - ): array { + ): iterable { $hasProjectInfo = $projectInfo !== null; $query = 'SELECT l.language_id, l.language_name, l.language_colour FROM fm_proglangs AS l'; @@ -57,23 +51,17 @@ class Projects { $stmt = $this->cache->get($query); if($hasProjectInfo) - $stmt->addParameter(1, $projectInfo instanceof ProjectInfo ? $projectInfo->getId() : $projectInfo); + $stmt->addParameter(1, $projectInfo instanceof ProjectInfo ? $projectInfo->id : $projectInfo); $stmt->execute(); - $result = $stmt->getResult(); - $langs = []; - - while($result->next()) - $langs[] = new LanguageInfo($result); - - return $langs; + return $stmt->getResult()->getIterator(LanguageInfo::fromResult(...)); } public function getProjectColour(ProjectInfo|string $projectInfo): Colour { $query = 'SELECT language_colour FROM fm_proglangs WHERE language_id = (SELECT language_id FROM fm_projects_proglangs WHERE project_id = ? ORDER BY priority ASC)'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $projectInfo instanceof ProjectInfo ? $projectInfo->getId() : $projectInfo); + $stmt->addParameter(1, $projectInfo instanceof ProjectInfo ? $projectInfo->id : $projectInfo); $stmt->execute(); $result = $stmt->getResult(); diff --git a/src/RoutingContext.php b/src/RoutingContext.php index 025cf1e..7c10db8 100644 --- a/src/RoutingContext.php +++ b/src/RoutingContext.php @@ -4,17 +4,13 @@ namespace Makai; use Index\Http\Routing\{HttpRouter,Router,RouteHandler}; class RoutingContext { - private HttpRouter $router; + public private(set) HttpRouter $router; public function __construct() { $this->router = new HttpRouter(errorHandler: new RoutingErrorHandler); $this->router->use('/', fn($resp) => $resp->setPoweredBy('Makai')); } - public function getRouter(): Router { - return $this->router; - } - public function register(RouteHandler $handler): void { $this->router->register($handler); } diff --git a/src/SSHKeys/SSHKeyInfo.php b/src/SSHKeys/SSHKeyInfo.php index b5cb851..02ae614 100644 --- a/src/SSHKeys/SSHKeyInfo.php +++ b/src/SSHKeys/SSHKeyInfo.php @@ -1,72 +1,49 @@ id = $result->getString(0); - $this->level = $result->getInteger(1); - $this->algo = $result->getString(2); - $this->body = $result->getString(3); - $this->comment = $result->getString(4); - $this->createdAt = $result->getInteger(5); - $this->deprecatedAt = $result->isNull(6) ? null : $result->getInteger(6); + public static function fromResult(DbResult $result): SSHKeyInfo { + return new SSHKeyInfo( + id: $result->getString(0), + level: $result->getInteger(1), + algo: $result->getString(2), + body: $result->getString(3), + comment: $result->getString(4), + createdTime: $result->getInteger(5), + deprecatedTime: $result->getIntegerOrNull(6), + ); } - public function getId(): string { - return $this->id; + public CarbonImmutable $createdAt { + get => CarbonImmutable::createFromTimestampUTC($this->createdTime); } - public function getLevel(): int { - return $this->level; + public bool $deprecated { + get => $this->deprecatedTime !== null; } - public function getAlgorithm(): string { - return $this->algo; - } - - public function getBody(): string { - return $this->body; - } - - public function getComment(): string { - return $this->comment; - } - - public function getCreatedTime(): int { - return $this->createdAt; - } - - public function getCreatedAt(): CarbonImmutable { - return CarbonImmutable::createFromTimestampUTC($this->createdAt); - } - - public function isDeprecated(): bool { - return $this->deprecatedAt !== null; - } - - public function getDeprecatedTime(): ?int { - return $this->deprecatedAt; - } - - public function getDeprecatedAt(): ?CarbonImmutable { - return $this->deprecatedAt === null ? null : CarbonImmutable::createFromTimestampUTC($this->deprecatedAt); + public ?CarbonImmutable $deprecatedAt { + get => $this->deprecatedTime === null ? null : CarbonImmutable::createFromTimestampUTC($this->deprecatedTime); } public function toString(bool $includeComment): string { - $line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody()); + $line = sprintf('ssh-%s %s', $this->algo, $this->body); if($includeComment) - $line .= sprintf(' %s (%s)', (string)$this->getComment(), $this->getCreatedAt()->format('M Y')); + $line .= sprintf(' %s (%s)', (string)$this->comment, $this->createdAt->format('M Y')); return $line; } diff --git a/src/SSHKeys/SSHKeys.php b/src/SSHKeys/SSHKeys.php index 9933cca..0888286 100644 --- a/src/SSHKeys/SSHKeys.php +++ b/src/SSHKeys/SSHKeys.php @@ -13,7 +13,7 @@ class SSHKeys { public function getKeys( ?int $minLevel = null, ?bool $deprecated = null, - ): array { + ): iterable { $hasMinLevel = $minLevel !== null; $hasDeprecated = $deprecated !== null; @@ -32,12 +32,6 @@ class SSHKeys { $stmt->addParameter(1, $minLevel); $stmt->execute(); - $result = $stmt->getResult(); - $keys = []; - - while($result->next()) - $keys[] = new SSHKeyInfo($result); - - return $keys; + return $stmt->getResult()->getIterator(SSHKeyInfo::fromResult(...)); } } diff --git a/src/SSHKeys/SSHKeysRoutes.php b/src/SSHKeys/SSHKeysRoutes.php index cc94ac2..2ad08f1 100644 --- a/src/SSHKeys/SSHKeysRoutes.php +++ b/src/SSHKeys/SSHKeysRoutes.php @@ -24,12 +24,12 @@ class SSHKeysRoutes implements RouteHandler { foreach($keys as $key) { $items[] = $item = new \stdClass; - $item->algo = $key->getAlgorithm(); - $item->key = $key->getBody(); + $item->algo = $key->algo; + $item->key = $key->body; if($includeComment) { - $item->comment = (string)$key->getComment(); - $item->created = $key->getCreatedAt()->format(DateTimeInterface::ATOM); - $item->level = $key->getLevel(); + $item->comment = (string)$key->comment; + $item->created = $key->createdAt->format(DateTimeInterface::ATOM); + $item->level = $key->level; } } diff --git a/src/SiteInfo.php b/src/SiteInfo.php index 44ae89f..d84398b 100644 --- a/src/SiteInfo.php +++ b/src/SiteInfo.php @@ -2,15 +2,15 @@ namespace Makai; class SiteInfo { - public function getHeaderNavigation(): array { - return [ + public array $headerNavigation { + get => [ ['title' => 'Home', 'url' => '/'], ['title' => 'Projects', 'url' => '/projects'], ]; } - public function getToolsMenu(): array { - return [ + public array $toolsMenu { + get => [ ['icon' => '♪', 'title' => 'Now Listening', 'url' => '//now.flash.moe'], ['icon' => 'A', 'title' => 'ASCII Table', 'url' => '/tools/ascii'], ['icon' => '?', 'title' => 'WHOIS', 'url' => '/tools/whois'], @@ -18,8 +18,8 @@ class SiteInfo { ]; } - public function getHeaderImages(): array { - return [ + public array $headerImages { + get => [ '/images/krk-000.jpg', '/images/krk-001.jpg', '/images/krk-002.jpg', '/images/krk-003.jpg', '/images/krk-004.jpg', '/images/krk-005.jpg', '/images/krk-006.jpg', '/images/krk-007.jpg', '/images/krk-008.jpg', diff --git a/src/Tools/Ascii/AsciiCharacter.php b/src/Tools/Ascii/AsciiCharacter.php index da6f82d..15268d6 100644 --- a/src/Tools/Ascii/AsciiCharacter.php +++ b/src/Tools/Ascii/AsciiCharacter.php @@ -6,38 +6,38 @@ use JsonSerializable; class AsciiCharacter implements JsonSerializable { public function __construct( - private int $char + public private(set) int $char ) { if($char < 0 || $char > 0xFF) throw new InvalidArgumentException('$char must be a single byte'); } - public function getDecimal(): string { - return (string)$this->char; + public string $decimal { + get => (string)$this->char; } - public function getOctal(): string { - return decoct($this->char); + public string $octal { + get => decoct($this->char); } - public function getHex(): string { - return dechex($this->char); + public string $hex { + get => dechex($this->char); } - public function isPrintable(): bool { - return $this->char > 31 + public bool $printable { + get => $this->char > 31 && $this->char < 127; } - public function hasHtml(): bool { - return $this->char === 34 + public bool $hasHtml { + get => $this->char === 34 || $this->char === 38 || $this->char === 60 || $this->char === 62; } - public function getHtml(): string { - return match($this->char) { + public string $html { + get => match($this->char) { 34 => 'quot', 38 => 'amp', 60 => 'lt', @@ -46,8 +46,8 @@ class AsciiCharacter implements JsonSerializable { }; } - public function getString(): string { - return match($this->char) { + public string $string { + get => match($this->char) { 0 => 'NUL', 1 => 'SOH', 2 => 'STX', 3 => 'ETX', 4 => 'EOT', 5 => 'ENQ', 6 => 'ACK', 7 => 'BEL', 8 => 'BS', 9 => 'HT', 10 => 'LF', 11 => 'VT', 12 => 'FF', 13 => 'CR', 14 => 'SO', @@ -59,8 +59,8 @@ class AsciiCharacter implements JsonSerializable { }; } - public function getName(): string { - return match($this->char) { + public string $name { + get => match($this->char) { 0 => 'Null character', 1 => 'Start of heading', 2 => 'Start of text', @@ -203,20 +203,20 @@ class AsciiCharacter implements JsonSerializable { } public function __toString(): string { - return $this->getString(); + return $this->string; } public function jsonSerialize(): mixed { $info = [ - 'dec' => $this->getDecimal(), - 'oct' => $this->getOctal(), - 'hex' => $this->getHex(), - 'string' => $this->getString(), - 'name' => $this->getName(), + 'dec' => $this->decimal, + 'oct' => $this->octal, + 'hex' => $this->hex, + 'string' => $this->string, + 'name' => $this->name, ]; - if($this->hasHtml()) - $info['html'] = $this->getHtml(); + if($this->hasHtml) + $info['html'] = $this->html; return $info; } diff --git a/src/Tools/Whois/WhoisClient.php b/src/Tools/Whois/WhoisClient.php index b442f43..43ff527 100644 --- a/src/Tools/Whois/WhoisClient.php +++ b/src/Tools/Whois/WhoisClient.php @@ -5,17 +5,13 @@ use Exception; use ErrorException; class WhoisClient { - public const ROOT = 'whois.iana.org'; - public const PORT = 43; + public const string ROOT = 'whois.iana.org'; + public const int PORT = 43; public function __construct( - private string $server = self::ROOT + public private(set) string $server = self::ROOT ) {} - public function getServer(): string { - return $this->server; - } - public function query(string $target, int $timeout = 5): WhoisResponse { $sock = @fsockopen($this->server, self::PORT, $errno, $errstr, $timeout); if(!$sock) throw new \RuntimeException('WhoisClient: ' . $errstr); diff --git a/src/Tools/Whois/WhoisResponse.php b/src/Tools/Whois/WhoisResponse.php index 7d959e3..12ddeed 100644 --- a/src/Tools/Whois/WhoisResponse.php +++ b/src/Tools/Whois/WhoisResponse.php @@ -1,24 +1,18 @@ server; - } - - public function getLines(): array { - return $this->lines; - } - - public function getText(): string { - return implode(PHP_EOL, $this->lines); + public string $text { + get => implode(PHP_EOL, $this->lines); } public function findNextWhoisServer(): string { diff --git a/src/Tools/Whois/WhoisResult.php b/src/Tools/Whois/WhoisResult.php index 5a352cd..7014f49 100644 --- a/src/Tools/Whois/WhoisResult.php +++ b/src/Tools/Whois/WhoisResult.php @@ -1,28 +1,18 @@ target; - } - - public function getResponses(): array { - return $this->responses; - } - public function getResponse(int $index): WhoisResponse { return $this->responses[$index]; } - public function getResponseCount(): int { - return count($this->responses); - } - public function jsonSerialize(): mixed { return [ 'target' => $this->target, diff --git a/templates/dev/master.twig b/templates/dev/master.twig index f656a26..3c365c9 100644 --- a/templates/dev/master.twig +++ b/templates/dev/master.twig @@ -6,7 +6,7 @@