diff --git a/src/Db.php b/src/Db.php index f765f5a..2538ab8 100644 --- a/src/Db.php +++ b/src/Db.php @@ -6,6 +6,7 @@ use PDO; use PDOStatement; +use stdClass; use function array_map; use function is_array; @@ -15,11 +16,11 @@ final class Db { - protected Sql $currentSql; + private Sql $currentSql; - protected Sql $protoSql; + private readonly Sql $protoSql; - public function __construct(protected readonly PDO $connection, Sql|null $sqlPrototype = null) + public function __construct(public readonly PDO $connection, Sql|null $sqlPrototype = null) { $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->protoSql = $sqlPrototype ?: new Sql(); @@ -31,38 +32,49 @@ public function exec(): bool return (bool) $this->executeStatement(); } - public function fetch(mixed $object = '\stdClass', mixed $extra = null): mixed + /** + * @param int|string|array|callable|object $object + * @param array|null $extra + */ + public function fetch(int|string|array|callable|object $object = stdClass::class, array|null $extra = null): mixed { $result = $this->performFetch(__FUNCTION__, $object, $extra); return is_callable($object) ? $object($result) : $result; } - public function fetchAll(mixed $object = '\stdClass', mixed $extra = null): mixed - { + /** + * @param int|string|array|callable|object $object + * @param array|null $extra + */ + public function fetchAll( + int|string|array|callable|object $object = stdClass::class, + array|null $extra = null, + ): mixed { $result = $this->performFetch(__FUNCTION__, $object, $extra); return is_callable($object) ? array_map($object, $result) : $result; } - public function getConnection(): PDO - { - return $this->connection; - } - public function getSql(): Sql { return $this->currentSql; } - /** @param array|null $extra */ - public function prepare(string $queryString, mixed $object = '\stdClass', array|null $extra = null): PDOStatement - { + /** + * @param int|string|array|callable|object $object + * @param array|null $extra + */ + public function prepare( + string $queryString, + int|string|array|callable|object $object = stdClass::class, + array|null $extra = null, + ): PDOStatement { $statement = $this->connection->prepare($queryString); match (true) { is_int($object) => $statement->setFetchMode($object), - $object === '\stdClass' || $object === 'stdClass' => $statement->setFetchMode(PDO::FETCH_OBJ), + $object === stdClass::class => $statement->setFetchMode(PDO::FETCH_OBJ), is_callable($object) => $statement->setFetchMode(PDO::FETCH_OBJ), is_object($object) => $statement->setFetchMode(PDO::FETCH_INTO, $object), is_array($object) => $statement->setFetchMode(PDO::FETCH_ASSOC), @@ -73,20 +85,31 @@ public function prepare(string $queryString, mixed $object = '\stdClass', array| return $statement; } - protected function executeStatement(mixed $object = '\stdClass', mixed $extra = null): PDOStatement - { + /** + * @param int|string|array|callable|object $object + * @param array|null $extra + */ + private function executeStatement( + int|string|array|callable|object $object = stdClass::class, + array|null $extra = null, + ): PDOStatement { $statement = $this->prepare((string) $this->currentSql, $object, $extra); - $statement->execute($this->currentSql->getParams()); + $statement->execute($this->currentSql->params); $this->currentSql = clone $this->protoSql; return $statement; } - protected function performFetch(string $method, mixed $object = '\stdClass', mixed $extra = null): mixed - { - $statement = $this->executeStatement($object, $extra); - - return $statement->{$method}(); + /** + * @param int|string|array|callable|object $object + * @param array|null $extra + */ + private function performFetch( + string $method, + int|string|array|callable|object $object = stdClass::class, + array|null $extra = null, + ): mixed { + return $this->executeStatement($object, $extra)->{$method}(); } /** @param array $arguments */ diff --git a/src/Mapper.php b/src/Mapper.php index f763862..3e18d71 100644 --- a/src/Mapper.php +++ b/src/Mapper.php @@ -30,7 +30,7 @@ /** Maps objects to database operations */ final class Mapper extends AbstractMapper { - protected readonly Db $db; + public readonly Db $db; public function __construct(PDO|Db $db, EntityFactory $entityFactory = new EntityFactory()) { @@ -39,28 +39,19 @@ public function __construct(PDO|Db $db, EntityFactory $entityFactory = new Entit $this->db = $db instanceof PDO ? new Db($db) : $db; } - public function getDb(): Db - { - return $this->db; - } - public function fetch(Collection $collection, mixed $extra = null): mixed { - $statement = $this->createStatement($collection, $extra); - $hydrated = $this->fetchHydrated($collection, $statement); - if (!$hydrated) { - return false; - } + $hydrated = $this->fetchHydrated($collection, $this->createStatement($collection, $extra)); - return $this->parseHydrated($hydrated); + return $hydrated ? $this->parseHydrated($hydrated) : false; } /** @return array */ public function fetchAll(Collection $collection, mixed $extra = null): array { $statement = $this->createStatement($collection, $extra); - $entities = []; + $entities = []; while ($hydrated = $this->fetchHydrated($collection, $statement)) { $entities[] = $this->parseHydrated($hydrated); } @@ -74,17 +65,16 @@ public function persist(object $object, Collection $onCollection): bool return parent::persist($object, $onCollection); } - $next = $onCollection->getNext(); + $next = $onCollection->next; if ($next) { - $remote = $this->getStyle()->remoteIdentifier($next->getName()); - $next->setMapper($this); - $next->persist($this->entityFactory->get($object, $remote)); + $remote = $this->style->remoteIdentifier($next->name); + $this->persist($this->entityFactory->get($object, $remote), $next); } - foreach ($onCollection->getChildren() as $child) { - $remote = $this->getStyle()->remoteIdentifier($child->getName()); - $child->persist($this->entityFactory->get($object, $remote)); + foreach ($onCollection->children as $child) { + $remote = $this->style->remoteIdentifier($child->name); + $this->persist($this->entityFactory->get($object, $remote), $child); } return parent::persist($object, $onCollection); @@ -92,7 +82,7 @@ public function persist(object $object, Collection $onCollection): bool public function flush(): void { - $conn = $this->db->getConnection(); + $conn = $this->db->connection; $conn->beginTransaction(); try { @@ -109,7 +99,7 @@ public function flush(): void $conn->commit(); } - protected function flushSingle(object $entity): void + private function flushSingle(object $entity): void { $coll = $this->tracked[$entity]; $cols = $this->extractColumns($entity, $coll); @@ -128,13 +118,13 @@ protected function flushSingle(object $entity): void * * @return array */ - protected function extractAndOperateCompositions(Collection $collection, array $cols): array + private function extractAndOperateCompositions(Collection $collection, array $cols): array { if (!$collection instanceof Composite) { return $cols; } - foreach ($collection->getCompositions() as $comp => $spec) { + foreach ($collection->compositions as $comp => $spec) { $compCols = []; foreach ($spec as $key) { if (!isset($cols[$key])) { @@ -163,9 +153,9 @@ protected function extractAndOperateCompositions(Collection $collection, array $ * * @return array> */ - protected function guessCondition(array &$columns, Collection $collection): array + private function guessCondition(array &$columns, Collection $collection): array { - $primaryName = $this->getStyle()->identifier($collection->getName()); + $primaryName = $this->style->identifier($collection->name); $condition = [[$primaryName, '=', $columns[$primaryName]]]; unset($columns[$primaryName]); @@ -173,45 +163,42 @@ protected function guessCondition(array &$columns, Collection $collection): arra } /** @param array $condition */ - protected function rawDelete( + private function rawDelete( array $condition, Collection $collection, object $entity, ): bool { - $name = $collection->getName(); $columns = $this->extractColumns($entity, $collection); $condition = $this->guessCondition($columns, $collection); return $this->db - ->deleteFrom($name) + ->deleteFrom($collection->name) ->where($condition) ->exec(); } /** @param array $columns */ - protected function rawUpdate(array $columns, Collection $collection): bool + private function rawUpdate(array $columns, Collection $collection): bool { $columns = $this->extractAndOperateCompositions($collection, $columns); - $name = $collection->getName(); $condition = $this->guessCondition($columns, $collection); return $this->db - ->update($name) + ->update($collection->name) ->set($columns) ->where($condition) ->exec(); } /** @param array $columns */ - protected function rawInsert( + private function rawInsert( array $columns, Collection $collection, object|null $entity = null, ): bool { - $columns = $this->extractAndOperateCompositions($collection, $columns); - $name = $collection->getName(); - $isInserted = $this->db - ->insertInto($name, array_keys($columns)) + $columns = $this->extractAndOperateCompositions($collection, $columns); + $result = $this->db + ->insertInto($collection->name, array_keys($columns)) ->values(array_values($columns)) ->exec(); @@ -219,16 +206,14 @@ protected function rawInsert( $this->checkNewIdentity($entity, $collection); } - return $isInserted; + return $result; } - protected function checkNewIdentity(object $entity, Collection $collection): bool + private function checkNewIdentity(object $entity, Collection $collection): bool { - $identity = null; try { - $identity = $this->db->getConnection()->lastInsertId(); + $identity = $this->db->connection->lastInsertId(); } catch (PDOException) { - //some drivers may throw an exception here, it is just irrelevant return false; } @@ -236,13 +221,12 @@ protected function checkNewIdentity(object $entity, Collection $collection): boo return false; } - $primaryName = $this->getStyle()->identifier($collection->getName()); - $this->entityFactory->set($entity, $primaryName, $identity); + $this->entityFactory->set($entity, $this->style->identifier($collection->name), $identity); return true; } - protected function generateQuery(Collection $collection): Sql + private function generateQuery(Collection $collection): Sql { $collections = iterator_to_array( CollectionIterator::recursive($collection), @@ -257,9 +241,9 @@ protected function generateQuery(Collection $collection): Sql } /** @return array */ - protected function extractColumns(object $entity, Collection $collection): array + private function extractColumns(object $entity, Collection $collection): array { - $primaryName = $this->getStyle()->identifier($collection->getName()); + $primaryName = $this->style->identifier($collection->name); $cols = $this->entityFactory->extractProperties($entity); foreach ($cols as &$c) { @@ -274,44 +258,44 @@ protected function extractColumns(object $entity, Collection $collection): array } /** @param array $collections */ - protected function buildSelectStatement(Sql $sql, array $collections): Sql + private function buildSelectStatement(Sql $sql, array $collections): Sql { $selectTable = []; foreach ($collections as $tableSpecifier => $c) { if ($c instanceof Composite) { - foreach ($c->getCompositions() as $composition => $columns) { + foreach ($c->compositions as $composition => $columns) { foreach ($columns as $col) { $selectTable[] = $tableSpecifier . '_comp' . $composition . '.' . $col; } $selectTable[] = $tableSpecifier . '_comp' . $composition . '.' . - $this->getStyle()->identifier($composition) . + $this->style->identifier($composition) . ' as ' . $composition . '_id'; } } if ($c instanceof Filtered) { - $filters = $c->getFilters(); + $filters = $c->filters; if ($filters) { $pkName = $tableSpecifier . '.' . - $this->getStyle()->identifier($c->getName()); + $this->style->identifier($c->name); - if ($c->isIdentifierOnly()) { + if ($c->identifierOnly) { $selectColumns = [$pkName]; } else { $selectColumns = [ $tableSpecifier . '.' . - $this->getStyle()->identifier($c->getName()), + $this->style->identifier($c->name), ]; foreach ($filters as $f) { $selectColumns[] = $tableSpecifier . '.' . $f; } } - $nextName = $c->getNext()?->getName(); + $nextName = $c->next?->name; if ($nextName !== null) { $selectColumns[] = $tableSpecifier . '.' . - $this->getStyle()->remoteIdentifier($nextName); + $this->style->remoteIdentifier($nextName); } $selectTable = array_merge($selectTable, $selectColumns); @@ -325,7 +309,7 @@ protected function buildSelectStatement(Sql $sql, array $collections): Sql } /** @param array $collections */ - protected function buildTables(Sql $sql, array $collections): Sql + private function buildTables(Sql $sql, array $collections): Sql { $conditions = $aliases = []; @@ -347,17 +331,15 @@ protected function buildTables(Sql $sql, array $collections): Sql * * @return array */ - protected function parseConditions(array &$conditions, Collection $collection, string $alias): array + private function parseConditions(array &$conditions, Collection $collection, string $alias): array { - $entity = $collection->getName(); - $originalConditions = $collection->getCondition(); - $parsedConditions = []; - $aliasedPk = $alias . '.' . $this->getStyle()->identifier($entity); - - if (is_scalar($originalConditions)) { - $parsedConditions[] = [$aliasedPk, '=', $originalConditions]; - } elseif (is_array($originalConditions)) { - foreach ($originalConditions as $column => $value) { + $parsedConditions = []; + $aliasedPk = $alias . '.' . $this->style->identifier($collection->name); + + if (is_scalar($collection->condition)) { + $parsedConditions[] = [$aliasedPk, '=', $collection->condition]; + } elseif (is_array($collection->condition)) { + foreach ($collection->condition as $column => $value) { if (!empty($parsedConditions)) { $parsedConditions[] = 'AND'; } @@ -369,13 +351,13 @@ protected function parseConditions(array &$conditions, Collection $collection, s return $parsedConditions; } - protected function parseCompositions(Sql $sql, Collection $collection, string $entity): void + private function parseCompositions(Sql $sql, Collection $collection, string $entity): void { if (!$collection instanceof Composite) { return; } - foreach (array_keys($collection->getCompositions()) as $comp) { + foreach (array_keys($collection->compositions) as $comp) { $sql->innerJoin($comp); $sql->as($entity . '_comp' . $comp); } @@ -385,17 +367,17 @@ protected function parseCompositions(Sql $sql, Collection $collection, string $e * @param array $aliases * @param array $conditions */ - protected function parseCollection( + private function parseCollection( Sql $sql, Collection $collection, string $alias, array &$aliases, array &$conditions, - ): mixed { - $s = $this->getStyle(); - $entity = $collection->getName(); - $parent = $collection->getParent()?->getName(); - $next = $collection->getNext()?->getName(); + ): void { + $s = $this->style; + $entity = $collection->name; + $parent = $collection->parent?->name; + $next = $collection->next?->name; $parentAlias = $parent ? $aliases[$parent] : null; $aliases[$entity] = $alias; @@ -417,10 +399,10 @@ protected function parseCollection( $sql->from($entity); $this->parseCompositions($sql, $collection, $entity); - return null; + return; } - if ($collection->isRequired()) { + if ($collection->required) { $sql->innerJoin($entity); } else { $sql->leftJoin($entity); @@ -443,19 +425,17 @@ protected function parseCollection( $onAlias = $aliasedPk; } - return $sql->on([$onName => $onAlias]); + $sql->on([$onName => $onAlias]); } - protected function hasComposition(string $entity, string|null $next, string|null $parent): bool + private function hasComposition(string $entity, string|null $next, string|null $parent): bool { if ($next === null || $parent === null) { return false; } - $s = $this->getStyle(); - - return $entity === $s->composed($parent, $next) - || $entity === $s->composed($next, $parent); + return $entity === $this->style->composed($parent, $next) + || $entity === $this->style->composed($next, $parent); } /** @@ -463,7 +443,7 @@ protected function hasComposition(string $entity, string|null $next, string|null * * @return SplObjectStorage */ - protected function createEntities( + private function createEntities( array $row, PDOStatement $statement, Collection $collection, @@ -479,8 +459,8 @@ protected function createEntities( foreach (array_reverse($row, true) as $col => $value) { /** @phpstan-ignore offsetAccess.nonOffsetAccessible */ $columnName = $statement->getColumnMeta($col)['name']; - $primaryName = $this->getStyle()->identifier( - $entities[$entityInstance]->getName(), + $primaryName = $this->style->identifier( + $entities[$entityInstance]->name, ); $this->entityFactory->set($entityInstance, $columnName, $value); @@ -496,7 +476,7 @@ protected function createEntities( } /** @param SplObjectStorage $hydrated */ - private function parseHydrated(SplObjectStorage $hydrated): mixed + private function parseHydrated(SplObjectStorage $hydrated): object { $this->tracked->addAll($hydrated); $hydrated->rewind(); @@ -507,11 +487,9 @@ private function parseHydrated(SplObjectStorage $hydrated): mixed /** @return SplObjectStorage|false */ private function fetchHydrated(Collection $collection, PDOStatement $statement): SplObjectStorage|false { - if (!$collection->hasMore()) { - return $this->fetchSingle($collection, $statement); - } + $method = $collection->more ? 'fetchMulti' : 'fetchSingle'; - return $this->fetchMulti($collection, $statement); + return $this->$method($collection, $statement); } private function createStatement( @@ -525,7 +503,7 @@ private function createStatement( } $statement = $this->db->prepare((string) $query, PDO::FETCH_NUM); - $statement->execute($query->getParams()); + $statement->execute($query->params); return $statement; } @@ -541,9 +519,9 @@ private function fetchSingle( return false; } - $entityName = $collection->resolveEntityName($this->entityFactory, $row); + $entity = $this->entityFactory->hydrate($row, $collection->resolveEntityName($this->entityFactory, $row)); $entities = new SplObjectStorage(); - $entities[$this->entityFactory->hydrate($row, $entityName)] = $collection; + $entities[$entity] = $collection; return $entities; } diff --git a/src/Sql.php b/src/Sql.php index ff985fb..3483140 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -43,17 +43,14 @@ class Sql /** @phpstan-var list */ private(set) array $params = []; - private bool $raw = false; - - public function __construct() + public function __construct(private readonly bool $raw = false) { } public static function raw(string $expression): static { - $sql = new static(); + $sql = new static(raw: true); $sql->query[] = $expression; - $sql->raw = true; return $sql; } @@ -66,12 +63,6 @@ public function concat(self $sql): static return $this; } - /** @return list */ - public function getParams(): array - { - return $this->params; - } - /** * select('a', 'b'), from('t1', 't2'), orderBy('col') * diff --git a/src/SqlException.php b/src/SqlException.php index 0845577..bf80458 100644 --- a/src/SqlException.php +++ b/src/SqlException.php @@ -6,6 +6,6 @@ use InvalidArgumentException; -class SqlException extends InvalidArgumentException +final class SqlException extends InvalidArgumentException { } diff --git a/tests/DbTest.php b/tests/DbTest.php index 87030e9..b8ad777 100644 --- a/tests/DbTest.php +++ b/tests/DbTest.php @@ -113,7 +113,7 @@ public function testGetSql(): void $sql = $this->object->select('*')->from('unit') ->where([['testb', '=', 'abc']])->getSql(); $this->assertEquals('SELECT * FROM unit WHERE testb = ?', (string) $sql); - $this->assertEquals(['abc'], $sql->getParams()); + $this->assertEquals(['abc'], $sql->params); } public function testFluentSelectWithParams(): void @@ -133,7 +133,7 @@ public function testExecReturnsTrueOnSuccess(): void public function testGetConnectionReturnsPdoInstance(): void { - $connection = $this->object->getConnection(); + $connection = $this->object->connection; $this->assertInstanceOf(PDO::class, $connection); } diff --git a/tests/MapperTest.php b/tests/MapperTest.php index c4ae665..d68bb30 100644 --- a/tests/MapperTest.php +++ b/tests/MapperTest.php @@ -190,7 +190,7 @@ public function testCreatingWithDbInstance(): void { $db = new Db($this->conn); $mapper = new Mapper($db); - $this->assertSame($db, $mapper->getDb()); + $this->assertSame($db, $mapper->db); } public function testGetDefinedDbInstance(): void @@ -198,7 +198,7 @@ public function testGetDefinedDbInstance(): void $db = new Db($this->conn); $mapper = new Mapper($db); - $this->assertSame($db, $mapper->getDb()); + $this->assertSame($db, $mapper->db); } public function testCreatingWithInvalidArgsShouldThrowException(): void @@ -603,11 +603,11 @@ public function testStyle(): void { $this->assertInstanceOf( 'Respect\Data\Styles\Stylable', - $this->mapper->getStyle(), + $this->mapper->style, ); $this->assertInstanceOf( 'Respect\Data\Styles\Standard', - $this->mapper->getStyle(), + $this->mapper->style, ); $styles = [ new Styles\CakePHP(), @@ -617,7 +617,7 @@ public function testStyle(): void ]; foreach ($styles as $style) { $mapper = new Mapper($this->conn, new EntityFactory(style: $style)); - $this->assertEquals($style, $mapper->getStyle()); + $this->assertEquals($style, $mapper->style); } } @@ -1202,7 +1202,7 @@ public function testFetchReturnsDbInstance(): void { $db = new Db($this->conn); $mapper = new Mapper($db); - $this->assertInstanceOf(Db::class, $mapper->getDb()); + $this->assertInstanceOf(Db::class, $mapper->db); } private function query(string $sql): PDOStatement diff --git a/tests/SqlTest.php b/tests/SqlTest.php index d8a054d..b1b80e4 100644 --- a/tests/SqlTest.php +++ b/tests/SqlTest.php @@ -63,7 +63,7 @@ public function testSelectUsingAliasedColumns(): void 'SELECT f1, f2 AS alias, f3, f4 AS another_alias FROM table', $sql, ); - $this->assertEmpty($this->object->getParams()); + $this->assertEmpty($this->object->params); } public function testSelectWithAggregateFunctions(): void @@ -95,7 +95,7 @@ public function testWhereWithAndConditions(): void 'SELECT * FROM table WHERE column = ? AND other_column = ?', $sql, ); - $this->assertEquals(['123', '456'], $this->object->getParams()); + $this->assertEquals(['123', '456'], $this->object->params); } public function testWhereWithOrConditions(): void @@ -109,7 +109,7 @@ public function testWhereWithOrConditions(): void 'SELECT * FROM table WHERE column = ? OR other_column = ?', $sql, ); - $this->assertEquals(['123', '456'], $this->object->getParams()); + $this->assertEquals(['123', '456'], $this->object->params); } public function testWhereWithNestedGroupedConditions(): void @@ -127,7 +127,7 @@ public function testWhereWithNestedGroupedConditions(): void 'SELECT * FROM table WHERE foo = ? OR (xoo = ? AND xoo = ?)', $sql, ); - $this->assertEquals(['baz', 'qux', 'zap'], $this->object->getParams()); + $this->assertEquals(['baz', 'qux', 'zap'], $this->object->params); } public function testSelectWhereArrayQualifiedNames(): void @@ -143,7 +143,7 @@ public function testSelectWhereArrayQualifiedNames(): void 'SELECT * FROM table a, other_table b WHERE a.column = ? AND b.other_column = ?', $sql, ); - $this->assertEquals(['123', '456'], $this->object->getParams()); + $this->assertEquals(['123', '456'], $this->object->params); } public function testWhereIn(): void @@ -152,7 +152,7 @@ public function testWhereIn(): void $sql = (string) $this->object->select('*')->from('table') ->where([['column', 'IN', $data]]); $this->assertEquals('SELECT * FROM table WHERE column IN (?, ?)', $sql); - $this->assertEquals($data, $this->object->getParams()); + $this->assertEquals($data, $this->object->params); } public function testWhereBetween(): void @@ -160,7 +160,7 @@ public function testWhereBetween(): void $sql = (string) $this->object->select('*')->from('table') ->where([['column', 'BETWEEN', [1, 100]]]); $this->assertEquals('SELECT * FROM table WHERE column BETWEEN ? AND ?', $sql); - $this->assertEquals([1, 100], $this->object->getParams()); + $this->assertEquals([1, 100], $this->object->params); } public function testWhereInWithCompoundConditions(): void @@ -174,7 +174,7 @@ public function testWhereInWithCompoundConditions(): void 'SELECT * FROM table WHERE column IN (?, ?, ?) AND other = ?', $sql, ); - $this->assertEquals(['a', 'b', 'c', 'foo'], $this->object->getParams()); + $this->assertEquals(['a', 'b', 'c', 'foo'], $this->object->params); } /** @return array> */ @@ -200,7 +200,7 @@ public function testAllComparisonOperators(string $operator): void $sql = (string) $this->object->select('*')->from('table') ->where([['id', $operator, '10']]); $this->assertEquals('SELECT * FROM table WHERE id ' . $operator . ' ?', $sql); - $this->assertEquals(['10'], $this->object->getParams()); + $this->assertEquals(['10'], $this->object->params); } public function testMixedOperatorsInCompoundConditions(): void @@ -216,7 +216,7 @@ public function testMixedOperatorsInCompoundConditions(): void 'SELECT * FROM table WHERE age >= ? AND name LIKE ? AND status != ?', $sql, ); - $this->assertEquals(['18', '%foo%', 'banned'], $this->object->getParams()); + $this->assertEquals(['18', '%foo%', 'banned'], $this->object->params); } public function testSelectGroupBy(): void @@ -239,7 +239,7 @@ public function testGroupByWithHaving(): void . ' HAVING other_column = ? AND yet_another_column = ?', $sql, ); - $this->assertEquals([456, 567], $this->object->getParams()); + $this->assertEquals([456, 567], $this->object->params); } public function testHavingWithAggregateOperators(): void @@ -257,7 +257,7 @@ public function testHavingWithAggregateOperators(): void . ' GROUP BY abc, def HAVING SUM(abc) >= ? AND AVG(def) = ?', $sql, ); - $this->assertEquals(['10', '10', 15], $this->object->getParams()); + $this->assertEquals(['10', '10', 15], $this->object->params); } public function testSimpleUpdate(): void @@ -273,7 +273,7 @@ public function testSimpleUpdate(): void . ' WHERE other_column = ? AND yet_another_column = ?', $sql, ); - $this->assertEquals([123, 234, 456, 567], $this->object->getParams()); + $this->assertEquals([123, 234, 456, 567], $this->object->params); } public function testSetWithRawExpression(): void @@ -285,7 +285,7 @@ public function testSetWithRawExpression(): void 'UPDATE table SET counter = counter + 1, updated_at = NOW() WHERE id = ?', $sql, ); - $this->assertEquals(['5'], $this->object->getParams()); + $this->assertEquals(['5'], $this->object->params); } public function testSetWithSubquery(): void @@ -298,7 +298,7 @@ public function testSetWithSubquery(): void 'UPDATE table SET high_score = (SELECT MAX(score) FROM scores WHERE active = ?) WHERE id = ?', $sql, ); - $this->assertEquals(['1', '5'], $this->object->getParams()); + $this->assertEquals(['1', '5'], $this->object->params); } public function testSimpleInsert(): void @@ -306,7 +306,7 @@ public function testSimpleInsert(): void $sql = (string) $this->object->insertInto('table', ['column', 'column_2']) ->values([123, 234]); $this->assertEquals('INSERT INTO table (column, column_2) VALUES (?, ?)', $sql); - $this->assertEquals([123, 234], $this->object->getParams()); + $this->assertEquals([123, 234], $this->object->params); } public function testInsertWithRawValues(): void @@ -317,7 +317,7 @@ public function testInsertWithRawValues(): void 'INSERT INTO table (column, column_2, date) VALUES (?, ?, NOW())', $sql, ); - $this->assertEquals([123, 234], $this->object->getParams()); + $this->assertEquals([123, 234], $this->object->params); } public function testInsertWithSelectSubquery(): void @@ -333,7 +333,7 @@ public function testInsertWithSelectSubquery(): void 'INSERT INTO t1 (f1, f2) SELECT f1, f2 FROM t2 WHERE f3 = ? AND f4 = ?', $sql, ); - $this->assertEquals([3, 4], $this->object->getParams()); + $this->assertEquals([3, 4], $this->object->params); } public function testSimpleDelete(): void @@ -347,7 +347,7 @@ public function testSimpleDelete(): void 'DELETE FROM table WHERE other_column = ? AND yet_another_column = ?', $sql, ); - $this->assertEquals([456, 567], $this->object->getParams()); + $this->assertEquals([456, 567], $this->object->params); } public function testWhereWithSubquery(): void @@ -361,7 +361,7 @@ public function testWhereWithSubquery(): void . ' AND column2 = ?', $sql, ); - $this->assertEquals([2, 'foo'], $this->object->getParams()); + $this->assertEquals([2, 'foo'], $this->object->params); } public function testNestedSubqueries(): void @@ -377,7 +377,7 @@ public function testNestedSubqueries(): void . ' WHERE column2 = (SELECT column1 FROM t3 WHERE column3 = ?) AND column3 = ?)', $sql, ); - $this->assertEquals([3, 'foo'], $this->object->getParams()); + $this->assertEquals([3, 'foo'], $this->object->params); } public function testSelectColumnAsSubquery(): void @@ -390,7 +390,7 @@ public function testSelectColumnAsSubquery(): void 'SELECT f1, (SELECT f1 FROM t2 WHERE f2 = ?) AS subalias FROM t1 WHERE f2 = ?', $sql, ); - $this->assertEquals([2, 'foo'], $this->object->getParams()); + $this->assertEquals([2, 'foo'], $this->object->params); } public function testWhereWithFunctionColumn(): void @@ -401,7 +401,7 @@ public function testWhereWithFunctionColumn(): void "SELECT column, COUNT(column), other_column FROM table WHERE AES_DECRYPT('pass', 'salt') = ?", $sql, ); - $this->assertEquals([123], $this->object->getParams()); + $this->assertEquals([123], $this->object->params); } public function testCreateTable(): void @@ -533,7 +533,7 @@ public function testConcat(): void 'SELECT * FROM table WHERE a = ? ORDER BY b DESC', (string) $base, ); - $this->assertEquals([1], $base->getParams()); + $this->assertEquals([1], $base->params); } public function testConcatMergesParams(): void @@ -542,7 +542,7 @@ public function testConcatMergesParams(): void $extra = Sql::select('*')->from('t2')->where([['b', '=', 2]]); $base->concat($extra); - $this->assertEquals([1, 2], $base->getParams()); + $this->assertEquals([1, 2], $base->params); } public function testWhereWithNullValue(): void @@ -550,7 +550,7 @@ public function testWhereWithNullValue(): void $sql = (string) $this->object->select('*')->from('table') ->where([['col', '=', null]]); $this->assertEquals('SELECT * FROM table WHERE col IS NULL', $sql); - $this->assertEmpty($this->object->getParams()); + $this->assertEmpty($this->object->params); } public function testWhereWithNotEqualNull(): void @@ -558,7 +558,7 @@ public function testWhereWithNotEqualNull(): void $sql = (string) $this->object->select('*')->from('table') ->where([['col', '!=', null]]); $this->assertEquals('SELECT * FROM table WHERE col IS NOT NULL', $sql); - $this->assertEmpty($this->object->getParams()); + $this->assertEmpty($this->object->params); } public function testWhereWithNotEqualNullDiamondOperator(): void @@ -579,7 +579,7 @@ public function testWhereWithNullInCompoundCondition(): void 'SELECT * FROM table WHERE name = ? AND deleted_at IS NULL', $sql, ); - $this->assertEquals(['foo'], $this->object->getParams()); + $this->assertEquals(['foo'], $this->object->params); } public function testInsertWithNullValue(): void @@ -587,7 +587,7 @@ public function testInsertWithNullValue(): void $sql = (string) $this->object->insertInto('table', ['a', 'b', 'c']) ->values([1, null, 'foo']); $this->assertEquals('INSERT INTO table (a, b, c) VALUES (?, ?, ?)', $sql); - $this->assertEquals([1, null, 'foo'], $this->object->getParams()); + $this->assertEquals([1, null, 'foo'], $this->object->params); } public function testSetWithNullValue(): void @@ -599,7 +599,7 @@ public function testSetWithNullValue(): void 'UPDATE table SET col = ?, other = ? WHERE id = ?', $sql, ); - $this->assertEquals([null, 123, 1], $this->object->getParams()); + $this->assertEquals([null, 123, 1], $this->object->params); } public function testNullWithUnsupportedOperatorThrows(): void