Skip to content

Commit 06cc8e8

Browse files
Add return types to "safe" functions (#3011)
PHP type annotations improve static analysis because static analysis tools can make stronger guarantees about types further down the AST. These type hints are immensely useful for developers using PHP-specific IDEs such as myself. This PR adds type annotations to many functions throughout the codebase where the return type is immediately clear from a brief inspection of the implementation. In addition to clearing nuisance warnings in my IDE, PHPStan analysis is improved as can be seen from some of the more specific errors changed in the PHPStan baseline.
1 parent cafdcf0 commit 06cc8e8

File tree

111 files changed

+615
-1883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+615
-1883
lines changed

app/Console/Commands/AutoRemoveBuilds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct()
3737
/**
3838
* Execute the console command.
3939
*/
40-
public function handle()
40+
public function handle(): void
4141
{
4242
set_time_limit(0);
4343

app/Console/Commands/CheckKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct()
3131
parent::__construct();
3232
}
3333

34-
public function handle()
34+
public function handle(): int
3535
{
3636
if (trim(config('app.key')) === '') {
3737
echo 'Error: APP_KEY environment variable is not set. You can use the following randomly generated key:' . PHP_EOL;

app/Console/Commands/MakeStorageDirectories.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ class MakeStorageDirectories extends Command
2222

2323
/**
2424
* Execute the console command.
25-
*
26-
* @return int
2725
*/
28-
public function handle()
26+
public function handle(): int
2927
{
3028
$storage_path = storage_path();
3129
$dirs_to_check = [

app/Console/Commands/PurgeUnusedProjects.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public function __construct()
3333

3434
/**
3535
* Execute the console command.
36-
*
37-
* @return void
3836
*/
39-
public function handle()
37+
public function handle(): void
4038
{
4139
foreach (Project::doesntHave('builds')->get() as $project) {
4240
echo 'Deleting project: ' . $project->name . PHP_EOL;

app/Console/Commands/QueueSubmissions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct()
3737
/**
3838
* Execute the console command.
3939
*/
40-
public function handle()
40+
public function handle(): void
4141
{
4242
// Queue the "build metadata" JSON files first, so they have a chance
4343
// to get parsed before the subsequent payload files.
@@ -57,7 +57,7 @@ public function handle()
5757
}
5858
}
5959

60-
private function queueFile($inboxFile)
60+
private function queueFile($inboxFile): void
6161
{
6262
$filename = str_replace('inbox/', '', $inboxFile);
6363
$pos = strpos($filename, '_-_');

app/Console/Commands/RemoveUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct()
3434
/**
3535
* Execute the console command.
3636
*/
37-
public function handle()
37+
public function handle(): void
3838
{
3939
$email = $this->option('email');
4040
if (is_null($email)) {

app/Console/Commands/SaveUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct()
3434
/**
3535
* Create or update a user.
3636
*/
37-
public function handle()
37+
public function handle(): void
3838
{
3939
$email = $this->option('email');
4040
if (is_null($email)) {

app/Http/Controllers/BuildController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public function targets(int $build_id): View
4747
}
4848

4949
// Render the build configure page.
50-
public function configure($build_id = null)
50+
public function configure($build_id = null): View
5151
{
5252
return $this->renderBuildPage($build_id, 'configure');
5353
}
5454

5555
// Render the build notes page.
56-
public function notes($build_id = null)
56+
public function notes($build_id = null): View
5757
{
5858
$this->setBuildById($build_id);
5959

@@ -63,7 +63,7 @@ public function notes($build_id = null)
6363
}
6464

6565
// Render the build summary page.
66-
public function summary($build_id = null)
66+
public function summary($build_id = null): View
6767
{
6868
return $this->renderBuildPage($build_id, 'summary', 'Build Summary');
6969
}
@@ -85,7 +85,7 @@ public function tests(int $build_id): View
8585
]);
8686
}
8787

88-
protected function renderBuildPage(int $build_id, string $page_name, string $page_title = '')
88+
protected function renderBuildPage(int $build_id, string $page_name, string $page_title = ''): View
8989
{
9090
$this->setBuildById($build_id);
9191
if ($page_title === '') {

app/Http/Controllers/CDash.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ protected function getRequestContents()
108108
/**
109109
* Returns JSON responses for CDash API requests or regular response given an
110110
* un-decodable json response
111-
*
112-
* @return ResponseFactory|JsonResponse|Response|\Symfony\Component\HttpFoundation\Response
113111
*/
114-
protected function handleApiRequest()
112+
protected function handleApiRequest(): Response|JsonResponse|\Symfony\Component\HttpFoundation\Response|ResponseFactory
115113
{
116114
$json = $this->getRequestContents();
117115
$status = http_response_code(); // this should be empty if not previously set

app/Http/Controllers/EditProjectController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
namespace App\Http\Controllers;
44

55
use Illuminate\Support\Facades\Gate;
6+
use Illuminate\View\View;
67

78
final class EditProjectController extends AbstractProjectController
89
{
910
// Render the create project form.
10-
public function create()
11+
public function create(): View
1112
{
1213
Gate::authorize('create-project');
1314

1415
return $this->vue('edit-project', 'Create Project', ['projectid' => 0], false);
1516
}
1617

1718
// Render the edit project form.
18-
public function edit($project_id)
19+
public function edit($project_id): View
1920
{
2021
$this->setProjectById((int) $project_id);
2122
Gate::authorize('edit-project', $this->project);

0 commit comments

Comments
 (0)