Skip to content

Commit

Permalink
Fix more PHPstan
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-boudry committed Sep 30, 2024
1 parent e189ce4 commit 1d537ef
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"cast_spaces": true,
"class_reference_name_casing": true,
"combine_consecutive_issets": true,
"comment_to_phpdoc": true,
"constant_case": true,
"declare_strict_types": true,
"dir_constant": true,
Expand Down
3 changes: 3 additions & 0 deletions src/DataDrivers/DataDriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace MammothPHP\WoollyM\DataDrivers;

use Countable;
use Iterator;
use IteratorAggregate;

interface DataDriverInterface extends Countable, IteratorAggregate
{
public const ColumnKeyType COLUMN_KEY_TYPE = ColumnKeyType::COLUMN_KEY;

public function getIterator(): Iterator;

public function getRecordKey(int $recordKey): array;

// public function getRecordColumn(int $recordKey, int $columnKey): mixed;
Expand Down
5 changes: 2 additions & 3 deletions src/DataDrivers/PdoSql/PdoSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use MammothPHP\WoollyM\Exceptions\{FeatureNotImplementedYet, NotYetImplementedException};
use PDO;
use PDOStatement;
use Traversable;

/**
* @internal
Expand Down Expand Up @@ -88,14 +87,14 @@ protected function escapeColumnName(string $columnName): string
return trim(str_replace("'", '', $this->db->quote($columnName)));
}

public function getIterator(): Traversable
public function getIterator(): Iterator
{
$stmt = $this->db->query('SELECT * FROM ' . $this->escapeTableName() . ';');
$stmt->setFetchMode(PDO::FETCH_ASSOC);

$iterator = $stmt->getIterator();

return new class ($iterator, $this->keyColumn) implements Iterator {
return new class ($iterator, $this->keyColumn) implements Iterator { // @phpstan-ignore argument.type (phpstan bug)
public function __construct(public readonly Iterator $iterator, public readonly string $keyColumn) {}

public function current(): mixed
Expand Down
2 changes: 1 addition & 1 deletion src/IO/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function insertInto(string $tableName): int

try {
$this->identifyAnyMissingColumns($columns, $tableName);
} catch (PDOException) {
} catch (PDOException) { // @phpstan-ignore catch.neverThrown
// If this function throws a PDO exception then it's probably just a unit test running a SQLite query
// SQLite doesn't support "show columns like" syntax
} catch (InvalidSelectException $ice) {
Expand Down
2 changes: 1 addition & 1 deletion src/IO/XLSX.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class XLSX extends Builder

public function import(DataFrame $to = new DataFrame): DataFrame
{
$fileName = $this->file?->getPathname() ?? $this->input ?? false;
$fileName = $this->file?->getPathname() ?? $this->input ?? false; // @phpstan-ignore nullsafe.neverNull (phpstan bug, syntax also deal with unset properties)

if ($fileName === false) {
throw new NotYetImplementedException('Invalid file');
Expand Down

0 comments on commit 1d537ef

Please sign in to comment.