Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| MydbMysqliResult | |
100.00% |
15 / 15 |
|
100.00% |
7 / 7 |
13 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getFieldCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getWarnings | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setErrorMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setErrorNumber | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getError | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 | |||
| getResult | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the sshilko/php-sql-mydb package. |
| 4 | * |
| 5 | * (c) Sergei Shilko <contact@sshilko.com> |
| 6 | * |
| 7 | * MIT License |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | * @license https://opensource.org/licenses/mit-license.php MIT |
| 12 | */ |
| 13 | |
| 14 | declare(strict_types = 1); |
| 15 | |
| 16 | namespace sql\MydbMysqli; |
| 17 | |
| 18 | use mysqli_result; |
| 19 | use const MYSQLI_ASSOC; |
| 20 | |
| 21 | /** |
| 22 | * @author Sergei Shilko <contact@sshilko.com> |
| 23 | * @license https://opensource.org/licenses/mit-license.php MIT |
| 24 | * @see https://github.com/sshilko/php-sql-mydb |
| 25 | * @access protected |
| 26 | */ |
| 27 | class MydbMysqliResult implements MydbMysqliResultInterface |
| 28 | { |
| 29 | protected const MYSQLI_ASSOC = MYSQLI_ASSOC; |
| 30 | |
| 31 | protected ?array $result = null; |
| 32 | |
| 33 | /** |
| 34 | * @psalm-var array<array-key, string> |
| 35 | * @phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion |
| 36 | */ |
| 37 | protected array $warnings; |
| 38 | |
| 39 | protected ?string $errorMessage = null; |
| 40 | |
| 41 | protected int $errorNumber = 0; |
| 42 | |
| 43 | /** |
| 44 | * @psalm-param array<array-key, string> $warnings |
| 45 | */ |
| 46 | public function __construct(?mysqli_result $result, array $warnings, protected int $fieldsCount) |
| 47 | { |
| 48 | if (null !== $result) { |
| 49 | $this->result = $result->fetch_all(self::MYSQLI_ASSOC); |
| 50 | $result->free(); |
| 51 | } |
| 52 | |
| 53 | $this->warnings = $warnings; |
| 54 | } |
| 55 | |
| 56 | public function getFieldCount(): int |
| 57 | { |
| 58 | return $this->fieldsCount; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @psalm-return array<array-key, string> |
| 63 | */ |
| 64 | public function getWarnings(): array |
| 65 | { |
| 66 | return $this->warnings; |
| 67 | } |
| 68 | |
| 69 | public function setErrorMessage(string $errorMessage): void |
| 70 | { |
| 71 | $this->errorMessage = $errorMessage; |
| 72 | } |
| 73 | |
| 74 | public function setErrorNumber(int $errorNumber): void |
| 75 | { |
| 76 | $this->errorNumber = $errorNumber; |
| 77 | } |
| 78 | |
| 79 | public function getError(): ?string |
| 80 | { |
| 81 | if ($this->result) { |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | if ($this->errorNumber > 0 || null !== $this->errorMessage) { |
| 86 | if (null !== $this->errorMessage && '' !== $this->errorMessage) { |
| 87 | return ((string) $this->errorNumber) . ' ' . $this->errorMessage; |
| 88 | } |
| 89 | |
| 90 | // @codeCoverageIgnoreStart |
| 91 | return (string) $this->errorNumber; |
| 92 | // @codeCoverageIgnoreEnd |
| 93 | } |
| 94 | |
| 95 | return null; |
| 96 | } |
| 97 | |
| 98 | public function getResult(): ?array |
| 99 | { |
| 100 | return $this->result; |
| 101 | } |
| 102 | } |