Skip to content

Commit

Permalink
rename some things
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Mar 29, 2024
1 parent c39d7e6 commit 19677a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/CallbackType.php → src/Prototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function array_map;
use function get_class;

final class CallbackType{
final class Prototype{
private ReturnInfo $returnInfo;

/** @var ParameterInfo[] */
Expand Down Expand Up @@ -46,7 +46,7 @@ private static function convertReflectionType(?\ReflectionType $type) : ?BaseTyp
return $type === null ? null : self::convertReflectionTypeInner($type);
}

public static function createFromCallable(\Closure $callable) : CallbackType{
public static function createFromCallable(\Closure $callable) : Prototype{
$reflection = new \ReflectionFunction($callable);

$returnType = new ReturnInfo(self::convertReflectionType($reflection->getReturnType()), $reflection->returnsReference());
Expand All @@ -63,7 +63,7 @@ public static function createFromCallable(\Closure $callable) : CallbackType{
);
}

return new CallbackType($returnType, ...$parameters);
return new Prototype($returnType, ...$parameters);
}

public function __construct(ReturnInfo $returnType, ParameterInfo ...$parameters){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace DaveRandom\CallbackValidator\Test\Base;

use DaveRandom\CallbackValidator\CallbackType;
use DaveRandom\CallbackValidator\Prototype;
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface1;
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface2;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class CallbackTypeTest extends TestCase{
class PrototypeTest extends TestCase{

public static function returnCovarianceProvider() : \Generator{
//anything is covariant with void in a return type, at least for the purposes of callbacks
Expand Down Expand Up @@ -81,10 +81,10 @@ public static function paramContravarianceProvider() : \Generator{
#[DataProvider('returnCovarianceProvider')]
#[DataProvider('paramContravarianceProvider')]
public function testCompatibility(\Closure $required, \Closure $given, bool $matches, string $reason) : void{
$required = CallbackType::createFromCallable($required);
$required = Prototype::createFromCallable($required);

$serializedRequire = (string) $required;
$serializedGiven = (string) CallbackType::createFromCallable($given);
$serializedGiven = (string) Prototype::createFromCallable($given);
self::assertSame($required->isSatisfiedBy($given), $matches, $reason . " ($serializedRequire, $serializedGiven)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace DaveRandom\CallbackValidator\Test\Php82;

use DaveRandom\CallbackValidator\CallbackType;
use DaveRandom\CallbackValidator\Prototype;
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface1;
use DaveRandom\CallbackValidator\Test\Base\Fixtures\Interface2;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class CallbackTypeTest extends TestCase{
class PrototypeTest extends TestCase{

public static function returnCovarianceProvider() : \Generator{
//DNF types - PHP 8.2+ only
Expand All @@ -27,10 +27,10 @@ public static function paramContravarianceProvider() : \Generator{
#[DataProvider('returnCovarianceProvider')]
#[DataProvider('paramContravarianceProvider')]
public function testCompatibility(\Closure $required, \Closure $given, bool $matches, string $reason) : void{
$required = CallbackType::createFromCallable($required);
$required = Prototype::createFromCallable($required);

$serializedRequire = (string) $required;
$serializedGiven = (string) CallbackType::createFromCallable($given);
$serializedGiven = (string) Prototype::createFromCallable($given);
self::assertSame($required->isSatisfiedBy($given), $matches, $reason . " ($serializedRequire, $serializedGiven)");
}
}

0 comments on commit 19677a2

Please sign in to comment.