Add type hints for Laravel 10

This commit is contained in:
Shift
2024-02-16 21:13:13 +00:00
parent 8725493fcf
commit 2cb837e4b5
44 changed files with 82 additions and 79 deletions

View File

@@ -38,7 +38,7 @@ class RegisterApp extends Command
*
* @return void
*/
public function handle()
public function handle(): void
{
$folder = $this->argument('folder');
if ($folder == 'all') {

View File

@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
* @param Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')
// ->hourly();
@@ -24,7 +24,7 @@ class Kernel extends ConsoleKernel
*
* @return void
*/
protected function commands()
protected function commands(): void
{
$this->load(__DIR__.'/Commands');

View File

@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use Symfony\Component\HttpFoundation\Response;
use App\User;
use Closure;
use Illuminate\Auth\AuthenticationException;
@@ -20,7 +21,7 @@ class CheckAllowed
* @return mixed
* @throws AuthenticationException
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): Response
{
$route = Route::currentRouteName();
$current_user = User::currentUser();

View File

@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use Symfony\Component\HttpFoundation\Response;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -16,7 +17,7 @@ class RedirectIfAuthenticated
* @param string|null $guard
* @return mixed
*/
public function handle(Request $request, Closure $next, string $guard = null)
public function handle(Request $request, Closure $next, string $guard = null): Response
{
if (Auth::guard($guard)->check()) {
return redirect()->intended();

View File

@@ -35,7 +35,7 @@ class ProcessApps implements ShouldQueue, ShouldBeUnique
* @return void
* @throws GuzzleException
*/
public function handle()
public function handle(): void
{
Log::debug('Process Apps dispatched');
$localapps = Application::whereNull('class')->get();

View File

@@ -33,7 +33,7 @@ class UpdateApps implements ShouldQueue, ShouldBeUnique
* @return void
* @throws GuzzleException
*/
public function handle()
public function handle(): void
{
Log::debug('Update of all apps triggered!');
$apps = Application::all('appid')->toArray();

View File

@@ -22,7 +22,7 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
if (! class_exists('ZipArchive')) {
die('You are missing php-zip');
@@ -122,7 +122,7 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function register()
public function register(): void
{
if ($this->app->isLocal()) {
$this->app->register(IdeHelperServiceProvider::class);

View File

@@ -20,7 +20,7 @@ class AuthServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
//
}

View File

@@ -22,7 +22,7 @@ class EventServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
parent::boot();
@@ -34,7 +34,7 @@ class EventServiceProvider extends ServiceProvider
*
* @return bool
*/
public function shouldDiscoverEvents()
public function shouldDiscoverEvents(): bool
{
return false;
}

View File

@@ -20,7 +20,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
//

View File

@@ -16,7 +16,7 @@ class UserFactory extends Factory
*/
protected static ?string $password;
public function definition()
public function definition(): array
{
return [
'username' => $this->faker->name(),

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
@@ -32,7 +32,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('items');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
@@ -31,7 +31,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('settings');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('setting_groups', function (Blueprint $table) {
$table->increments('id');
@@ -25,7 +25,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('setting_groups');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('items', function (Blueprint $table) {
$table->integer('type')->default(0)->index(); // 0 = item, 1 = category
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn(['type']);

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('item_tag', function (Blueprint $table) {
$table->integer('item_id')->unsigned()->index();
@@ -28,7 +28,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('item_tag');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
@@ -31,7 +31,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('users');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
@@ -25,7 +25,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('password_resets');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('items', function (Blueprint $table) {
$table->integer('user_id')->default(1)->index(); // 0 = item, 1 = category
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn(['user_id']);

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('setting_user', function (Blueprint $table) {
$table->integer('setting_id')->unsigned()->index();
@@ -28,7 +28,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('setting_user');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('applications', function (Blueprint $table) {
$table->string('appid')->unique();
@@ -33,7 +33,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('applications');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('items', function (Blueprint $table) {
$table->string('class')->nullable();
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn(['class']);

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
@@ -29,7 +29,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('jobs');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
@@ -28,7 +28,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('failed_jobs');
}

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('items', function (Blueprint $table) {
$table->string('appid')->nullable();
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn(['appid']);

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->string('class')->nullable()->index();
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->dropColumn(['class']);

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('items', function (Blueprint $table) {
$table->text('appdescription')->nullable();
@@ -23,7 +23,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
//

View File

@@ -11,7 +11,7 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::rename('password_resets', 'password_reset_tokens');
}
@@ -21,7 +21,7 @@ return new class extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
Schema::rename('password_reset_tokens', 'password_resets');
}

View File

@@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder
*
* @return void
*/
public function run()
public function run(): void
{
$this->call(SettingsSeeder::class);
$this->call(UsersSeeder::class);

View File

@@ -55,7 +55,7 @@ class SettingsSeeder extends Seeder
*
* @return void
*/
public function run()
public function run(): void
{
// Groups
if (! $setting_group = SettingGroup::find(1)) {

View File

@@ -12,7 +12,7 @@ class UsersSeeder extends Seeder
*
* @return void
*/
public function run()
public function run(): void
{
// Groups
if (!User::find(1)) {

View File

@@ -2,6 +2,7 @@
namespace Tests;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
@@ -11,7 +12,7 @@ trait CreatesApplication
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';

View File

@@ -42,7 +42,7 @@ class DashTest extends TestCase
* Test Cases
*/
public function test_loads_empty_dash()
public function test_loads_empty_dash(): void
{
$this->seed();
@@ -51,7 +51,7 @@ class DashTest extends TestCase
$response->assertStatus(200);
}
public function test_displays_items_on_the_dash()
public function test_displays_items_on_the_dash(): void
{
$this->seed();
@@ -67,7 +67,7 @@ class DashTest extends TestCase
$response->assertSee('Item 3');
}
public function test_displays_tags_on_the_dash()
public function test_displays_tags_on_the_dash(): void
{
$this->seed();

View File

@@ -9,7 +9,7 @@ class ItemCreateTest extends TestCase
{
use RefreshDatabase;
public function test_displays_the_item_create_page()
public function test_displays_the_item_create_page(): void
{
$this->seed();
@@ -18,7 +18,7 @@ class ItemCreateTest extends TestCase
$response->assertStatus(200);
}
public function test_display_the_home_dashboard_tag()
public function test_display_the_home_dashboard_tag(): void
{
$this->seed();
@@ -27,7 +27,7 @@ class ItemCreateTest extends TestCase
$response->assertSee('Home dashboard');
}
public function test_creates_a_new_item()
public function test_creates_a_new_item(): void
{
$this->seed();
$item = [
@@ -46,7 +46,7 @@ class ItemCreateTest extends TestCase
$response->assertSee('Redirecting to');
}
public function test_redirects_to_dash_when_adding_a_new_item()
public function test_redirects_to_dash_when_adding_a_new_item(): void
{
$this->seed();
$item = [

View File

@@ -10,7 +10,7 @@ class ItemDeleteTest extends TestCase
{
use RefreshDatabase;
public function test_deletes_an_item()
public function test_deletes_an_item(): void
{
$this->seed();
$item = Item::factory()
@@ -23,7 +23,7 @@ class ItemDeleteTest extends TestCase
$response->assertStatus(302);
}
public function test_redirects_to_item_list_page_when_deleting_an_item()
public function test_redirects_to_item_list_page_when_deleting_an_item(): void
{
$this->seed();
$item = Item::factory()

View File

@@ -12,14 +12,14 @@ class ItemExportTest extends TestCase
use RefreshDatabase;
public function test_returns_empty_jsonarray_when_there_are_no_items_in_the_db()
public function test_returns_empty_jsonarray_when_there_are_no_items_in_the_db(): void
{
$response = $this->get('api/item');
$response->assertJsonCount(0);
}
public function test_returns_exactly_the_defined_fields()
public function test_returns_exactly_the_defined_fields(): void
{
$exampleItem = [
"appdescription" => "Description",
@@ -37,7 +37,7 @@ class ItemExportTest extends TestCase
$response->assertExactJson([(object)$exampleItem]);
}
public function test_returns_all_items()
public function test_returns_all_items(): void
{
Item::factory()
->count(3)
@@ -48,7 +48,7 @@ class ItemExportTest extends TestCase
$response->assertJsonCount(3);
}
public function test_does_not_return_deleted_item()
public function test_does_not_return_deleted_item(): void
{
Item::factory()
->create([
@@ -62,7 +62,7 @@ class ItemExportTest extends TestCase
$response->assertJsonCount(1);
}
public function test_does_not_return_tags()
public function test_does_not_return_tags(): void
{
Item::factory()
->create([

View File

@@ -18,7 +18,7 @@ class ItemListTest extends TestCase
]);
}
public function test_displays_items_on_the_item_list_page()
public function test_displays_items_on_the_item_list_page(): void
{
$this->addItemWithTitleToDB('Item 1');
$this->addItemWithTitleToDB('Item 2');
@@ -32,7 +32,7 @@ class ItemListTest extends TestCase
$response->assertSee('Item 3');
}
public function test_escapes_xss_on_the_item_list_page()
public function test_escapes_xss_on_the_item_list_page(): void
{
$this->addItemWithTitleToDB('<script>alert("XSS")</script>');

View File

@@ -9,7 +9,7 @@ class SettingsTest extends TestCase
{
use RefreshDatabase;
public function test_displays_the_settings_page()
public function test_displays_the_settings_page(): void
{
$this->seed();

View File

@@ -19,7 +19,7 @@ class TagListTest extends TestCase
]);
}
public function test_displays_the_tags_on_the_tag_list_page()
public function test_displays_the_tags_on_the_tag_list_page(): void
{
$this->addTagWithTitleToDB('Tag 1');
$this->addTagWithTitleToDB('Tag 2');
@@ -33,7 +33,7 @@ class TagListTest extends TestCase
$response->assertSee('Tag 3');
}
public function test_escapes_xss_on_the_tag_list_page()
public function test_escapes_xss_on_the_tag_list_page(): void
{
$this->addTagWithTitleToDB('<script>alert("XSS")</script>');

View File

@@ -18,7 +18,7 @@ class UserListTest extends TestCase
]);
}
public function test_displays_admin_on_user_list_page_when_default_install()
public function test_displays_admin_on_user_list_page_when_default_install(): void
{
$this->seed();
@@ -28,7 +28,7 @@ class UserListTest extends TestCase
$response->assertSee('admin');
}
public function test_displays_users_on_user_list_page()
public function test_displays_users_on_user_list_page(): void
{
$this->seed();

View File

@@ -12,7 +12,7 @@ class SettingsSeederTest extends TestCase
*
* @return void
*/
public function test_returns_a_jsonmap_with_same_amount_of_items_as_language_directories_present()
public function test_returns_a_jsonmap_with_same_amount_of_items_as_language_directories_present(): void
{
$languageDirectories = array_filter(glob(resource_path().'/lang/*'), 'is_dir');

View File

@@ -9,7 +9,7 @@ class IsImageTest extends TestCase
/**
* @return void
*/
public function test_returns_true_when_file_is_image()
public function test_returns_true_when_file_is_image(): void
{
$file = file_get_contents(__DIR__ . '/fixtures/heimdall-icon-small.png');
@@ -21,7 +21,7 @@ class IsImageTest extends TestCase
/**
* @return void
*/
public function test_returns_false_when_file_extension_is_image_but_content_is_not()
public function test_returns_false_when_file_extension_is_image_but_content_is_not(): void
{
$actual = isImage("<?php ?>", "png");
@@ -31,7 +31,7 @@ class IsImageTest extends TestCase
/**
* @return void
*/
public function test_returns_false_when_file_extension_is_not_image_but_content_is()
public function test_returns_false_when_file_extension_is_not_image_but_content_is(): void
{
$file = file_get_contents(__DIR__ . '/fixtures/heimdall-icon-small.png');

View File

@@ -9,7 +9,7 @@ class SlugTest extends TestCase
/**
* @return void
*/
public function test_slug_returns_valid_tag_for_cn_characters_when_language_is_set_to_en_US()
public function test_slug_returns_valid_tag_for_cn_characters_when_language_is_set_to_en_US(): void
{
$tag = str_slug('中文測試', '-', 'en_US');

View File

@@ -11,7 +11,7 @@ class LangTest extends TestCase
*
* @return void
*/
public function test_all_language_keys_are_defined()
public function test_all_language_keys_are_defined(): void
{
$this->markTestSkipped('2022-11-14 Lot of keys missing. Enable this test to see them all.');
$languageDirectories = array_filter(glob(resource_path().'/lang/*'), 'is_dir');