Skip to content

Commit

Permalink
Add more return type hints (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Michot authored Apr 18, 2020
1 parent 3b7890c commit da434aa
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 30 deletions.
8 changes: 4 additions & 4 deletions docs/tutorial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
public function up()
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
Expand All @@ -198,7 +198,7 @@ class CreatePostsTable extends Migration
});
}

public function down()
public function down(): void
{
Schema::dropIfExists('posts');
}
Expand Down Expand Up @@ -233,7 +233,7 @@ use Illuminate\Database\Migrations\Migration;

class CreateCommentsTable extends Migration
{
public function up()
public function up(): void
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
Expand All @@ -243,7 +243,7 @@ class CreateCommentsTable extends Migration
});
}

public function down()
public function down(): void
{
Schema::dropIfExists('comments');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Execution/Arguments/ArgPartitioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected static function attachNestedArgResolver(string $name, Argument &$argum
* @param \Nuwave\Lighthouse\Execution\Arguments\ArgumentSet $argumentSet
* @return \Nuwave\Lighthouse\Execution\Arguments\ArgumentSet[]
*/
public static function partition(ArgumentSet $argumentSet, \Closure $predicate)
public static function partition(ArgumentSet $argumentSet, \Closure $predicate): array
{
$matched = new ArgumentSet();
$notMatched = new ArgumentSet();
Expand Down
2 changes: 1 addition & 1 deletion src/Execution/Arguments/ArgumentSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function enhanceBuilder($builder, array $scopes, Closure $directiveFilter
* @param \Nuwave\Lighthouse\Execution\Arguments\ArgumentSet $argumentSet
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation $builder
*/
protected static function applyArgBuilderDirectives(self $argumentSet, &$builder, Closure $directiveFilter = null)
protected static function applyArgBuilderDirectives(self $argumentSet, &$builder, Closure $directiveFilter = null): void
{
foreach ($argumentSet->arguments as $argument) {
$value = $argument->toPlain();
Expand Down
4 changes: 2 additions & 2 deletions src/Pagination/PaginationArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Nuwave\Lighthouse\Pagination;

use GraphQL\Error\Error;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Arr;
use Laravel\Scout\Builder as ScoutBuilder;

Expand Down Expand Up @@ -85,9 +86,8 @@ protected static function calculateCurrentPage(int $first, int $after, int $defa
* Apply the args to a builder, constructing a paginator.
*
* @param \Illuminate\Database\Query\Builder $builder
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function applyToBuilder($builder)
public function applyToBuilder($builder): LengthAwarePaginator
{
if ($builder instanceof ScoutBuilder) {
return $builder->paginate($this->first, 'page', $this->page);
Expand Down
5 changes: 2 additions & 3 deletions src/Support/Http/Controllers/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nuwave\Lighthouse\Execution\GraphQLRequest;
use Nuwave\Lighthouse\GraphQL;
use Nuwave\Lighthouse\Support\Contracts\CreatesResponse;
use Symfony\Component\HttpFoundation\Response;

class GraphQLController extends Controller
{
Expand Down Expand Up @@ -46,10 +47,8 @@ public function __construct(

/**
* Execute GraphQL query.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function query(GraphQLRequest $request)
public function query(GraphQLRequest $request): Response
{
$this->eventsDispatcher->dispatch(
new StartRequest($request)
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Http/Middleware/AcceptJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AcceptJson
/**
* Force the Accept header of the request.
*
* @return \Illuminate\Http\JsonResponse
* @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Http\JsonResponse
*/
public function handle(Request $request, Closure $next)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Support/Http/Middleware/AttemptAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public function handle($request, Closure $next, ...$guards)

/**
* Attempt to authenticate the user, but don't do anything if they are not.
*
* @return void
*/
protected function attemptAuthentication(array $guards)
protected function attemptAuthentication(array $guards): void
{
if (empty($guards)) {
$guards = [null];
}

foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
$this->auth->shouldUse($guard);

return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testGetsPolymorphicRelationship(): void
$this->assertCount($first, $tasks->first()->tags);
}

protected function makePaginationArgs(int $first)
protected function makePaginationArgs(int $first): PaginationArgs
{
$paginatorArgs = new PaginationArgs();
$paginatorArgs->first = $first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public function testCanUpsertUsingCreationWithBelongsToMany(): void
$this->assertSame('is_user', $role->name);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function testCanUpsertWithNewBelongsTo(): void
]);
}

public function testUpsertBelongsToWithoutId()
public function testUpsertBelongsToWithoutId(): void
{
$this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL'
mutation {
Expand Down Expand Up @@ -465,7 +465,7 @@ public function testCanUpsertUsingCreateAndUpdateUsingUpsertBelongsTo(): void
]);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function testCanCreateUsingUpsertWithNewHasMany(): void
]);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function testAllowsNullOperations(): void
]);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function testAllowsNullOperations(): void
]);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testAllowsNullOperations(): void
]);
}

public function existingModelMutations()
public function existingModelMutations(): array
{
return [
['Update action' => 'update'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/RouteRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RouteRegistrationTest extends TestCase
* @param \Illuminate\Foundation\Application $app
* @return string[]
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
LighthouseServiceProvider::class,
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ protected function getEnvironmentSetUp($app)
* are fully dumped to the console when making requests.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function resolveApplicationExceptionHandler($app)
protected function resolveApplicationExceptionHandler($app): void
{
$app->singleton(ExceptionHandler::class, function () {
if (AppVersion::atLeast(7.0)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Schema/Directives/CountDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CountDirectiveTest extends TestCase
{
public function testRequireRelationOrModelArgument()
public function testRequireRelationOrModelArgument(): void
{
$this->schema = '
type Query {
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/InterfacesSecondary/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Bar
{
public function resolve()
public function resolve(): void
{
//
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function image(): MorphOne
return $this->morphOne(Image::class, 'imageable');
}

public function scopeWhereTags(Builder $query, $tags)
public function scopeWhereTags(Builder $query, $tags): Builder
{
return $query->whereHas('tags', function (Builder $query) use ($tags) {
$query->whereIn('name', $tags);
Expand Down

0 comments on commit da434aa

Please sign in to comment.