diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6f032f6d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# @see https://git-scm.com/docs/gitattributes +# when you composer-require this library with --prefer-dist the tests will not be part of the installed vendor code +# making your final package smaller in size and therefore faster to build and deploy + +# git files +.github/ export-ignore +.gitattributes export-ignore +.gitignore export-ignore + +# testing and other +tests/ export-ignore +phpunit.xml.dist export-ignore +phpunit.php export-ignore +composer.lock export-ignore +.scrutinizer.yml export-ignore + +# code style +.editorconfig export-ignore + +# license +LICENSE export-ignore +CONTRIBUTING.md export-ignore diff --git a/README.md b/README.md index 03b71e8f..0b101539 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Alternatively, [download a release][], or clone this repository, then map the ## Dependencies -This package requires PHP 8.1 or later; it has been tested on PHP 8.1. +This package requires PHP 8.1 or later; it has also been tested on PHP 8.1. We recommend using the latest available version of PHP as a matter of principle. diff --git a/composer.json b/composer.json index fb5d5d74..54389b3c 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "require-dev": { "pds/skeleton": "~1.0", - "phpunit/phpunit": "~5.7|~9.5" + "phpunit/phpunit": "^9.5" }, "autoload-dev": { "psr-4": { diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 204611a0..cb28bbc2 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -200,12 +200,12 @@ public function errorInfo(): array * * @param string $statement The SQL statement to prepare and execute. * - * @return int The number of affected rows. + * @return int|false The number of affected rows. * * @see http://php.net/manual/en/pdo.exec.php * */ - public function exec(string $statement): int + public function exec(string $statement): int|false { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -344,7 +344,7 @@ public function fetchObject( array $values = [], string $class = 'stdClass', array $args = [] - ): object { + ): object|false { $sth = $this->perform($statement, $values); if (! empty($args)) { @@ -567,12 +567,12 @@ public function perform(string $statement, array $values = []): PDOStatement * @param array $options Set these attributes on the returned * PDOStatement. * - * @return PDOStatement + * @return PDOStatement|false * * @see http://php.net/manual/en/pdo.prepare.php * */ - public function prepare(string $query, array $options = []): PDOStatement + public function prepare(string $query, array $options = []): PDOStatement|false { $this->connect(); $sth = $this->pdo->prepare($query, $options); @@ -638,12 +638,12 @@ public function prepareWithValues(string $statement, array $values = []): PDOSta * * @param mixed ...$fetch_mode_args Optional fetch-related parameters. * - * @return PDOStatement + * @return PDOStatement|false * * @see http://php.net/manual/en/pdo.query.php * */ - public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement + public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mode_args): PDOStatement|false { $this->connect(); $this->profiler->start(__FUNCTION__); @@ -663,12 +663,12 @@ public function query(string $query, ?int $fetchMode = null, mixed ...$fetch_mod * * @param int $type A data type hint for the database driver. * - * @return string The quoted value. + * @return string|false The quoted value or false if the driver does not support quoting in this way. * * @see http://php.net/manual/en/pdo.quote.php * */ - public function quote(string|int|array|float|null $value, int $type = self::PARAM_STR): string + public function quote(string|int|array|float|null $value, int $type = self::PARAM_STR): string|false { $this->connect(); @@ -697,7 +697,7 @@ public function quote(string|int|array|float|null $value, int $type = self::PARA */ public function quoteName(string $name): string { - if (strpos($name, '.') === false) { + if (!str_contains($name, '.')) { return $this->quoteSingleName($name); } diff --git a/src/ExtendedPdoInterface.php b/src/ExtendedPdoInterface.php index e82ae94a..88196a50 100644 --- a/src/ExtendedPdoInterface.php +++ b/src/ExtendedPdoInterface.php @@ -135,7 +135,7 @@ public function fetchGroup( * * @param array $args Arguments to pass to the object constructor. * - * @return object + * @return object|false * */ public function fetchObject( @@ -143,7 +143,7 @@ public function fetchObject( array $values = [], string $class = 'stdClass', array $args = [] - ): object; + ): object|false; /** * diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 463f33a1..c04a43ba 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -298,8 +298,6 @@ public function testFetchObject() $stm = "SELECT id, name FROM pdotest WHERE id = ?"; $actual = $this->pdo->fetchObject($stm, [1]); - // in php <= 8 id is a string, in php >= 8.1 it is a int - // https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131 $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); } @@ -313,8 +311,7 @@ public function testFetchObject_withCtorArgs() 'Aura\Sql\FakeObject', ['bar'] ); - // in php <= 8 id is a string, in php >= 8.1 it is a int - // https://github.com/php/php-src/blob/PHP-8.1/UPGRADING#L131 + $this->assertSame(1, $actual->id); $this->assertSame('Anna', $actual->name); $this->assertSame('bar', $actual->foo); @@ -334,6 +331,12 @@ public function testFetchObjects() $this->assertEquals($expect, $actual); } + public function testFetchObjectWithNoResult() + { + $stm = "SELECT * FROM pdotest where 0"; + $this->assertFalse($this->pdo->fetchObject($stm)); + } + public function testYieldObjects() { $stm = "SELECT * FROM pdotest";