Skip to content

Commit

Permalink
Add generics to BaseRack and its children
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Aug 22, 2024
1 parent 3b6a13a commit aaa61d5
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases).

## Unreleased

## v4.1.0

### Added

- Add generics to `BaseRack` and its children

## v4.0.0

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/AlublockA.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class AlublockA extends BaseRack
{
public function type(): string
Expand Down
9 changes: 5 additions & 4 deletions src/Tecan/Rack/BaseRack.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Support\Collection;

/** @template TContent */
abstract class BaseRack implements Rack
{
public const EMPTY_POSITION = null;

/** @var Collection<int, mixed> */
/** @var Collection<int, TContent|null> */
public Collection $positions;

public function __construct()
Expand All @@ -31,13 +32,13 @@ public function toString(): string
]);
}

/** @param mixed $content Anything goes, null is considered empty */
/** @param TContent|null $content Anything goes, null is considered empty */
public function assignFirstEmptyPosition($content): int
{
return $this->assignPosition($content, $this->findFirstEmptyPosition());
}

/** @param mixed $content Anything goes, null is considered empty */
/** @param TContent|null $content Anything goes, null is considered empty */
public function assignLastEmptyPosition($content): int
{
return $this->assignPosition($content, $this->findLastEmptyPosition());
Expand Down Expand Up @@ -71,7 +72,7 @@ public function findLastEmptyPosition(): int
return $lastEmpty;
}

/** @param mixed $content Anything goes, null is considered empty */
/** @param TContent|null $content Anything goes, null is considered empty */
public function assignPosition($content, int $position): int
{
if (! $this->positions->has($position)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/DestLC.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class DestLC extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/DestPCR.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class DestPCR extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/DestTaqMan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class DestTaqMan extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/FluidXRack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class FluidXRack extends BaseRack implements ScannedRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/MPCDNA.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class MPCDNA extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/MPSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class MPSample extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/MPWater.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class MPWater extends BaseRack
{
public function type(): string
Expand Down
5 changes: 5 additions & 0 deletions src/Tecan/Rack/MasterMixRack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace MLL\Utils\Tecan\Rack;

/**
* @template TContent
*
* @extends BaseRack<TContent>
*/
class MasterMixRack extends BaseRack
{
public function type(): string
Expand Down
8 changes: 6 additions & 2 deletions tests/Tecan/Rack/RackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testThrowsExceptionForInvalidPosition(): void
$rack->assignPosition('Sample', $lastPosition + 1);
}

/** @return iterable<string, array{BaseRack, string, string, int}> */
/** @return iterable<string, array{BaseRack<mixed>, string, string, int}> */
public static function rackDataProvider(): iterable
{
yield 'MPCDNA' => [new MPCDNA(), 'MPCDNA', 'MP cDNA', 96];
Expand All @@ -76,7 +76,11 @@ public static function rackDataProvider(): iterable
yield 'MPWater' => [new MPWater(), 'MPWasser', 'Trough 300ml MCA Portrait', 1];
}

/** @dataProvider rackDataProvider */
/**
* @param BaseRack<mixed> $rack
*
* @dataProvider rackDataProvider
*/
#[DataProvider('rackDataProvider')]
public function testRackProperties(BaseRack $rack, string $expectedName, string $expectedType, int $expectedPositionCount): void
{
Expand Down

0 comments on commit aaa61d5

Please sign in to comment.