diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 94b4829..58f379d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,15 +1,18 @@ parameters: - level: 2 + level: 5 paths: - src/ - tests/ ignoreErrors: - message: '/Call to an undefined (static )?method Respect\\Relational\\(Sql|Db|Mapper)::\w+\(\)\./' - - message: '/Call to an undefined static method Respect\\Data\\Collections\\(Collection|Filtered|Mix|Typed)::\w+\(\)\./' + - message: '/Call to an undefined (static )?method Respect\\Data\\Collections\\(Collection|Filtered|Mix|Typed)::\w+\(\)\./' - message: '/Access to an undefined property Respect\\Relational\\Mapper::\$\w+\./' - message: '/Unsafe usage of new static\(\)\./' - message: '/Cannot unset property .+ because it might have hooks in a subclass\./' - message: '/Array has \d+ duplicate keys/' - - message: '/unknown class/' + message: '/(unknown class|does not accept)/' path: tests/Styles/ + - + message: '/Parameter #1 .+ of class Respect\\Relational\\Mapper constructor expects .+, string given\./' + path: tests/MapperTest.php diff --git a/src/Db.php b/src/Db.php index ee53fc2..63d4020 100644 --- a/src/Db.php +++ b/src/Db.php @@ -5,14 +5,15 @@ namespace Respect\Relational; use PDO; +use PDOStatement; -class Db +final class Db { - protected $connection; - protected $currentSql; - protected $protoSql; + protected PDO $connection; + protected Sql $currentSql; + protected Sql $protoSql; - public function __call($methodName, $arguments) + public function __call(string $methodName, array $arguments): static { $this->currentSql->__call($methodName, $arguments); @@ -27,66 +28,60 @@ public function __construct(PDO $connection, Sql|null $sqlPrototype = null) $this->currentSql = clone $this->protoSql; } - public function exec() + public function exec(): bool { return (bool) $this->executeStatement(); } - public function fetch($object = '\stdClass', $extra = null) + public function fetch(mixed $object = '\stdClass', mixed $extra = null): mixed { $result = $this->performFetch(__FUNCTION__, $object, $extra); return is_callable($object) ? $object($result) : $result; } - public function fetchAll($object = '\stdClass', $extra = null) + public function fetchAll(mixed $object = '\stdClass', mixed $extra = null): mixed { $result = $this->performFetch(__FUNCTION__, $object, $extra); return is_callable($object) ? array_map($object, $result) : $result; } - public function getConnection() + public function getConnection(): PDO { return $this->connection; } - public function getSql() + public function getSql(): Sql { return $this->currentSql; } - public function prepare($queryString, $object = '\stdClass', array|null $extra = null) + public function prepare(string $queryString, mixed $object = '\stdClass', array|null $extra = null): PDOStatement { $statement = $this->connection->prepare($queryString); - if (is_int($object)) { - $statement->setFetchMode($object); - } elseif ('\stdClass' === $object || 'stdClass' === $object) { - $statement->setFetchMode(PDO::FETCH_OBJ); - } elseif (is_callable($object)) { - $statement->setFetchMode(PDO::FETCH_OBJ); - } elseif (is_object($object)) { - $statement->setFetchMode(PDO::FETCH_INTO, $object); - } elseif (is_array($object)) { - $statement->setFetchMode(PDO::FETCH_ASSOC); - } elseif (is_null($extra)) { - $statement->setFetchMode(PDO::FETCH_CLASS, $object); - } else { - $statement->setFetchMode(PDO::FETCH_CLASS, $object, $extra); - } + match (true) { + is_int($object) => $statement->setFetchMode($object), + '\stdClass' === $object || 'stdClass' === $object => $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), + is_null($extra) => $statement->setFetchMode(PDO::FETCH_CLASS, $object), + default => $statement->setFetchMode(PDO::FETCH_CLASS, $object, $extra), + }; return $statement; } - public function query($rawSql, array|null $params = null) + public function query(string $rawSql, array|null $params = null): static { $this->currentSql->setQuery($rawSql, $params); return $this; } - protected function executeStatement($object = '\stdClass', $extra = null) + protected function executeStatement(mixed $object = '\stdClass', mixed $extra = null): PDOStatement { $statement = $this->prepare((string) $this->currentSql, $object, $extra); $statement->execute($this->currentSql->getParams()); @@ -95,7 +90,7 @@ protected function executeStatement($object = '\stdClass', $extra = null) return $statement; } - protected function performFetch($method, $object = '\stdClass', $extra = null) + protected function performFetch(string $method, mixed $object = '\stdClass', mixed $extra = null): mixed { $statement = $this->executeStatement($object, $extra); $result = $statement->{$method}(); diff --git a/src/Mapper.php b/src/Mapper.php index 4ad03bb..17942e0 100644 --- a/src/Mapper.php +++ b/src/Mapper.php @@ -6,79 +6,37 @@ use Exception; use PDO; -use SplObjectStorage; -use InvalidArgumentException; -use PDOStatement; use PDOException; -use stdClass; +use PDOStatement; +use ReflectionClass; use Respect\Data\AbstractMapper; -use Respect\Data\Collections\Collection; use Respect\Data\Collections as c; +use Respect\Data\Collections\Collection; use Respect\Data\CollectionIterator; -use ReflectionProperty; -use ReflectionClass; +use SplObjectStorage; /** Maps objects to database operations */ -class Mapper extends AbstractMapper implements +final class Mapper extends AbstractMapper implements c\Filterable, c\Mixable, c\Typable { - /** - * Holds our connector - * - * @var Db - */ - protected $db; - - /** - * Namespace to look for entities. - * - * @var string - */ - public $entityNamespace = '\\'; - - /** - * Disable or enable entity constructors. - * - * @var bool - */ - public $disableEntityConstructor = false; - - /** - * @param mixed $db Db or Pdo - */ - public function __construct($db) + protected Db $db; + public string $entityNamespace = '\\'; + public bool $disableEntityConstructor = false; + + public function __construct(PDO|Db $db) { parent::__construct(); - - if ($db instanceof PDO) { - $this->db = new Db($db); - } elseif ($db instanceof Db) { - $this->db = $db; - } else { - throw new InvalidArgumentException( - '$db must be an instance of Respect\Relational\Db or PDO.' - ); - } + $this->db = $db instanceof PDO ? new Db($db) : $db; } - /** - * @return Db - */ - public function getDb() + public function getDb(): Db { return $this->db; } - /** - * Flushes a single instance into the database. This method supports - * mixing, so flushing a mixed instance will flush distinct tables on the - * database. - * - * @param object $entity Entity instance to be flushed - */ - protected function flushSingle($entity) + protected function flushSingle(object $entity): void { $coll = $this->tracked[$entity]; $cols = $this->extractColumns($entity, $coll); @@ -92,7 +50,7 @@ protected function flushSingle($entity) } } - public function persist($object, Collection $onCollection) + public function persist(object $object, Collection $onCollection): bool { $next = $onCollection->getNext(); @@ -100,7 +58,7 @@ public function persist($object, Collection $onCollection) $next->setMapper($this); $next->persist($object); - return; + return true; } if ($next) { @@ -117,18 +75,7 @@ public function persist($object, Collection $onCollection) return parent::persist($object, $onCollection); } - /** - * Receives columns from an entity and her collection. Returns the columns - * that belong only to the main entity. This method supports mixing, so - * extracting mixins will also persist them on their respective - * tables. - * - * @param Collection $collection Target collection - * @param array $cols Entity columns - * - * @return array Columns left for the main collection - */ - protected function extractAndOperateMixins(Collection $collection, $cols) + protected function extractAndOperateMixins(Collection $collection, array $cols): array { if (!$this->mixable($collection)) { return $cols; @@ -158,10 +105,10 @@ protected function extractAndOperateMixins(Collection $collection, $cols) return $cols; } - protected function guessCondition(&$columns, Collection $collection) + protected function guessCondition(array &$columns, Collection $collection): array { $primaryName = $this->getStyle()->identifier($collection->getName()); - $condition = array($primaryName => $columns[$primaryName]); + $condition = [$primaryName => $columns[$primaryName]]; unset($columns[$primaryName]); return $condition; @@ -170,8 +117,8 @@ protected function guessCondition(&$columns, Collection $collection) protected function rawDelete( array $condition, Collection $collection, - $entity - ) { + object $entity + ): bool { $name = $collection->getName(); $columns = $this->extractColumns($entity, $collection); $condition = $this->guessCondition($columns, $collection); @@ -182,7 +129,7 @@ protected function rawDelete( ->exec(); } - protected function rawUpdate(array $columns, Collection $collection) + protected function rawUpdate(array $columns, Collection $collection): bool { $columns = $this->extractAndOperateMixins($collection, $columns); $name = $collection->getName(); @@ -198,8 +145,8 @@ protected function rawUpdate(array $columns, Collection $collection) protected function rawInsert( array $columns, Collection $collection, - $entity = null - ) { + object|null $entity = null + ): bool { $columns = $this->extractAndOperateMixins($collection, $columns); $name = $collection->getName(); $isInserted = $this->db @@ -214,7 +161,7 @@ protected function rawInsert( return $isInserted; } - public function flush() + public function flush(): void { $conn = $this->db->getConnection(); $conn->beginTransaction(); @@ -232,7 +179,7 @@ public function flush() $conn->commit(); } - protected function checkNewIdentity($entity, Collection $collection) + protected function checkNewIdentity(object $entity, Collection $collection): bool { $identity = null; try { @@ -253,8 +200,8 @@ protected function checkNewIdentity($entity, Collection $collection) protected function createStatement( Collection $collection, - $withExtra = null - ) { + mixed $withExtra = null + ): PDOStatement { $query = $this->generateQuery($collection); if ($withExtra instanceof Sql) { @@ -267,7 +214,7 @@ protected function createStatement( return $statement; } - protected function generateQuery(Collection $collection) + protected function generateQuery(Collection $collection): Sql { $collections = iterator_to_array( CollectionIterator::recursive($collection), @@ -281,7 +228,7 @@ protected function generateQuery(Collection $collection) return $sql; } - protected function extractColumns($entity, Collection $collection) + protected function extractColumns(object $entity, Collection $collection): array { $primaryName = $this->getStyle()->identifier($collection->getName()); $cols = $this->getAllProperties($entity); @@ -295,9 +242,9 @@ protected function extractColumns($entity, Collection $collection) return $cols; } - protected function buildSelectStatement(Sql $sql, $collections) + protected function buildSelectStatement(Sql $sql, array $collections): Sql { - $selectTable = array(); + $selectTable = []; foreach ($collections as $tableSpecifier => $c) { if ($this->mixable($c)) { foreach ($this->getMixins($c) as $mixin => $columns) { @@ -315,13 +262,13 @@ protected function buildSelectStatement(Sql $sql, $collections) $pkName = $tableSpecifier.'.'. $this->getStyle()->identifier($c->getName()); - if ($filters == array('*')) { + if ($filters == ['*']) { $selectColumns[] = $pkName; } else { - $selectColumns = array( + $selectColumns = [ $tableSpecifier.'.'. $this->getStyle()->identifier($c->getName()), - ); + ]; foreach ($filters as $f) { $selectColumns[] = "{$tableSpecifier}.{$f}"; } @@ -344,9 +291,9 @@ protected function buildSelectStatement(Sql $sql, $collections) return $sql->select($selectTable); } - protected function buildTables(Sql $sql, $collections) + protected function buildTables(Sql $sql, array $collections): Sql { - $conditions = $aliases = array(); + $conditions = $aliases = []; foreach ($collections as $alias => $collection) { $this->parseCollection( @@ -361,16 +308,16 @@ protected function buildTables(Sql $sql, $collections) return $sql->where($conditions); } - protected function parseConditions(&$conditions, $collection, $alias) + protected function parseConditions(array &$conditions, Collection $collection, string $alias): array { $entity = $collection->getName(); $originalConditions = $collection->getCondition(); - $parsedConditions = array(); + $parsedConditions = []; $aliasedPk = $this->getStyle()->identifier($entity); $aliasedPk = $alias.'.'.$aliasedPk; if (is_scalar($originalConditions)) { - $parsedConditions = array($aliasedPk => $originalConditions); + $parsedConditions = [$aliasedPk => $originalConditions]; } elseif (is_array($originalConditions)) { foreach ($originalConditions as $column => $value) { if (is_numeric($column)) { @@ -388,7 +335,7 @@ protected function parseConditions(&$conditions, $collection, $alias) return $parsedConditions; } - protected function parseMixins(Sql $sql, Collection $collection, $entity) + protected function parseMixins(Sql $sql, Collection $collection, string $entity): void { if ($this->mixable($collection)) { foreach ($this->getMixins($collection) as $mix => $spec) { @@ -401,10 +348,10 @@ protected function parseMixins(Sql $sql, Collection $collection, $entity) protected function parseCollection( Sql $sql, Collection $collection, - $alias, - &$aliases, - &$conditions - ) { + string $alias, + array &$aliases, + array &$conditions + ): mixed { $s = $this->getStyle(); $entity = $collection->getName(); $parent = $collection->getParentName(); @@ -423,7 +370,7 @@ protected function parseCollection( $sql->from($entity); $this->parseMixins($sql, $collection, $entity); - return; + return null; } else { if ($collection->isRequired()) { $sql->innerJoin($entity); @@ -448,11 +395,11 @@ protected function parseCollection( $onAlias = $aliasedPk; } - return $sql->on(array($onName => $onAlias)); + return $sql->on([$onName => $onAlias]); } } - protected function hasComposition($entity, $next, $parent) + protected function hasComposition(string $entity, string|null $next, string|null $parent): bool { if ($next === null || $parent === null) { return false; @@ -467,7 +414,7 @@ protected function hasComposition($entity, $next, $parent) protected function fetchSingle( Collection $collection, PDOStatement $statement - ) { + ): SplObjectStorage|false { $name = $collection->getName(); $entityName = $name; $row = $statement->fetch(PDO::FETCH_OBJ); @@ -486,7 +433,7 @@ protected function fetchSingle( return $entities; } - protected function getNewEntityByName($entityName) + protected function getNewEntityByName(string $entityName): object { $entityName = $this->getStyle()->styledName($entityName); $entityClass = $this->entityNamespace.$entityName; @@ -500,7 +447,7 @@ protected function getNewEntityByName($entityName) return $entityReflection->newInstanceWithoutConstructor(); } - protected function transformSingleRow($row, $entityName) + protected function transformSingleRow(object $row, string $entityName): object { $newRow = $this->getNewEntityByName($entityName); @@ -511,7 +458,7 @@ protected function transformSingleRow($row, $entityName) return $newRow; } - protected function inferSet(&$entity, $prop, $value) + protected function inferSet(object &$entity, string $prop, mixed $value): void { if ($entity === $value) { return; @@ -525,22 +472,22 @@ protected function inferSet(&$entity, $prop, $value) } } - protected function inferGet(&$object, $prop) + protected function inferGet(object &$object, string $prop): mixed { try { $mirror = new \ReflectionProperty($object, $prop); return $mirror->getValue($object); } catch (\ReflectionException $e) { - return; + return null; } } protected function fetchMulti( Collection $collection, PDOStatement $statement - ) { - $entities = array(); + ): SplObjectStorage|false { + $entities = []; $row = $statement->fetch(PDO::FETCH_NUM); if (!$row) { @@ -555,10 +502,10 @@ protected function fetchMulti( } protected function createEntities( - $row, + array $row, PDOStatement $statement, Collection $collection - ) { + ): SplObjectStorage { $entities = new SplObjectStorage(); $entitiesInstances = $this->buildEntitiesInstances( $collection, @@ -587,8 +534,8 @@ protected function createEntities( protected function buildEntitiesInstances( Collection $collection, SplObjectStorage $entities - ) { - $entitiesInstances = array(); + ): array { + $entitiesInstances = []; foreach (CollectionIterator::recursive($collection) as $c) { if ($this->filterable($c) && !$this->getFilters($c)) { @@ -596,7 +543,7 @@ protected function buildEntitiesInstances( } $entityInstance = $this->getNewEntityByName($c->getName()); - $mixins = array(); + $mixins = []; if ($this->mixable($c)) { $mixins = $this->getMixins($c); @@ -612,7 +559,7 @@ protected function buildEntitiesInstances( return $entitiesInstances; } - protected function postHydrate(SplObjectStorage $entities) + protected function postHydrate(SplObjectStorage $entities): void { $entitiesClone = clone $entities; @@ -630,7 +577,7 @@ protected function postHydrate(SplObjectStorage $entities) } } - protected function tryHydration($entities, $sub, $field, &$v) + protected function tryHydration(SplObjectStorage $entities, object $sub, string $field, mixed &$v): void { $tableName = $entities[$sub]->getName(); $primaryName = $this->getStyle()->identifier($tableName); @@ -641,14 +588,14 @@ protected function tryHydration($entities, $sub, $field, &$v) } } - protected function getSetterStyle($name) + protected function getSetterStyle(string $name): string { $name = str_replace('_', '', $this->getStyle()->styledProperty($name)); return "set{$name}"; } - protected function getAllProperties($object) + protected function getAllProperties(object $object): array { $cols = get_object_vars($object); $ref = new \ReflectionClass($object); @@ -663,27 +610,27 @@ protected function getAllProperties($object) return $cols; } - public function getFilters(Collection $collection) + public function getFilters(Collection $collection): mixed { return $collection->getExtra('filters'); } - public function getMixins(Collection $collection) + public function getMixins(Collection $collection): mixed { return $collection->getExtra('mixins'); } - public function getType(Collection $collection) + public function getType(Collection $collection): mixed { return $collection->getExtra('type'); } - public function mixable(Collection $collection) + public function mixable(Collection $collection): bool { return $collection->have('mixins'); } - public function typable(Collection $collection) + public function typable(Collection $collection): bool { return $collection->have('type'); } - public function filterable(Collection $collection) + public function filterable(Collection $collection): bool { return $collection->have('filters'); } diff --git a/src/Sql.php b/src/Sql.php index b933fc1..5a801e0 100644 --- a/src/Sql.php +++ b/src/Sql.php @@ -9,17 +9,17 @@ class Sql const SQL_OPERATORS = '/\s?(NOT)?\s?(=|==|<>|!=|>|>=|<|<=|LIKE)\s?$/'; const PLACEHOLDER = '?'; - protected $query = ''; - protected $params = array(); + protected string $query = ''; + protected array $params = []; - public static function __callStatic($operation, $parts) + public static function __callStatic(string $operation, array $parts): static { $sql = new static(); - return call_user_func_array(array($sql, $operation), $parts); + return $sql->$operation(...$parts); } - public static function enclose($sql) + public static function enclose(mixed $sql): mixed { if ($sql instanceof self) { $sql->query = '('.trim($sql->query).') '; @@ -30,27 +30,27 @@ public static function enclose($sql) return $sql; } - public function __call($operation, $parts) + public function __call(string $operation, array $parts): static { return $this->preBuild($operation, $parts); } - public function __construct($rawSql = '', array|null $params = null) + public function __construct(string $rawSql = '', array|null $params = null) { $this->setQuery($rawSql, $params); } - public function __toString() + public function __toString(): string { return rtrim($this->query); } - public function getParams() + public function getParams(): array { return $this->params; } - public function setQuery($rawSql, array|null $params = null) + public function setQuery(string $rawSql, array|null $params = null): static { $this->query = $rawSql; if ($params !== null) { @@ -60,7 +60,7 @@ public function setQuery($rawSql, array|null $params = null) return $this; } - public function appendQuery($sql, array|null $params = null) + public function appendQuery(mixed $sql, array|null $params = null): static { $this->query = trim($this->query)." $sql"; if ($sql instanceof self) { @@ -73,19 +73,12 @@ public function appendQuery($sql, array|null $params = null) return $this; } - protected function preBuild($operation, $parts) + protected function preBuild(string $operation, array $parts): static { $raw = ($operation == 'select' || $operation == 'on'); $parts = $this->normalizeParts($parts, $raw); - if (empty($parts)) { - switch ($operation) { - case 'asc': - case 'desc': - case '_': - break; - default: - return $this; - } + if (empty($parts) && !in_array($operation, ['asc', 'desc', '_'], true)) { + return $this; } if ($operation == 'cond') { // condition list @@ -98,42 +91,37 @@ protected function preBuild($operation, $parts) return $this->build($operation, $parts); } - protected function build($operation, $parts) - { - switch ($operation) { //just special cases - case 'select': - return $this->buildAliases($parts); - case 'and': - case 'having': - case 'where': - case 'between': - return $this->buildKeyValues($parts, '%s ', ' AND '); - case 'or': - return $this->buildKeyValues($parts, '%s ', ' OR '); - case 'set': - return $this->buildKeyValues($parts); - case 'on': - return $this->buildComparators($parts, '%s ', ' AND '); - case 'alterTable': - $this->buildFirstPart($parts); - - return $this->buildParts($parts, '%s '); - case 'in': - case 'values': - return $this->buildValuesList($parts); - case 'createTable': - case 'insertInto': - case 'replaceInto': - $this->params = array(); - $this->buildFirstPart($parts); - - return $this->buildParts($parts, '(%s) '); - default: //defaults to any other SQL instruction - return $this->buildParts($parts); - } + protected function build(string $operation, array $parts): static + { + return match ($operation) { + 'select' => $this->buildAliases($parts), + 'and', 'having', 'where', 'between' => $this->buildKeyValues($parts, '%s ', ' AND '), + 'or' => $this->buildKeyValues($parts, '%s ', ' OR '), + 'set' => $this->buildKeyValues($parts), + 'on' => $this->buildComparators($parts, '%s ', ' AND '), + 'in', 'values' => $this->buildValuesList($parts), + 'alterTable' => $this->buildAlterTable($parts), + 'createTable', 'insertInto', 'replaceInto' => $this->buildCreate($parts), + default => $this->buildParts($parts), + }; + } + + private function buildAlterTable(array $parts): static + { + $this->buildFirstPart($parts); + + return $this->buildParts($parts, '%s '); + } + + private function buildCreate(array $parts): static + { + $this->params = []; + $this->buildFirstPart($parts); + + return $this->buildParts($parts, '(%s) '); } - protected function buildKeyValues($parts, $format = '%s ', $partSeparator = ', ') + protected function buildKeyValues(array $parts, string $format = '%s ', string $partSeparator = ', '): static { foreach ($parts as $key => $part) { if (is_numeric($key)) { @@ -151,7 +139,7 @@ protected function buildKeyValues($parts, $format = '%s ', $partSeparator = ', ' return $this->buildParts($parts, $format, $partSeparator); } - protected function buildComparators($parts, $format = '%s ', $partSeparator = ', ') + protected function buildComparators(array $parts, string $format = '%s ', string $partSeparator = ', '): static { foreach ($parts as $key => $part) { if (is_numeric($key)) { @@ -164,7 +152,7 @@ protected function buildComparators($parts, $format = '%s ', $partSeparator = ', return $this->buildParts($parts, $format, $partSeparator); } - protected function buildAliases($parts, $format = '%s ', $partSeparator = ', ') + protected function buildAliases(array $parts, string $format = '%s ', string $partSeparator = ', '): static { foreach ($parts as $key => $part) { if (is_numeric($key)) { @@ -177,7 +165,7 @@ protected function buildAliases($parts, $format = '%s ', $partSeparator = ', ') return $this->buildParts($parts, $format, $partSeparator); } - protected function buildValuesList($parts) + protected function buildValuesList(array $parts): static { foreach ($parts as $key => $part) { if (is_numeric($key) || $part instanceof self) { @@ -190,7 +178,7 @@ protected function buildValuesList($parts) return $this->buildParts($parts, '(%s) ', ', '); } - protected function buildOperation($operation) + protected function buildOperation(string $operation): void { $command = strtoupper(preg_replace('/[A-Z0-9]+/', ' $0', $operation)); if ($command == '_') { @@ -204,12 +192,12 @@ protected function buildOperation($operation) } } - protected function buildFirstPart(&$parts) + protected function buildFirstPart(array &$parts): void { $this->query .= array_shift($parts).' '; } - protected function buildParts($parts, $format = '%s ', $partSeparator = ', ') + protected function buildParts(array $parts, string $format = '%s ', string $partSeparator = ', '): static { if (!empty($parts)) { $this->query .= sprintf($format, implode($partSeparator, $parts)); @@ -218,10 +206,10 @@ protected function buildParts($parts, $format = '%s ', $partSeparator = ', ') return $this; } - protected function normalizeParts($parts, $raw = false) + protected function normalizeParts(array $parts, bool $raw = false): array { $params = & $this->params; - $newParts = array(); + $newParts = []; array_walk_recursive($parts, function ($value, $key) use (&$newParts, &$params, &$raw) { if ($value instanceof Sql) { diff --git a/tests/MapperTest.php b/tests/MapperTest.php index 10fb2c2..37f44df 100644 --- a/tests/MapperTest.php +++ b/tests/MapperTest.php @@ -148,7 +148,7 @@ public function test_get_defined_db_instance() public function test_creating_with_invalid_args_should_throw_exception() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\TypeError::class); $mapper = new Mapper('foo'); }