diff --git a/app/Form/Fields/Field.php b/app/Form/Fields/Field.php index bf511259..73c3d150 100644 --- a/app/Form/Fields/Field.php +++ b/app/Form/Fields/Field.php @@ -79,7 +79,9 @@ abstract class Field extends Data */ public function presentValue($value) { - return [$this->key => $value]; + return [ + $this->key => $value, + ]; } /** diff --git a/app/Form/Resources/ParticipantResource.php b/app/Form/Resources/ParticipantResource.php index a0f081d6..3cf00781 100644 --- a/app/Form/Resources/ParticipantResource.php +++ b/app/Form/Resources/ParticipantResource.php @@ -4,15 +4,19 @@ namespace App\Form\Resources; use App\Form\Fields\Field; use App\Form\Models\Form; +use App\Form\Models\Participant; use Illuminate\Http\Resources\Json\JsonResource; +/** + * @mixin Participant + */ class ParticipantResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @return array */ public function toArray($request) { @@ -22,9 +26,12 @@ class ParticipantResource extends JsonResource $attributes = $attributes->merge(Field::fromConfig($field)->presentValue($this->data[$field['key']])); } - return $attributes; + return $attributes->toArray(); } + /** + * @return array + */ public static function meta(Form $form): array { return [ diff --git a/database/factories/Form/Models/ParticipantFactory.php b/database/factories/Form/Models/ParticipantFactory.php index ec52d114..7e45c7e1 100644 --- a/database/factories/Form/Models/ParticipantFactory.php +++ b/database/factories/Form/Models/ParticipantFactory.php @@ -2,7 +2,6 @@ namespace Database\Factories\Form\Models; -use App\Form\Models\Form; use App\Form\Models\Participant; use Illuminate\Database\Eloquent\Factories\Factory; use Tests\Feature\Form\FormtemplateSectionRequest; @@ -15,7 +14,7 @@ class ParticipantFactory extends Factory /** * The name of the factory's corresponding model. * - * @var class-string
+ * @var class-string */ protected $model = Participant::class; diff --git a/database/factories/Traits/FakesMedia.php b/database/factories/Traits/FakesMedia.php index 1fab82fb..1b6ddce5 100644 --- a/database/factories/Traits/FakesMedia.php +++ b/database/factories/Traits/FakesMedia.php @@ -8,7 +8,7 @@ use Spatie\MediaLibrary\HasMedia; trait FakesMedia { - public function withImage(string $collection, $filename): self + public function withImage(string $collection, string $filename): self { return $this->afterCreating(function (HasMedia $model) use ($filename, $collection) { $pathinfo = pathinfo($filename); diff --git a/phpstan.neon b/phpstan.neon index f0bf3afe..c5a8f0b1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -532,3 +532,18 @@ parameters: message: "#^Parameter \\#1 \\.\\.\\.\\$parts of method App\\\\Member\\\\FilterScope\\:\\:combinations\\(\\) expects array\\, array\\\\> given\\.$#" count: 1 path: app/Member/FilterScope.php + + - + message: "#^Call to function is_null\\(\\) with array will always evaluate to false\\.$#" + count: 1 + path: app/Form/Models/Form.php + + - + message: "#^Unable to resolve the template type TKey in call to function collect$#" + count: 1 + path: app/Form/Models/Form.php + + - + message: "#^Unable to resolve the template type TValue in call to function collect$#" + count: 1 + path: app/Form/Models/Form.php diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index 13069bc4..f49c2fca 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -63,7 +63,7 @@ class FormIndexActionTest extends EndToEndTestCase ->assertInertiaPath('data.meta.section_default.name', ''); } - public function testItHandlesFullTextSearch() + public function testItHandlesFullTextSearch(): void { $this->withoutExceptionHandling()->login()->loginNami(); Form::factory()->to(now()->addYear())->name('ZEM 2024')->create(); @@ -76,7 +76,7 @@ class FormIndexActionTest extends EndToEndTestCase ->assertInertiaCount('data.data', 2); } - public function testItOrdersByStartDateDesc() + public function testItOrdersByStartDateDesc(): void { $this->withoutExceptionHandling()->login()->loginNami(); $form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create(); @@ -90,7 +90,7 @@ class FormIndexActionTest extends EndToEndTestCase ->assertInertiaPath('data.data.2.id', $form1->id); } - public function testItShowsPastEvents() + public function testItShowsPastEvents(): void { $this->withoutExceptionHandling()->login()->loginNami(); Form::factory()->count(5)->to(now()->subDays(2))->create(); diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index 3e6824db..2fe32e99 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -56,6 +56,8 @@ class FormRegisterActionTest extends TestCase /** * @dataProvider validationDataProvider + * @param array $payload + * @param ?array $messages */ public function testItValidatesInput(FormtemplateFieldRequest $fieldGenerator, array $payload, ?array $messages): void { @@ -73,7 +75,7 @@ class FormRegisterActionTest extends TestCase } } - private function validationDataProvider(): Generator + public function validationDataProvider(): Generator { yield [ FormtemplateFieldRequest::type(DateField::class)->name('Geburtsdatum')->maxToday(false)->key('birthday'), @@ -89,7 +91,7 @@ class FormRegisterActionTest extends TestCase yield [ FormtemplateFieldRequest::type(DateField::class)->name('Geburtsdatum')->maxToday(true)->key('birthday'), - ['birthday' => now()->addDay(1)->format('Y-m-d')], + ['birthday' => now()->addDay()->format('Y-m-d')], ['birthday' => 'Geburtsdatum muss ein Datum vor oder gleich dem ' . now()->format('d.m.Y') . ' sein.'], ]; diff --git a/tests/Feature/Form/FormStoreActionTest.php b/tests/Feature/Form/FormStoreActionTest.php index b00f7521..e9bc170a 100644 --- a/tests/Feature/Form/FormStoreActionTest.php +++ b/tests/Feature/Form/FormStoreActionTest.php @@ -31,7 +31,7 @@ class FormStoreActionTest extends TestCase $description = EditorRequestFactory::new()->text(10, 'Lorem'); FormRequest::new() ->name('formname') - ->description($description->create()) + ->description($description) ->excerpt('avff') ->registrationFrom('2023-05-04 01:00:00')->registrationUntil('2023-07-07 01:00:00')->from('2023-07-07')->to('2023-07-08') ->mailTop('Guten Tag') diff --git a/tests/Feature/Form/FormtemplateFieldRequest.php b/tests/Feature/Form/FormtemplateFieldRequest.php index c9abb7d4..a15d2dea 100644 --- a/tests/Feature/Form/FormtemplateFieldRequest.php +++ b/tests/Feature/Form/FormtemplateFieldRequest.php @@ -14,6 +14,8 @@ use Worksome\RequestFactories\RequestFactory; * @method self default(mixed $default) * @method self options(array $options) * @method self maxToday(bool $maxToday) + * @method self parentGroup(int $groupId) + * @method self parentField(string $fieldKey) */ class FormtemplateFieldRequest extends RequestFactory { diff --git a/tests/RequestFactories/EditorRequestFactory.php b/tests/RequestFactories/EditorRequestFactory.php index 20a2e020..230d7799 100644 --- a/tests/RequestFactories/EditorRequestFactory.php +++ b/tests/RequestFactories/EditorRequestFactory.php @@ -2,8 +2,6 @@ namespace Tests\RequestFactories; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use Worksome\RequestFactories\RequestFactory; class EditorRequestFactory extends RequestFactory @@ -27,6 +25,9 @@ class EditorRequestFactory extends RequestFactory return $this->state($this->paragraphBlock($id, $text)); } + /** + * @return array + */ public function paragraphBlock(int $id, string $text): array { return [