diff --git a/composer.json b/composer.json index 14997fc..cce2a54 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "support": { "email": "daniel@bitbadger.solutions", "source": "https://git.bitbadger.solutions/bit-badger/pdo-document", - "rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss" + "rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss", + "docs": "https://bitbadger.solutions/open-source/pdo-document/" }, "require": { "php": ">=8.2", diff --git a/composer.lock b/composer.lock index 0c455af..4ae6774 100644 --- a/composer.lock +++ b/composer.lock @@ -59,16 +59,16 @@ }, { "name": "phpoption/phpoption", - "version": "1.9.2", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", - "reference": "80735db690fe4fc5c76dfa7f9b770634285fa820" + "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/80735db690fe4fc5c76dfa7f9b770634285fa820", - "reference": "80735db690fe4fc5c76dfa7f9b770634285fa820", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/e3fac8b24f56113f7cb96af14958c0dd16330f54", + "reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54", "shasum": "" }, "require": { @@ -76,13 +76,13 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2" + "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28" }, "type": "library", "extra": { "bamarni-bin": { "bin-links": true, - "forward-command": true + "forward-command": false }, "branch-alias": { "dev-master": "1.9-dev" @@ -118,7 +118,7 @@ ], "support": { "issues": "https://github.com/schmittjoh/php-option/issues", - "source": "https://github.com/schmittjoh/php-option/tree/1.9.2" + "source": "https://github.com/schmittjoh/php-option/tree/1.9.3" }, "funding": [ { @@ -130,7 +130,7 @@ "type": "tidelift" } ], - "time": "2023-11-12T21:59:55+00:00" + "time": "2024-07-20T21:41:07+00:00" } ], "packages-dev": [ @@ -695,16 +695,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.2.7", + "version": "11.2.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "15c7e69dec4a8f246840859e6b430bd2abeb5039" + "reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/15c7e69dec4a8f246840859e6b430bd2abeb5039", - "reference": "15c7e69dec4a8f246840859e6b430bd2abeb5039", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7a29e8d3113806f18f99d670f580a30e8ffff39", + "reference": "a7a29e8d3113806f18f99d670f580a30e8ffff39", "shasum": "" }, "require": { @@ -775,7 +775,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.7" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.8" }, "funding": [ { @@ -791,7 +791,7 @@ "type": "tidelift" } ], - "time": "2024-07-10T11:50:09+00:00" + "time": "2024-07-18T14:56:37+00:00" }, { "name": "sebastian/cli-parser", diff --git a/src/Configuration.php b/src/Configuration.php index ddd1b8c..74ad318 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -38,13 +38,13 @@ class Configuration public static ?array $options = null; /** @var Option The mode in which the library is operating */ - public static Option $_mode; + public static Option $mode; /** @var Option The data source name (DSN) of the connection string */ - private static Option $_pdoDSN; + private static Option $pdoDSN; /** @var PDO|null The PDO instance to use for database commands */ - private static ?PDO $_pdo = null; + private static ?PDO $pdo = null; /** * Use a Data Source Name (DSN) @@ -55,10 +55,10 @@ class Configuration public static function useDSN(string $dsn): void { if (empty($dsn)) { - self::$_mode = self::$_pdoDSN = None::create(); + self::$mode = self::$pdoDSN = None::create(); } else { - self::$_mode = Some::create(Mode::deriveFromDSN($dsn)); - self::$_pdoDSN = Some::create($dsn); + self::$mode = Some::create(Mode::deriveFromDSN($dsn)); + self::$pdoDSN = Some::create($dsn); } } @@ -70,14 +70,14 @@ class Configuration */ public static function dbConn(): PDO { - if (is_null(self::$_pdo)) { - $dsn = (self::$_pdoDSN ?? None::create())->getOrThrow( + if (is_null(self::$pdo)) { + $dsn = (self::$pdoDSN ?? None::create())->getOrThrow( new DocumentException('Please provide a data source name (DSN) before attempting data access')); - self::$_pdo = new PDO($dsn, $_ENV['PDO_DOC_USERNAME'] ?? self::$username, + self::$pdo = new PDO($dsn, $_ENV['PDO_DOC_USERNAME'] ?? self::$username, $_ENV['PDO_DOC_PASSWORD'] ?? self::$password, self::$options); } - return self::$_pdo; + return self::$pdo; } /** @@ -88,7 +88,7 @@ class Configuration */ public static function mode(?string $process = null): Mode { - return self::$_mode->getOrThrow( + return self::$mode->getOrThrow( new DocumentException('Database mode not set' . (is_null($process) ? '' : "; cannot $process"))); } @@ -99,7 +99,7 @@ class Configuration */ public static function overrideMode(?Mode $mode): void { - self::$_mode = Option::fromValue($mode); + self::$mode = Option::fromValue($mode); } /** @@ -107,6 +107,6 @@ class Configuration */ public static function resetPDO(): void { - self::$_pdo = null; + self::$pdo = null; } } diff --git a/src/Custom.php b/src/Custom.php index 2e25862..572fcb0 100644 --- a/src/Custom.php +++ b/src/Custom.php @@ -45,7 +45,7 @@ class Custom is_bool($value) => PDO::PARAM_BOOL, is_int($value) => PDO::PARAM_INT, is_null($value) => PDO::PARAM_NULL, - default => PDO::PARAM_STR + default => PDO::PARAM_STR, }; $stmt->bindValue($key, $value, $dataType); } diff --git a/src/DocumentList.php b/src/DocumentList.php index 2fcb95c..f4ca6f9 100644 --- a/src/DocumentList.php +++ b/src/DocumentList.php @@ -21,8 +21,8 @@ use PDOStatement; */ class DocumentList { - /** @var TDoc|null $_first The first item from the results */ - private mixed $_first = null; + /** @var TDoc|null $first The first item from the results */ + private mixed $first = null; /** * Constructor @@ -33,7 +33,7 @@ class DocumentList private function __construct(private ?PDOStatement &$result, private readonly Mapper $mapper) { if ($row = $this->result->fetch(PDO::FETCH_ASSOC)) { - $this->_first = $this->mapper->map($row); + $this->first = $this->mapper->map($row); } else { $this->result = null; } @@ -62,7 +62,7 @@ class DocumentList public function items(): Generator { if (!$this->result) return; - yield $this->_first; + yield $this->first; while ($row = $this->result->fetch(PDO::FETCH_ASSOC)) { yield $this->mapper->map($row); } diff --git a/src/Field.php b/src/Field.php index 985bd8e..b8accb2 100644 --- a/src/Field.php +++ b/src/Field.php @@ -64,20 +64,20 @@ class Field $fieldName = (empty($this->qualifier) ? '' : "$this->qualifier.") . 'data' . match (true) { !str_contains($this->fieldName, '.') => "->>'$this->fieldName'", $mode === Mode::PgSQL => "#>>'{" . implode(',', explode('.', $this->fieldName)) . "}'", - $mode === Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'" + $mode === Mode::SQLite => "->>'" . implode("'->>'", explode('.', $this->fieldName)) . "'", }; $fieldPath = match ($mode) { Mode::PgSQL => match (true) { $this->op === Op::BT => is_numeric($this->value[0]) ? "($fieldName)::numeric" : $fieldName, is_numeric($this->value) => "($fieldName)::numeric", - default => $fieldName + default => $fieldName, }, - default => $fieldName + default => $fieldName, }; $criteria = match ($this->op) { Op::EX, Op::NEX => '', Op::BT => " {$this->paramName}min AND {$this->paramName}max", - default => " $this->paramName" + default => " $this->paramName", }; return $fieldPath . ' ' . $this->op->toSQL() . $criteria; } diff --git a/src/FieldMatch.php b/src/FieldMatch.php index 9658508..ab87dda 100644 --- a/src/FieldMatch.php +++ b/src/FieldMatch.php @@ -28,7 +28,7 @@ enum FieldMatch { return match ($this) { FieldMatch::All => 'AND', - FieldMatch::Any => 'OR' + FieldMatch::Any => 'OR', }; } } diff --git a/src/Mapper/DocumentMapper.php b/src/Mapper/DocumentMapper.php index 70a2f16..9bf4859 100644 --- a/src/Mapper/DocumentMapper.php +++ b/src/Mapper/DocumentMapper.php @@ -26,7 +26,7 @@ class DocumentMapper implements Mapper * @param class-string $className The type of class to be returned by this mapping * @param string $fieldName The name of the field (optional; defaults to `data`) */ - public function __construct(public string $className, public string $fieldName = 'data') { } + public function __construct(public string $className, public string $fieldName = 'data') {} /** * Map a result to a domain class instance diff --git a/src/Mapper/ExistsMapper.php b/src/Mapper/ExistsMapper.php index 2a3f63c..56f6a26 100644 --- a/src/Mapper/ExistsMapper.php +++ b/src/Mapper/ExistsMapper.php @@ -24,7 +24,7 @@ class ExistsMapper implements Mapper { return match (Configuration::mode('map existence result')) { Mode::PgSQL => (bool)$result[0], - Mode::SQLite => (int)$result[0] > 0 + Mode::SQLite => (int)$result[0] > 0, }; } } diff --git a/src/Mapper/StringMapper.php b/src/Mapper/StringMapper.php index 60ffbd2..c8e1194 100644 --- a/src/Mapper/StringMapper.php +++ b/src/Mapper/StringMapper.php @@ -30,7 +30,7 @@ class StringMapper implements Mapper return match (false) { key_exists($this->fieldName, $result) => null, is_string($result[$this->fieldName]) => "{$result[$this->fieldName]}", - default => $result[$this->fieldName] + default => $result[$this->fieldName], }; } } diff --git a/src/Mode.php b/src/Mode.php index ded0ec6..bb19cbe 100644 --- a/src/Mode.php +++ b/src/Mode.php @@ -30,7 +30,7 @@ enum Mode return match (true) { str_starts_with($dsn, 'pgsql:') => Mode::PgSQL, str_starts_with($dsn, 'sqlite:') => Mode::SQLite, - default => throw new DocumentException('This library currently supports PostgreSQL and SQLite') + default => throw new DocumentException('This library currently supports PostgreSQL and SQLite'), }; } } diff --git a/src/Op.php b/src/Op.php index 6950dbb..1da71ae 100644 --- a/src/Op.php +++ b/src/Op.php @@ -48,7 +48,7 @@ enum Op Op::NE => "<>", Op::BT => "BETWEEN", Op::EX => "IS NOT NULL", - Op::NEX => "IS NULL" + Op::NEX => "IS NULL", }; } } diff --git a/src/Query.php b/src/Query.php index 15d19af..f6be31f 100644 --- a/src/Query.php +++ b/src/Query.php @@ -102,7 +102,7 @@ class Query AutoId::Number => "json_set(:data, '$.$id', " . "(SELECT coalesce(max(data->>'$id'), 0) + 1 FROM $tableName))", AutoId::UUID => "json_set(:data, '$.$id', '" . AutoId::generateUUID() . "')", - AutoId::RandomString => "json_set(:data, '$.$id', '" . AutoId::generateRandom() ."')" + AutoId::RandomString => "json_set(:data, '$.$id', '" . AutoId::generateRandom() ."')", }, Mode::PgSQL => match ($autoId ?? AutoId::None) { AutoId::None => ':data', diff --git a/src/Query/Definition.php b/src/Query/Definition.php index e6ef53b..1f1f953 100644 --- a/src/Query/Definition.php +++ b/src/Query/Definition.php @@ -27,7 +27,7 @@ class Definition { $dataType = match (Configuration::mode('make create table statement')) { Mode::PgSQL => 'JSONB', - Mode::SQLite => 'TEXT' + Mode::SQLite => 'TEXT', }; return "CREATE TABLE IF NOT EXISTS $name (data $dataType NOT NULL)"; } @@ -91,7 +91,7 @@ class Definition [, $tbl] = self::splitSchemaAndTable($tableName); $extraOps = match ($indexType) { DocumentIndex::Full => '', - DocumentIndex::Optimized => ' jsonb_path_ops' + DocumentIndex::Optimized => ' jsonb_path_ops', }; return "CREATE INDEX IF NOT EXISTS idx_{$tbl}_document ON $tableName USING GIN (data$extraOps)"; } diff --git a/src/Query/Patch.php b/src/Query/Patch.php index 6aa15ca..dbac59d 100644 --- a/src/Query/Patch.php +++ b/src/Query/Patch.php @@ -28,7 +28,7 @@ class Patch { $setValue = match (Configuration::mode('make patch statement')) { Mode::PgSQL => 'data || :data', - Mode::SQLite => 'json_patch(data, json(:data))' + Mode::SQLite => 'json_patch(data, json(:data))', }; return "UPDATE $tableName SET data = $setValue WHERE $whereClause"; } diff --git a/src/Query/RemoveFields.php b/src/Query/RemoveFields.php index 04935c8..16bded7 100644 --- a/src/Query/RemoveFields.php +++ b/src/Query/RemoveFields.php @@ -35,7 +35,7 @@ class RemoveFields Mode::PgSQL => "UPDATE $tableName SET data = data - " . array_keys($parameters)[0] . "::text[] WHERE $whereClause", Mode::SQLite => "UPDATE $tableName SET data = json_remove(data, " . implode(', ', array_keys($parameters)) - . ") WHERE $whereClause" + . ") WHERE $whereClause", }; }