Skip to content

Commit

Permalink
Added property and return types in all places
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Feb 25, 2023
1 parent 8d9c698 commit 421fd2b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGE LOG
* Support Laravel 8-10 only
* `FacadeTrait` methods `getFacadeAccessor`, `getFacadeClass`, `getFacadeRoot` and `getServiceProviderClass` are now `static`
* `ServiceProviderTrait::getServiceProviderClass` is now `static` and no longer receives app as param 1
* Added property and return types in all places


## V3.4.1 (25/02/2023)
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/ArraySubset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ final class ArraySubset extends Constraint
/**
* @var iterable
*/
private $subset;
private iterable $subset;

/**
* @var bool
*/
private $strict;
private bool $strict;

/**
* Create a new array subset constraint instance.
Expand Down
16 changes: 8 additions & 8 deletions src/FacadeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ trait FacadeTrait
*
* @return string
*/
abstract protected static function getFacadeAccessor();
abstract protected static function getFacadeAccessor(): string;

/**
* Get the facade class.
*
* @return string
*/
abstract protected static function getFacadeClass();
abstract protected static function getFacadeClass(): string;

/**
* Get the facade root.
*
* @return string
*/
abstract protected static function getFacadeRoot();
abstract protected static function getFacadeRoot(): string;

/**
* Get the service provider class.
*
* @return string
*/
abstract protected static function getServiceProviderClass();
abstract protected static function getServiceProviderClass(): string;

public function testIsAFacade()
public function testIsAFacade(): void
{
$class = static::getFacadeClass();
$reflection = new ReflectionClass($class);
Expand All @@ -64,7 +64,7 @@ public function testIsAFacade()
static::assertTrue($reflection->isSubclassOf($facade), $msg);
}

public function testFacadeAccessor()
public function testFacadeAccessor(): void
{
$accessor = static::getFacadeAccessor();
$class = static::getFacadeClass();
Expand All @@ -77,7 +77,7 @@ public function testFacadeAccessor()
static::assertSame($accessor, $method->invoke(null), $msg);
}

public function testFacadeRoot()
public function testFacadeRoot(): void
{
$root = static::getFacadeRoot();
$class = static::getFacadeClass();
Expand All @@ -90,7 +90,7 @@ public function testFacadeRoot()
static::assertInstanceOf($root, $method->invoke(null), $msg);
}

public function testServiceProvider()
public function testServiceProvider(): void
{
$accessor = static::getFacadeAccessor();
$provider = static::getServiceProviderClass($this->app);
Expand Down
6 changes: 3 additions & 3 deletions src/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait HelperTrait
*
* @return void
*/
public static function assertInArray($needle, array $haystack, string $msg = '')
public static function assertInArray($needle, array $haystack, string $msg = ''): void
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
Expand All @@ -52,7 +52,7 @@ public static function assertInArray($needle, array $haystack, string $msg = '')
*
* @return void
*/
public static function assertMethodExists(string $method, string $class, string $msg = '')
public static function assertMethodExists(string $method, string $class, string $msg = ''): void
{
if ($msg === '') {
$msg = "Expected the class '$class' to have method '$method'.";
Expand All @@ -72,7 +72,7 @@ public static function assertMethodExists(string $method, string $class, string
*
* @return void
*/
public static function assertInJson(string $needle, array $haystack, string $msg = '')
public static function assertInJson(string $needle, array $haystack, string $msg = ''): void
{
if ($msg === '') {
$msg = "Expected the array to contain the element '$needle'.";
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait LaravelTrait
*
* @return void
*/
public function assertIsInjectable(string $name)
public function assertIsInjectable(string $name): void
{
$injectable = true;

Expand All @@ -56,7 +56,7 @@ public function assertIsInjectable(string $name)
*
* @return object
*/
protected function makeInjectableClass(string $name)
protected function makeInjectableClass(string $name): object
{
do {
$class = 'testBenchStub'.Str::random();
Expand Down
2 changes: 1 addition & 1 deletion src/MockeryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait MockeryTrait
*
* @return void
*/
public function tearDownMockery()
public function tearDownMockery(): void
{
if (class_exists(Mockery::class, false)) {
$container = Mockery::getContainer();
Expand Down
6 changes: 3 additions & 3 deletions src/ServiceProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ trait ServiceProviderTrait
*
* @return string
*/
abstract protected static function getServiceProviderClass();
abstract protected static function getServiceProviderClass(): string;

public function testIsAServiceProvider()
public function testIsAServiceProvider(): void
{
$class = static::getServiceProviderClass();

Expand All @@ -44,7 +44,7 @@ public function testIsAServiceProvider()
static::assertTrue($reflection->isSubclassOf($provider), $msg);
}

public function testProvides()
public function testProvides(): void
{
$class = static::getServiceProviderClass();
$reflection = new ReflectionClass($class);
Expand Down
4 changes: 2 additions & 2 deletions tests/AnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AnalysisTest extends TestCase
*
* @return string[]
*/
protected static function getPaths()
protected static function getPaths(): array
{
return [
realpath(__DIR__.'/../src'),
Expand All @@ -44,7 +44,7 @@ protected static function getPaths()
*
* @return string[]
*/
protected static function getIgnored()
protected static function getIgnored(): array
{
return [
Application::class,
Expand Down
20 changes: 10 additions & 10 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,61 @@ class HelpersTest extends TestCase
{
use HelperTrait;

public function testInArray()
public function testInArray(): void
{
self::assertInArray('foo', ['foo']);
}

public function testNotInArray()
public function testNotInArray(): void
{
self::expectException(ExpectationFailedException::class);
self::assertInArray('foo', ['bar']);
}

public function testMethodDoesExist()
public function testMethodDoesExist(): void
{
self::assertMethodExists('getBar', FooStub::class);
}

public function testMethodDoesNotExist()
public function testMethodDoesNotExist(): void
{
self::expectException(ExpectationFailedException::class);
self::assertMethodExists('getFoo', FooStub::class);
}

public function testInJson()
public function testInJson(): void
{
self::assertInJson('{"foo":"bar"}', ['foo' => 'bar']);
self::assertInJson('{ "foo": "bar", "bar": "baz" }', ['foo' => 'bar']);
self::assertInJson('{ "foo": "bar", "bar": "baz" }', ['bar' => 'baz']);
}

public function testNotInJsonOne()
public function testNotInJsonOne(): void
{
self::expectException(ExpectationFailedException::class);
self::assertInJson('{"foo":"baz"}', ['foo' => 'bar']);
}

public function testNotInJsonTwo()
public function testNotInJsonTwo(): void
{
self::expectException(ExpectationFailedException::class);
self::assertInJson('{ "foo": "bar", "bar": "baz" }', ['foo' => 'baz']);
}

public function testBadJsonInNotInJson()
public function testBadJsonInNotInJson(): void
{
self::expectException(InvalidArgumentException::class);
self::assertInJson('foobar', ['foo' => 'bar']);
}

public function testAssertArraySubsetBadArg1()
public function testAssertArraySubsetBadArg1(): void
{
$this->expectException(TypeError::class);

self::assertArraySubset(123, []);
}

public function testAssertArraySubsetBadArg2()
public function testAssertArraySubsetBadArg2(): void
{
$this->expectException(TypeError::class);

Expand Down

0 comments on commit 421fd2b

Please sign in to comment.