diff --git a/src/app/lib/Data.php b/src/app/lib/Data.php index cbf6a33..0e74246 100644 --- a/src/app/lib/Data.php +++ b/src/app/lib/Data.php @@ -14,7 +14,7 @@ class Data /** * Ensure the table and index exist */ - public static function startUp() + public static function startUp(): void { Definition::ensureTable(self::REQ_TABLE); Definition::ensureIndex(self::REQ_TABLE, DocumentIndex::Optimized); diff --git a/src/app/lib/documents/Configuration.php b/src/app/lib/documents/Configuration.php index 01cb0e2..c881936 100644 --- a/src/app/lib/documents/Configuration.php +++ b/src/app/lib/documents/Configuration.php @@ -13,16 +13,16 @@ class Configuration /** @var string $connectionString The connection string to use when establishing a database connection */ public static string $connectionString = ""; - /** @var Connection $pgConn The active connection */ + /** @var ?Connection $pgConn The active connection */ private static ?Connection $pgConn = null; /** @var ?string $startUp The name of a function to run on first connection to the database */ public static ?string $startUp = null; /** - * Ensure that the connection string is set, either explicity, by environment variables, or with defaults + * Ensure that the connection string is set, either explicitly, by environment variables, or with defaults */ - private static function ensureConnectionString() + private static function ensureConnectionString(): void { if (self::$connectionString == "") { $host = $_ENV['PGDOC_HOST'] ?? 'localhost'; @@ -58,7 +58,7 @@ class Configuration /** * Close the PostgreSQL connection if it is open */ - public static function closeConn() + public static function closeConn(): void { if (!is_null(self::$pgConn)) { pg_close(self::$pgConn); diff --git a/src/app/lib/documents/Definition.php b/src/app/lib/documents/Definition.php index ea60f0f..2aa6ee2 100644 --- a/src/app/lib/documents/Definition.php +++ b/src/app/lib/documents/Definition.php @@ -41,9 +41,9 @@ class Definition * * @param string $name The name of the table */ - public static function ensureTable(string $name) + public static function ensureTable(string $name): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query(pg_conn(), self::createTable($name)); if ($result) pg_free_result($result); } @@ -54,9 +54,9 @@ class Definition * @param string $name The name of the table for which the index should be created * @param DocumentIndex $type The type of index to create */ - public static function ensureIndex(string $name, DocumentIndex $type) + public static function ensureIndex(string $name, DocumentIndex $type): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query(pg_conn(), self::createIndex($name, $type)); if ($result) pg_free_result($result); } diff --git a/src/app/lib/documents/Document.php b/src/app/lib/documents/Document.php index 668554b..43cff83 100644 --- a/src/app/lib/documents/Document.php +++ b/src/app/lib/documents/Document.php @@ -50,9 +50,9 @@ class Document * @param string $docId The ID of the document on which action should be taken * @param array|object $document The array or object representing the document */ - private static function executeNonQuery(string $query, string $docId, array|object $document) + private static function executeNonQuery(string $query, string $docId, array|object $document): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $query, [ $docId, Query::jsonbDocParam($document) ]); if ($result) pg_free_result($result); } @@ -64,7 +64,7 @@ class Document * @param string $docId The ID of the document to be inserted * @param array|object $document The array or object representing the document */ - public static function insert(string $tableName, string $docId, array|object $document) + public static function insert(string $tableName, string $docId, array|object $document): void { self::executeNonQuery(Query::insert($tableName), $docId, $document); } @@ -76,7 +76,7 @@ class Document * @param string $docId The ID of the document to be inserted * @param array|object $document The array or object representing the document */ - public static function save(string $tableName, string $docId, array|object $document) + public static function save(string $tableName, string $docId, array|object $document): void { self::executeNonQuery(Query::save($tableName), $docId, $document); } @@ -90,7 +90,7 @@ class Document */ private static function runCount(string $sql, array $params): int { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $sql, $params); if (!$result) return -1; $count = intval(pg_fetch_assoc($result)['it']); @@ -142,9 +142,9 @@ class Document */ private static function runExists(string $sql, array $params): bool { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $sql, $params); - if (!$result) return -1; + if (!$result) return false; $exists = boolval(pg_fetch_assoc($result)['it']); pg_free_result($result); return $exists; @@ -167,7 +167,7 @@ class Document * * @param string $tableName The name of the table in which existence should be checked * @param array|object $criteria The criteria for the JSON containment query - * @return int True if any documents in the table match the JSON containment query, false if not + * @return bool True if any documents in the table match the JSON containment query, false if not */ public static function existsByContains(string $tableName, array|object $criteria): bool { @@ -179,7 +179,7 @@ class Document * * @param string $tableName The name of the table in which existence should be checked * @param string $jsonPath The JSON Path to be matched - * @return int True if any documents in the table match the JSON Path, false if not + * @return bool True if any documents in the table match the JSON Path, false if not */ public static function existsByJsonPath(string $tableName, string $jsonPath): bool { @@ -196,7 +196,7 @@ class Document */ private static function runListQuery(string $sql, array $params, string $className): array { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $sql, $params); try { if (!$result || pg_result_status($result) == PGSQL_EMPTY_QUERY) return []; @@ -294,7 +294,7 @@ class Document * @param string $docId The ID of the document to be updated * @param array|object $document The document to be updated */ - public static function updateFull(string $tableName, string $docId, array|object $document) + public static function updateFull(string $tableName, string $docId, array|object $document): void { self::executeNonQuery(Query::updateFull($tableName), $docId, $document); } @@ -306,7 +306,7 @@ class Document * @param string $docId The ID of the document to be updated * @param array|object $document The partial document to be updated */ - public static function updatePartialById(string $tableName, string $docId, array|object $document) + public static function updatePartialById(string $tableName, string $docId, array|object $document): void { self::executeNonQuery(Query::updatePartialById($tableName), $docId, $document); } @@ -318,9 +318,9 @@ class Document * @param array|object $criteria The JSON containment criteria * @param array|object $document The document to be updated */ - public static function updatePartialByContains(string $tableName, array|object $criteria, array|object $document) + public static function updatePartialByContains(string $tableName, array|object $criteria, array|object $document): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), Query::updatePartialByContains($tableName), [ Query::jsonbDocParam($criteria), Query::jsonbDocParam($document) ]); if ($result) pg_free_result($result); @@ -333,9 +333,9 @@ class Document * @param string $jsonPath The JSON Path to be matched * @param array|object $document The document to be updated */ - public static function updatePartialByJsonPath(string $tableName, string $jsonPath, array|object $document) + public static function updatePartialByJsonPath(string $tableName, string $jsonPath, array|object $document): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), Query::updatePartialByContains($tableName), [ $jsonPath, Query::jsonbDocParam($document) ]); if ($result) pg_free_result($result); @@ -347,7 +347,7 @@ class Document * @param string $tableName The table from which a document should be deleted * @param string $docId The ID of the document to be deleted */ - public static function deleteById(string $tableName, string $docId) + public static function deleteById(string $tableName, string $docId): void { self::executeNonQuery(Query::deleteById($tableName), $docId, []); } @@ -358,9 +358,9 @@ class Document * @param string $tableName The table from which documents should be deleted * @param array|object $criteria The criteria for the JSON containment query */ - public static function deleteByContains(string $tableName, array|object $criteria) + public static function deleteByContains(string $tableName, array|object $criteria): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), Query::deleteByContains($tableName), [ Query::jsonbDocParam($criteria) ]); if ($result) pg_free_result($result); } @@ -371,9 +371,9 @@ class Document * @param string $tableName The table from which documents should be deleted * @param string $jsonPath The JSON Path expression to be matched */ - public static function deleteByJsonPath(string $tableName, string $jsonPath) + public static function deleteByJsonPath(string $tableName, string $jsonPath): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), Query::deleteByJsonPath($tableName), [ $jsonPath ]); if ($result) pg_free_result($result); } @@ -389,7 +389,7 @@ class Document */ public static function customList(string $sql, array $params, string $className, callable $mapFunc): array { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $sql, $params); try { if (!$result || pg_result_status($result) == PGSQL_EMPTY_QUERY) return []; @@ -420,9 +420,9 @@ class Document * @param string $sql The SQL query to execute * @param array $params A positional array of parameters for the SQL query */ - public static function customNonQuery(string $sql, array $params) + public static function customNonQuery(string $sql, array $params): void { - /** @var Result|bool */ + /** @var Result|bool $result */ $result = pg_query_params(pg_conn(), $sql, $params); if ($result) pg_free_result($result); } diff --git a/src/app/lib/domain/History.php b/src/app/lib/domain/History.php index 3e5ceee..137c40a 100644 --- a/src/app/lib/domain/History.php +++ b/src/app/lib/domain/History.php @@ -3,8 +3,6 @@ declare(strict_types=1); namespace MyPrayerJournal\Domain; -use DateTimeImmutable, DateTimeZone; - /** * A record of action taken on a prayer request, including updates to its text */ diff --git a/src/app/lib/domain/JournalRequest.php b/src/app/lib/domain/JournalRequest.php index c758be3..40774e2 100644 --- a/src/app/lib/domain/JournalRequest.php +++ b/src/app/lib/domain/JournalRequest.php @@ -28,7 +28,7 @@ class JournalRequest extends AsOf /** When this request will be shown again after having been snoozed */ public ?DateTimeImmutable $snoozedUntil = null; - /** When this request will be show agains after a non-immediate recurrence */ + /** When this request will be show again after a non-immediate recurrence */ public ?DateTimeImmutable $showAfter = null; /** The type of recurrence for this request */ diff --git a/src/app/lib/domain/Request.php b/src/app/lib/domain/Request.php index 9159ce6..90fd847 100644 --- a/src/app/lib/domain/Request.php +++ b/src/app/lib/domain/Request.php @@ -3,7 +3,7 @@ declare(strict_types=1); namespace MyPrayerJournal\Domain; -use DateTimeImmutable, DateTimeZone; +use DateTimeImmutable; use Visus\Cuid2\Cuid2; /** diff --git a/src/app/lib/start.php b/src/app/lib/start.php index 79f68d7..0ba4b31 100644 --- a/src/app/lib/start.php +++ b/src/app/lib/start.php @@ -39,7 +39,7 @@ Configuration::$startUp = '\MyPrayerJournal\Data::startUp'; /** * Bring in a template */ -function template(string $name) +function template(string $name): void { require_once __DIR__ . "/../templates/$name.php"; } @@ -49,7 +49,7 @@ function template(string $name) * * @param bool $fail Whether to fail the request (true) or redirect to log on (false - optional, default) */ -function require_user(bool $fail = false) +function require_user(bool $fail = false): void { if (!array_key_exists(Constants::USER_ID, $_REQUEST)) { if ($fail) { @@ -64,7 +64,7 @@ function require_user(bool $fail = false) /** * Write a bare header for a component result */ -function bare_header() +function bare_header(): void { echo '