Skip to content

Commit

Permalink
Remove FunctionResultSet::getClass()
Browse files Browse the repository at this point in the history
  • Loading branch information
emonkak committed Jun 19, 2020
1 parent d7439be commit e57ef26
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/Fetcher/FunctionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Emonkak\Orm\ResultSet\ResultSetInterface;

/**
* @template T of object
* @template T
* @implements FetcherInterface<T>
*/
class FunctionFetcher implements FetcherInterface
Expand All @@ -26,8 +26,8 @@ class FunctionFetcher implements FetcherInterface
private $pdo;

/**
* @psalm-var class-string<T>
* @var callable
* @psalm-var ?class-string<T>
* @var ?string
*/
private $class;

Expand Down Expand Up @@ -59,10 +59,10 @@ function(array $props) use ($class) {
}

/**
* @psalm-param class-string<T> $class
* @psalm-param ?class-string<T> $class
* @psalm-param callable(array<string,mixed>):T $instantiator
*/
public function __construct(PDOInterface $pdo, string $class, callable $instantiator)
public function __construct(PDOInterface $pdo, ?string $class, callable $instantiator)
{
$this->pdo = $pdo;
$this->class = $class;
Expand Down Expand Up @@ -96,6 +96,6 @@ public function getInstantiator(): callable
public function fetch(QueryBuilderInterface $queryBuilder): ResultSetInterface
{
$stmt = $queryBuilder->prepare($this->pdo);
return new FunctionResultSet($stmt, $this->class, $this->instantiator);
return new FunctionResultSet($stmt, $this->instantiator);
}
}
18 changes: 1 addition & 17 deletions src/ResultSet/FunctionResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,21 @@ class FunctionResultSet implements \IteratorAggregate, ResultSetInterface
*/
private $stmt;

/**
* @psalm-var ?class-string<T>
* @var ?class-string
*/
private $class;

/**
* @psalm-var callable(array<string,mixed>):T
* @var callable
*/
private $instantiator;

/**
* @psalm-param ?class-string<T> $class
* @psalm-param callable(array<string,mixed>):T $instantiator
*/
public function __construct(PDOStatementInterface $stmt, ?string $class, callable $instantiator)
public function __construct(PDOStatementInterface $stmt, callable $instantiator)
{
$this->stmt = $stmt;
$this->class = $class;
$this->instantiator = $instantiator;
}

/**
* @psalm-return ?class-string<T>
*/
public function getClass(): ?string
{
return $this->class;
}

/**
* @psalm-return callable(array<string,mixed>):T
*/
Expand Down
1 change: 0 additions & 1 deletion tests/Fetcher/FunctionFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function testFetch(): void
$result = $fetcher->fetch($queryBuilder);

$this->assertInstanceOf(FunctionResultSet::class, $result);
$this->assertEquals($class, $result->getClass());
$this->assertEquals($instantiator, $result->getInstantiator());
}
}
8 changes: 1 addition & 7 deletions tests/ResultSet/FunctionResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ class FunctionResultSetTest extends TestCase
public function setUp(): void
{
$this->stmt = $this->createMock(IterablePDOStatementInterface::class);
$this->class = Model::class;
$this->instantiator = function($props) {
return new Model($props);
};
$this->result = new FunctionResultSet($this->stmt, $this->class, $this->instantiator);
}

public function testGetClass(): void
{
$this->assertSame($this->class, $this->result->getClass());
$this->result = new FunctionResultSet($this->stmt, $this->instantiator);
}

public function testGetInstantiator(): void
Expand Down

0 comments on commit e57ef26

Please sign in to comment.