diff --git a/VERSION b/VERSION index 2d66d3d..2d4ead4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2408.12322 +0.2408.12356 diff --git a/src/ArrayIterator.php b/src/ArrayIterator.php index 3416d68..6f4870d 100644 --- a/src/ArrayIterator.php +++ b/src/ArrayIterator.php @@ -1,7 +1,7 @@ array = $array; - } + public function __construct( + private array $array + ) {} /** * Returns the current element. diff --git a/src/CSRFP.php b/src/CSRFP.php index f624af3..f387bd6 100644 --- a/src/CSRFP.php +++ b/src/CSRFP.php @@ -1,7 +1,7 @@ secretKey = $secretKey; - $this->identity = $identity; - $this->tolerance = $tolerance; - } + private string $secretKey, + private string $identity, + private int $tolerance = self::TOLERANCE + ) {} private static function time(int $time = -1): int { return ($time < 0 ? time() : $time) - self::EPOCH; diff --git a/src/Colour/ColourHSL.php b/src/Colour/ColourHSL.php index b3f5bdf..365231f 100644 --- a/src/Colour/ColourHSL.php +++ b/src/Colour/ColourHSL.php @@ -1,7 +1,7 @@ hue = $hue; - $this->saturation = max(0.0, min(1.0, $saturation)); - $this->lightness = max(0.0, min(1.0, $lightness)); - $this->alpha = max(0.0, min(1.0, $alpha)); + public function __construct( + private float $hue, + private float $saturation, + private float $lightness, + private float $alpha = 1.0 + ) { + $saturation = max(0.0, min(1.0, $saturation)); + $lightness = max(0.0, min(1.0, $lightness)); + $alpha = max(0.0, min(1.0, $alpha)); $c = (1 - abs(2 * $lightness - 1)) * $saturation; $x = $c * (1 - abs(fmod($hue / 60, 2) - 1)); diff --git a/src/Colour/ColourNamed.php b/src/Colour/ColourNamed.php index 8efc124..521a830 100644 --- a/src/Colour/ColourNamed.php +++ b/src/Colour/ColourNamed.php @@ -1,7 +1,7 @@ name = strtolower($name); + public function __construct( + private string $name + ) { + $name = strtolower($name); $raw = self::COLOURS[$name] ?? -1; $this->transparent = $raw === -1; diff --git a/src/Colour/ColourRGB.php b/src/Colour/ColourRGB.php index b7ef7fe..c480cac 100644 --- a/src/Colour/ColourRGB.php +++ b/src/Colour/ColourRGB.php @@ -1,7 +1,7 @@ red = max(0, min(255, $red)); - $this->green = max(0, min(255, $green)); - $this->blue = max(0, min(255, $blue)); - $this->alpha = max(0.0, min(1.0, $alpha)); + public function __construct( + private int $red, + private int $green, + private int $blue, + private float $alpha = 1.0 + ) { + $red = max(0, min(255, $red)); + $green = max(0, min(255, $green)); + $blue = max(0, min(255, $blue)); + $alpha = max(0.0, min(1.0, $alpha)); } public function getRed(): int { diff --git a/src/Data/DbStatementCache.php b/src/Data/DbStatementCache.php index 26527da..173190d 100644 --- a/src/Data/DbStatementCache.php +++ b/src/Data/DbStatementCache.php @@ -9,15 +9,14 @@ namespace Index\Data; * Container to avoid having many prepared instances of the same query. */ class DbStatementCache { - private IDbConnection $dbConn; private array $stmts = []; /** * @param IDbConnection $dbConn Connection to use with this cache. */ - public function __construct(IDbConnection $dbConn) { - $this->dbConn = $dbConn; - } + public function __construct( + private IDbConnection $dbConn + ) {} private static function hash(string $query): string { return hash('xxh3', $query, true); diff --git a/src/Data/MariaDB/MariaDBCharacterSetInfo.php b/src/Data/MariaDB/MariaDBCharacterSetInfo.php index 73709b3..369e4f3 100644 --- a/src/Data/MariaDB/MariaDBCharacterSetInfo.php +++ b/src/Data/MariaDB/MariaDBCharacterSetInfo.php @@ -1,7 +1,7 @@ charSet = $charSet; - } + public function __construct( + private stdClass $charSet + ) {} /** * Returns the name of the current character set. diff --git a/src/Data/MariaDB/MariaDBConnectionInfo.php b/src/Data/MariaDB/MariaDBConnectionInfo.php index 75edd6c..2b0e00b 100644 --- a/src/Data/MariaDB/MariaDBConnectionInfo.php +++ b/src/Data/MariaDB/MariaDBConnectionInfo.php @@ -13,20 +13,6 @@ use Index\Net\{EndPoint,DnsEndPoint,IPAddress,IPEndPoint,UnixEndPoint}; * Describes a MariaDB or MySQL connection. */ class MariaDBConnectionInfo implements IDbConnectionInfo { - private EndPoint $endPoint; - private string $userName; - private string $password; - private string $dbName; - private ?string $charSet; - private ?string $initCommand; - private ?string $keyPath; - private ?string $certPath; - private ?string $certAuthPath; - private ?string $trustedCertsPath; - private ?string $cipherAlgos; - private bool $verifyCert; - private bool $useCompression; - /** * Creates an instance of MariaDBConnectionInfo. * @@ -46,37 +32,39 @@ class MariaDBConnectionInfo implements IDbConnectionInfo { * @return MariaDBConnectionInfo A connection info instance representing the given information. */ public function __construct( - EndPoint $endPoint, - string $userName, - string $password, - string $dbName, - string|null $charSet, - string|null $initCommand, - string|null $keyPath, - string|null $certPath, - string|null $certAuthPath, - string|null $trustedCertsPath, - string|null $cipherAlgos, - bool $verifyCert, - bool $useCompression + private EndPoint $endPoint, + private string $userName, + private string $password, + private string $dbName, + private string|null $charSet, + private string|null $initCommand, + private string|null $keyPath, + private string|null $certPath, + private string|null $certAuthPath, + private string|null $trustedCertsPath, + private string|null $cipherAlgos, + private bool $verifyCert, + private bool $useCompression ) { if(!($endPoint instanceof IPEndPoint) && !($endPoint instanceof DnsEndPoint) && !($endPoint instanceof UnixEndPoint)) throw new InvalidArgumentException('$endPoint must be of type IPEndPoint, DnsEndPoint or UnixEndPoint.'); - $this->endPoint = $endPoint; - $this->userName = $userName; - $this->password = $password; - $this->dbName = $dbName; - $this->charSet = empty($charSet) ? null : $charSet; - $this->initCommand = empty($initCommand) ? null : $initCommand; - $this->keyPath = empty($keyPath) ? null : $keyPath; - $this->certPath = empty($certPath) ? null : $certPath; - $this->certAuthPath = empty($certAuthPath) ? null : $certAuthPath; - $this->trustedCertsPath = empty($trustedCertsPath) ? null : $trustedCertsPath; - $this->cipherAlgos = empty($cipherAlgos) ? null : $cipherAlgos; - $this->verifyCert = $verifyCert; - $this->useCompression = $useCompression; + + if(empty($charSet)) + $charSet = null; + if(empty($initCommand)) + $initCommand = null; + if(empty($keyPath)) + $keyPath = null; + if(empty($certPath)) + $certPath = null; + if(empty($certAuthPath)) + $certAuthPath = null; + if(empty($trustedCertsPath)) + $trustedCertsPath = null; + if(empty($cipherAlgos)) + $cipherAlgos = null; } /** diff --git a/src/Data/MariaDB/MariaDBParameter.php b/src/Data/MariaDB/MariaDBParameter.php index 32f769c..3d2abaf 100644 --- a/src/Data/MariaDB/MariaDBParameter.php +++ b/src/Data/MariaDB/MariaDBParameter.php @@ -11,10 +11,6 @@ use Index\Data\{DbTools,DbType}; * Represents a bound parameter. */ class MariaDBParameter { - private int $ordinal; - private int $type; - private mixed $value; - /** * Create a new MariaDBParameter. * @@ -23,14 +19,15 @@ class MariaDBParameter { * @param mixed $value Value to bind. * @return MariaDBParameter A new parameter instance. */ - public function __construct(int $ordinal, int $type, mixed $value) { - $this->ordinal = $ordinal; - + public function __construct( + private int $ordinal, + private int $type, + private mixed $value + ) { if($type == DbType::AUTO) $type = DbTools::detectType($value); - - $this->type = $type; - $this->value = $type === DbType::NULL ? null : $value; + if($type === DbType::NULL) + $value = null; } /** diff --git a/src/Data/MariaDB/MariaDBResult.php b/src/Data/MariaDB/MariaDBResult.php index 5fe8ed8..99abc9f 100644 --- a/src/Data/MariaDB/MariaDBResult.php +++ b/src/Data/MariaDB/MariaDBResult.php @@ -17,7 +17,6 @@ use Index\IO\{Stream,TempFileStream}; abstract class MariaDBResult implements IDbResult { use DbResultTrait; - protected mysqli_stmt|mysqli_result $result; protected array $currentRow = []; /** @@ -26,9 +25,9 @@ abstract class MariaDBResult implements IDbResult { * @param mysqli_stmt|mysqli_result $result A result to work with. * @return MariaDBResult A result instance. */ - public function __construct(mysqli_stmt|mysqli_result $result) { - $this->result = $result; - } + public function __construct( + protected mysqli_stmt|mysqli_result $result + ) {} /** * Gets the number of available rows in this result. diff --git a/src/Data/MariaDB/MariaDBStatement.php b/src/Data/MariaDB/MariaDBStatement.php index 5fd5881..7499b1c 100644 --- a/src/Data/MariaDB/MariaDBStatement.php +++ b/src/Data/MariaDB/MariaDBStatement.php @@ -15,7 +15,6 @@ use Index\IO\Stream; * Represents a MariaDB/MySQL prepared statement. */ class MariaDBStatement implements IDbStatement { - private mysqli_stmt $statement; private array $params = []; /** @@ -24,9 +23,9 @@ class MariaDBStatement implements IDbStatement { * @param mysqli_stmt $statement Underlying statement object. * @return MariaDBStatement A new statement instance. */ - public function __construct(mysqli_stmt $statement) { - $this->statement = $statement; - } + public function __construct( + private mysqli_stmt $statement + ) {} private static bool $constructed = false; private static string $resultImplementation; diff --git a/src/Data/MariaDB/MariaDBWarning.php b/src/Data/MariaDB/MariaDBWarning.php index 0d273a8..a7def43 100644 --- a/src/Data/MariaDB/MariaDBWarning.php +++ b/src/Data/MariaDB/MariaDBWarning.php @@ -1,7 +1,7 @@ message = $message; - $this->sqlState = $sqlState; - $this->code = $code; - } + public function __construct( + private string $message, + private string $sqlState, + private int $code + ) {} /** * Gets the warning message string. diff --git a/src/Data/Migration/FsDbMigrationInfo.php b/src/Data/Migration/FsDbMigrationInfo.php index c8799e4..70219e0 100644 --- a/src/Data/Migration/FsDbMigrationInfo.php +++ b/src/Data/Migration/FsDbMigrationInfo.php @@ -8,15 +8,15 @@ namespace Index\Data\Migration; use Index\Data\IDbConnection; class FsDbMigrationInfo implements IDbMigrationInfo { - private string $path; private string $name; private string $className; /** * @param string $path Filesystem path to the migration file. */ - public function __construct(string $path) { - $this->path = $path; + public function __construct( + private string $path + ) { $this->name = $name = pathinfo($path, PATHINFO_FILENAME); $dateTime = substr($name, 0, 17); diff --git a/src/Data/SQLite/SQLiteConnectionInfo.php b/src/Data/SQLite/SQLiteConnectionInfo.php index f4edb50..72cf4bc 100644 --- a/src/Data/SQLite/SQLiteConnectionInfo.php +++ b/src/Data/SQLite/SQLiteConnectionInfo.php @@ -1,7 +1,7 @@ fileName = $fileName; - $this->encryptionKey = $encryptionKey; - $this->readOnly = $readOnly; - $this->create = $create; - } + private string $fileName, + private string $encryptionKey, + private bool $readOnly, + private bool $create + ) {} /** * Gets the path of the SQLite database. diff --git a/src/Data/SQLite/SQLiteResult.php b/src/Data/SQLite/SQLiteResult.php index 6d2da0f..315764a 100644 --- a/src/Data/SQLite/SQLiteResult.php +++ b/src/Data/SQLite/SQLiteResult.php @@ -16,7 +16,6 @@ use Index\IO\{Stream,TempFileStream}; class SQLiteResult implements IDbResult { use DbResultTrait; - private SQLite3Result $result; private array $currentRow = []; /** @@ -25,9 +24,9 @@ class SQLiteResult implements IDbResult { * @param SQLite3Result $result Raw underlying result class. * @return SQLiteResult A new SQLiteResult instance. */ - public function __construct(SQLite3Result $result) { - $this->result = $result; - } + public function __construct( + private SQLite3Result $result + ) {} /** * Gets the number of columns per row in the result. diff --git a/src/Data/SQLite/SQLiteStatement.php b/src/Data/SQLite/SQLiteStatement.php index 42028e3..2fae29c 100644 --- a/src/Data/SQLite/SQLiteStatement.php +++ b/src/Data/SQLite/SQLiteStatement.php @@ -16,8 +16,6 @@ use Index\IO\Stream; * Represents a prepared SQLite SQL statement. */ class SQLiteStatement implements IDbStatement { - private SQLiteConnection $connection; - private SQLite3Stmt $statement; private ?SQLite3Result $result = null; /** @@ -27,10 +25,10 @@ class SQLiteStatement implements IDbStatement { * @param SQLite3Stmt $statement The raw statement instance. * @return SQLiteStatement A new statement instance. */ - public function __construct(SQLiteConnection $connection, SQLite3Stmt $statement) { - $this->connection = $connection; - $this->statement = $statement; - } + public function __construct( + private SQLiteConnection $connection, + private SQLite3Stmt $statement + ) {} public function getParameterCount(): int { return $this->statement->paramCount(); diff --git a/src/Http/Content/BencodedContent.php b/src/Http/Content/BencodedContent.php index 8ed56e4..d4eee23 100644 --- a/src/Http/Content/BencodedContent.php +++ b/src/Http/Content/BencodedContent.php @@ -12,14 +12,12 @@ use Index\IO\{Stream,FileStream}; * Represents Bencoded body content for a HTTP message. */ class BencodedContent implements IHttpContent, IBencodeSerialisable { - private mixed $content; - /** * @param mixed $content Content to be bencoded. */ - public function __construct(mixed $content) { - $this->content = $content; - } + public function __construct( + private mixed $content + ) {} /** * Retrieves unencoded content. diff --git a/src/Http/Content/FormContent.php b/src/Http/Content/FormContent.php index b9d715e..ce8e906 100644 --- a/src/Http/Content/FormContent.php +++ b/src/Http/Content/FormContent.php @@ -12,17 +12,14 @@ use Index\Http\HttpUploadedFile; * Represents form body content for a HTTP message. */ class FormContent implements IHttpContent { - private array $postFields; - private array $uploadedFiles; - /** * @param array $postFields Form fields. * @param array $uploadedFiles Uploaded files. */ - public function __construct(array $postFields, array $uploadedFiles) { - $this->postFields = $postFields; - $this->uploadedFiles = $uploadedFiles; - } + public function __construct( + private array $postFields, + private array $uploadedFiles + ) {} /** * Retrieves a form field with filtering. diff --git a/src/Http/Content/JsonContent.php b/src/Http/Content/JsonContent.php index dbe5931..6e0db07 100644 --- a/src/Http/Content/JsonContent.php +++ b/src/Http/Content/JsonContent.php @@ -12,14 +12,12 @@ use Index\IO\{Stream,FileStream}; * Represents JSON body content for a HTTP message. */ class JsonContent implements IHttpContent, JsonSerializable { - private mixed $content; - /** * @param mixed $content Content to be JSON encoded. */ - public function __construct(mixed $content) { - $this->content = $content; - } + public function __construct( + private mixed $content + ) {} /** * Retrieves unencoded content. diff --git a/src/Http/Content/StreamContent.php b/src/Http/Content/StreamContent.php index ee65821..d410969 100644 --- a/src/Http/Content/StreamContent.php +++ b/src/Http/Content/StreamContent.php @@ -11,14 +11,12 @@ use Index\IO\{Stream,FileStream}; * Represents Stream body content for a HTTP message. */ class StreamContent implements IHttpContent { - private Stream $stream; - /** * @param Stream $stream Stream that represents this message body. */ - public function __construct(Stream $stream) { - $this->stream = $stream; - } + public function __construct( + private Stream $stream + ) {} /** * Retrieves the underlying stream. diff --git a/src/Http/Content/StringContent.php b/src/Http/Content/StringContent.php index a95bcbe..24cba80 100644 --- a/src/Http/Content/StringContent.php +++ b/src/Http/Content/StringContent.php @@ -11,14 +11,12 @@ use Stringable; * Represents string body content for a HTTP message. */ class StringContent implements IHttpContent { - private string $string; - /** * @param string $string String that represents this message body. */ - public function __construct(string $string) { - $this->string = $string; - } + public function __construct( + private string $string + ) {} /** * Retrieves the underlying string. diff --git a/src/Http/HttpHeader.php b/src/Http/HttpHeader.php index 5cef3ca..74357a4 100644 --- a/src/Http/HttpHeader.php +++ b/src/Http/HttpHeader.php @@ -11,15 +11,16 @@ use Stringable; * Represents a generic HTTP header. */ class HttpHeader implements Stringable { - private string $name; private array $lines; /** * @param string $name Name of the header. * @param string ...$lines Lines of the header. */ - public function __construct(string $name, string ...$lines) { - $this->name = $name; + public function __construct( + private string $name, + string ...$lines + ) { $this->lines = $lines; } diff --git a/src/Http/HttpHeaders.php b/src/Http/HttpHeaders.php index e45d1cc..0962db0 100644 --- a/src/Http/HttpHeaders.php +++ b/src/Http/HttpHeaders.php @@ -11,12 +11,12 @@ use RuntimeException; * Represents a collection of HTTP headers. */ class HttpHeaders { - private array $headers; - /** * @param HttpHeader[] $headers HTTP header instances. */ - public function __construct(array $headers) { + public function __construct( + private array $headers + ) { $real = []; foreach($headers as $header) diff --git a/src/Http/HttpMessage.php b/src/Http/HttpMessage.php index 7e67564..b129a4b 100644 --- a/src/Http/HttpMessage.php +++ b/src/Http/HttpMessage.php @@ -13,20 +13,16 @@ use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,Str * Represents a base HTTP message. */ abstract class HttpMessage { - private string $version; - private HttpHeaders $headers; - private ?IHttpContent $content; - /** * @param string $version HTTP message version. * @param HttpHeaders $headers HTTP message headers. * @param ?IHttpContent $content Body contents. */ - public function __construct(string $version, HttpHeaders $headers, ?IHttpContent $content) { - $this->version = $version; - $this->headers = $headers; - $this->content = $content; - } + public function __construct( + private string $version, + private HttpHeaders $headers, + private ?IHttpContent $content + ) {} /** * Retrieves the HTTP version of this message. diff --git a/src/Http/HttpRequest.php b/src/Http/HttpRequest.php index f2a256a..4c1633a 100644 --- a/src/Http/HttpRequest.php +++ b/src/Http/HttpRequest.php @@ -14,11 +14,6 @@ use Index\Http\Content\{IHttpContent,JsonContent,StreamContent,FormContent}; * Represents a HTTP request message. */ class HttpRequest extends HttpMessage { - private string $method; - private string $path; - private array $params; - private array $cookies; - /** * @param string $version HTTP message version. * @param string $method HTTP request method. @@ -30,18 +25,13 @@ class HttpRequest extends HttpMessage { */ public function __construct( string $version, - string $method, - string $path, - array $params, - array $cookies, + private string $method, + private string $path, + private array $params, + private array $cookies, HttpHeaders $headers, ?IHttpContent $content ) { - $this->method = $method; - $this->path = $path; - $this->params = $params; - $this->cookies = $cookies; - parent::__construct($version, $headers, $content); } @@ -93,7 +83,7 @@ class HttpRequest extends HttpMessage { public function getParam(string $name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed { if(!isset($this->params[$name])) return null; - return filter_var($this->params[$name] ?? null, $filter, $options); + return filter_var($this->params[$name], $filter, $options); } /** @@ -126,7 +116,7 @@ class HttpRequest extends HttpMessage { public function getCookie(string $name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed { if(!isset($this->cookies[$name])) return null; - return filter_var($this->cookies[$name] ?? null, $filter, $options); + return filter_var($this->cookies[$name], $filter, $options); } /** diff --git a/src/Http/HttpResponse.php b/src/Http/HttpResponse.php index c078468..aa0e569 100644 --- a/src/Http/HttpResponse.php +++ b/src/Http/HttpResponse.php @@ -11,9 +11,6 @@ use Index\Http\Content\IHttpContent; * Represents a HTTP response message. */ class HttpResponse extends HttpMessage { - private int $statusCode; - private string $statusText; - /** * @param string $version HTTP message version. * @param int $statusCode HTTP response status code. @@ -23,14 +20,11 @@ class HttpResponse extends HttpMessage { */ public function __construct( string $version, - int $statusCode, - string $statusText, + private int $statusCode, + private string $statusText, HttpHeaders $headers, ?IHttpContent $content ) { - $this->statusCode = $statusCode; - $this->statusText = $statusText; - parent::__construct($version, $headers, $content); } diff --git a/src/Http/HttpUploadedFile.php b/src/Http/HttpUploadedFile.php index 0bec5db..4a7b367 100644 --- a/src/Http/HttpUploadedFile.php +++ b/src/Http/HttpUploadedFile.php @@ -14,11 +14,6 @@ use Index\IO\{Stream,FileStream}; * Represents an uploaded file in a multipart/form-data request. */ class HttpUploadedFile implements ICloseable { - private int $errorCode; - private int $size; - private string $localFileName; - private string $suggestedFileName; - private MediaType $suggestedMediaType; private bool $hasMoved = false; private ?Stream $stream = null; @@ -30,20 +25,14 @@ class HttpUploadedFile implements ICloseable { * @param MediaType|string $suggestedMediaType Mediatype included by the client. */ public function __construct( - int $errorCode, - int $size, - string $localFileName, - string $suggestedFileName, - MediaType|string $suggestedMediaType + private int $errorCode, + private int $size, + private string $localFileName, + private string $suggestedFileName, + private MediaType|string $suggestedMediaType ) { if(!($suggestedMediaType instanceof MediaType)) $suggestedMediaType = MediaType::parse($suggestedMediaType); - - $this->errorCode = $errorCode; - $this->size = $size; - $this->localFileName = $localFileName; - $this->suggestedFileName = $suggestedFileName; - $this->suggestedMediaType = $suggestedMediaType; } /** diff --git a/src/Http/Routing/HandlerAttribute.php b/src/Http/Routing/HandlerAttribute.php index d7f758c..194ce09 100644 --- a/src/Http/Routing/HandlerAttribute.php +++ b/src/Http/Routing/HandlerAttribute.php @@ -1,7 +1,7 @@ method = $method; } /** diff --git a/src/Http/Routing/HttpRouter.php b/src/Http/Routing/HttpRouter.php index a831411..834eda5 100644 --- a/src/Http/Routing/HttpRouter.php +++ b/src/Http/Routing/HttpRouter.php @@ -22,8 +22,6 @@ class HttpRouter implements IRouter { private array $contentHandlers = []; - private string $defaultCharSet; - private IErrorHandler $errorHandler; /** @@ -32,11 +30,10 @@ class HttpRouter implements IRouter { * @param bool $registerDefaultContentHandlers true to register default content handlers for JSON, Bencode, etc. */ public function __construct( - string $charSet = '', + private string $charSet = '', IErrorHandler|string $errorHandler = 'html', bool $registerDefaultContentHandlers = true, ) { - $this->defaultCharSet = $charSet; $this->setErrorHandler($errorHandler); if($registerDefaultContentHandlers) @@ -49,9 +46,9 @@ class HttpRouter implements IRouter { * @return string Normalised character set name. */ public function getCharSet(): string { - if($this->defaultCharSet === '') + if($this->charSet === '') return strtolower(mb_preferred_mime_name(mb_internal_encoding())); - return $this->defaultCharSet; + return $this->charSet; } /** diff --git a/src/Http/Routing/ScopedRouter.php b/src/Http/Routing/ScopedRouter.php index 96aa166..b3ca5b6 100644 --- a/src/Http/Routing/ScopedRouter.php +++ b/src/Http/Routing/ScopedRouter.php @@ -11,20 +11,18 @@ namespace Index\Http\Routing; class ScopedRouter implements IRouter { use RouterTrait; - private IRouter $router; - private string $prefix; - /** * @param IRouter $router Underlying router. * @param string $prefix Base path to use as a prefix. */ - public function __construct(IRouter $router, string $prefix) { + public function __construct( + private IRouter $router, + private string $prefix + ) { if($router instanceof ScopedRouter) $router = $router->getParentRouter(); - $this->router = $router; - // todo: cleanup - $this->prefix = $prefix; + // TODO: cleanup prefix } private function getParentRouter(): IRouter { diff --git a/src/IO/FileStream.php b/src/IO/FileStream.php index a543684..02a0964 100644 --- a/src/IO/FileStream.php +++ b/src/IO/FileStream.php @@ -110,17 +110,17 @@ class FileStream extends GenericStream { */ public const LOCK_NON_BLOCKING = LOCK_NB; - private int $lock; - /** * @param string $path Path to the file. * @param string $mode Stream mode to use to open the file. * @param int $lock Locking method to use. * @throws RuntimeException If the file could not be opened. */ - public function __construct(string $path, string $mode, int $lock) { - $this->lock = $lock; - + public function __construct( + string $path, + string $mode, + private int $lock + ) { try { $stream = fopen($path, $mode); } catch(ErrorException $ex) { diff --git a/src/IO/GenericStream.php b/src/IO/GenericStream.php index c37bcd7..6368d92 100644 --- a/src/IO/GenericStream.php +++ b/src/IO/GenericStream.php @@ -32,7 +32,9 @@ class GenericStream extends Stream { 'x+', 'x+b', 'c', 'cb', 'c+', 'c+b', ]; - protected $stream; // resource + // resource + // can't seem to turn this one into a constructor property thing? + protected $stream; private bool $canRead; private bool $canWrite; diff --git a/src/MediaType.php b/src/MediaType.php index b04aaa5..e9c752f 100644 --- a/src/MediaType.php +++ b/src/MediaType.php @@ -12,17 +12,12 @@ use Stringable; * Implements a structure for representing and comparing media/mime types. */ class MediaType implements Stringable, IComparable, IEquatable { - private string $category = ''; - private string $kind = ''; - private string $suffix = ''; - private array $params = []; - - public function __construct(string $category, string $kind, string $suffix, array $params) { - $this->category = $category; - $this->kind = $kind; - $this->suffix = $suffix; - $this->params = $params; - } + public function __construct( + private string $category, + private string $kind, + private string $suffix, + private array $params + ) {} public function getCategory(): string { return $this->category; diff --git a/src/Net/DnsEndPoint.php b/src/Net/DnsEndPoint.php index 781e338..c544c0a 100644 --- a/src/Net/DnsEndPoint.php +++ b/src/Net/DnsEndPoint.php @@ -11,19 +11,17 @@ use InvalidArgumentException; * A DNS end point. */ class DnsEndPoint extends EndPoint { - private string $host; - private int $port; - /** * @param string $host DNS host name. * @param int $port Network port, 0 to leave default. * @throws InvalidArgumentException If $port is less than 0 or greater than 65535. */ - public function __construct(string $host, int $port) { + public function __construct( + private string $host, + private int $port + ) { if($port < 0 || $port > 0xFFFF) throw new InvalidArgumentException('$port is not a valid port number.'); - $this->host = $host; - $this->port = $port; } /** diff --git a/src/Net/IPAddress.php b/src/Net/IPAddress.php index 69df3df..fc554c5 100644 --- a/src/Net/IPAddress.php +++ b/src/Net/IPAddress.php @@ -35,14 +35,14 @@ final class IPAddress implements JsonSerializable, Stringable, IEquatable { */ public const V6 = 6; - private string $raw; private int $width; /** * @param string $raw Raw IP address data. */ - public function __construct(string $raw) { - $this->raw = $raw; + public function __construct( + private string $raw + ) { $this->width = strlen($raw); } diff --git a/src/Net/IPAddressRange.php b/src/Net/IPAddressRange.php index 83b948b..04b2b33 100644 --- a/src/Net/IPAddressRange.php +++ b/src/Net/IPAddressRange.php @@ -14,17 +14,14 @@ use Index\IEquatable; * Represents a CIDR range of IP addresses. */ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable { - private IPAddress $base; - private int $mask; - /** * @param IPAddress $base Base IP address. * @param int $mask CIDR mask. */ - public function __construct(IPAddress $base, int $mask) { - $this->base = $base; - $this->mask = $mask; - } + public function __construct( + private IPAddress $base, + private int $mask + ) {} /** * Retrieves the base IP address. diff --git a/src/Net/IPEndPoint.php b/src/Net/IPEndPoint.php index 504895c..04c5055 100644 --- a/src/Net/IPEndPoint.php +++ b/src/Net/IPEndPoint.php @@ -12,19 +12,17 @@ use Index\XString; * Represents an IP address end point. */ class IPEndPoint extends EndPoint { - private IPAddress $address; - private int $port; - /** * @param IPAddress $address IP address. * @param int $port Network port, 0 to leave default. * @throws InvalidArgumentException If $port is less than 0 or greater than 65535. */ - public function __construct(IPAddress $address, int $port) { + public function __construct( + private IPAddress $address, + private int $port + ) { if($port < 0 || $port > 0xFFFF) throw new InvalidArgumentException('$port is not a valid port number.'); - $this->address = $address; - $this->port = $port; } /** diff --git a/src/Net/UnixEndPoint.php b/src/Net/UnixEndPoint.php index b9ab7b6..463e701 100644 --- a/src/Net/UnixEndPoint.php +++ b/src/Net/UnixEndPoint.php @@ -9,14 +9,12 @@ namespace Index\Net; * Represents a UNIX socket path end point. */ class UnixEndPoint extends EndPoint { - private string $path; - /** * @param string $socketPath Path to the socket file. */ - public function __construct(string $socketPath) { - $this->path = $socketPath; - } + public function __construct( + private string $socketPath + ) {} /** * Gets path to the socket file. @@ -24,20 +22,20 @@ class UnixEndPoint extends EndPoint { * @return string Path to the socket file. */ public function getPath(): string { - return $this->path; + return $this->socketPath; } public function __serialize(): array { - return [$this->path]; + return [$this->socketPath]; } public function __unserialize(array $serialized): void { - $this->path = $serialized[0]; + $this->socketPath = $serialized[0]; } public function equals(mixed $other): bool { return $other instanceof UnixEndPoint - && $this->path === $other->path; + && $this->socketPath === $other->socketPath; } /** @@ -56,6 +54,6 @@ class UnixEndPoint extends EndPoint { } public function __toString(): string { - return $this->path; + return $this->socketPath; } } diff --git a/src/Performance/TimingPoint.php b/src/Performance/TimingPoint.php index f6acdeb..8a97854 100644 --- a/src/Performance/TimingPoint.php +++ b/src/Performance/TimingPoint.php @@ -9,11 +9,6 @@ namespace Index\Performance; * Represents a timing point. */ class TimingPoint { - private int $timePoint; - private int $duration; - private string $name; - private string $comment; - /** * @param int $timePoint Starting tick count. * @param int $duration Duration ticks count. @@ -21,16 +16,11 @@ class TimingPoint { * @param string $comment Timing point comment. */ public function __construct( - int $timePoint, - int $duration, - string $name, - string $comment - ) { - $this->timePoint = $timePoint; - $this->duration = $duration; - $this->name = $name; - $this->comment = $comment; - } + private int $timePoint, + private int $duration, + private string $name, + private string $comment + ) {} /** * Gets the starting ticks count.