From d06ae7acb55d35192da36c695eb34b7ca2f685ef Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 29 Jun 2024 11:18:40 +0200 Subject: [PATCH] Lint --- app/Contribution/ContributionFactory.php | 2 +- app/Dav/AddressBookBackend.php | 9 +-- app/Fileshare/Actions/ListFilesAction.php | 3 + .../ConnectionTypes/ConnectionType.php | 19 +++-- app/Fileshare/Data/ResourceData.php | 2 +- app/Fileshare/Resources/FileshareResource.php | 2 +- app/Form/Casts/FieldCollectionCast.php | 2 +- app/Form/Fields/Field.php | 3 + packages/laravel-nami | 2 +- phpstan.neon | 77 ++++++++++++------- tests/TestCase.php | 3 +- tests/stub/phpstan/TestResponse.stub | 2 +- 12 files changed, 81 insertions(+), 45 deletions(-) diff --git a/app/Contribution/ContributionFactory.php b/app/Contribution/ContributionFactory.php index 25e66020..0db0aab1 100644 --- a/app/Contribution/ContributionFactory.php +++ b/app/Contribution/ContributionFactory.php @@ -25,7 +25,7 @@ class ContributionFactory ]; /** - * @return Collection + * @return Collection}> */ public function compilerSelect(): Collection { diff --git a/app/Dav/AddressBookBackend.php b/app/Dav/AddressBookBackend.php index 2696687a..39370629 100644 --- a/app/Dav/AddressBookBackend.php +++ b/app/Dav/AddressBookBackend.php @@ -8,9 +8,6 @@ use Sabre\CardDAV\Backend\AbstractBackend; use Sabre\DAV\PropPatch; use Sabre\VObject\Component\VCard; -/** - * @template M as array{lastmodified: int, etag: string, uri: string, id: int, size: int} - */ class AddressBookBackend extends AbstractBackend { /** @@ -115,7 +112,7 @@ class AddressBookBackend extends AbstractBackend * * @param mixed $addressbookId * - * @return array + * @return array */ public function getCards($addressbookId): array { @@ -133,7 +130,7 @@ class AddressBookBackend extends AbstractBackend * @param mixed $addressBookId * @param string $cardUri * - * @return M + * @return AddressBookCard|bool */ public function getCard($addressBookId, $cardUri) { @@ -248,7 +245,7 @@ class AddressBookBackend extends AbstractBackend } /** - * @return M + * @return AddressBookCard */ private function cardMeta(Member $member): array { diff --git a/app/Fileshare/Actions/ListFilesAction.php b/app/Fileshare/Actions/ListFilesAction.php index 6465faa5..b1a2b4f6 100644 --- a/app/Fileshare/Actions/ListFilesAction.php +++ b/app/Fileshare/Actions/ListFilesAction.php @@ -12,6 +12,9 @@ class ListFilesAction { use AsAction; + /** + * @return DataCollection + */ public function handle(ActionRequest $request, Fileshare $fileshare): DataCollection { return ResourceData::collection($fileshare->type->getSubDirectories($request->input('parent')))->wrap('data'); diff --git a/app/Fileshare/ConnectionTypes/ConnectionType.php b/app/Fileshare/ConnectionTypes/ConnectionType.php index dad1c00b..4536679d 100644 --- a/app/Fileshare/ConnectionTypes/ConnectionType.php +++ b/app/Fileshare/ConnectionTypes/ConnectionType.php @@ -2,10 +2,9 @@ namespace App\Fileshare\ConnectionTypes; -use App\Fileshare\Data\ResourceData; use Illuminate\Filesystem\FilesystemAdapter; +use Illuminate\Support\Collection; use Spatie\LaravelData\Data; -use Spatie\LaravelData\DataCollection; abstract class ConnectionType extends Data { @@ -30,10 +29,7 @@ abstract class ConnectionType extends Data */ public static function forSelect(): array { - return collect(glob(base_path('app/Fileshare/ConnectionTypes/*'))) - ->map(fn ($file) => 'App\\Fileshare\\ConnectionTypes\\' . pathinfo($file, PATHINFO_FILENAME)) - ->filter(fn ($file) => $file !== static::class) - ->values() + return self::types() ->map(fn ($file) => ['id' => $file, 'name' => $file::title(), 'defaults' => $file::defaults(), 'fields' => $file::fields()]) ->toArray(); } @@ -47,4 +43,15 @@ abstract class ConnectionType extends Data return $filesystem->directories($parent ?: '/'); } + + /** + * @return Collection> + */ + private static function types(): Collection + { + return collect(glob(base_path('app/Fileshare/ConnectionTypes/*'))) + ->map(fn ($file) => 'App\\Fileshare\\ConnectionTypes\\' . pathinfo($file, PATHINFO_FILENAME)) + ->filter(fn ($file) => $file !== static::class) + ->values(); + } } diff --git a/app/Fileshare/Data/ResourceData.php b/app/Fileshare/Data/ResourceData.php index ccc9073a..8d356992 100644 --- a/app/Fileshare/Data/ResourceData.php +++ b/app/Fileshare/Data/ResourceData.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Data; class ResourceData extends Data { - public function __construct(public $name, public $path, public $parent) + public function __construct(public string $name, public string $path, public string $parent) { } diff --git a/app/Fileshare/Resources/FileshareResource.php b/app/Fileshare/Resources/FileshareResource.php index c9102e39..5a604b6f 100644 --- a/app/Fileshare/Resources/FileshareResource.php +++ b/app/Fileshare/Resources/FileshareResource.php @@ -8,7 +8,7 @@ use App\Lib\HasMeta; use Illuminate\Http\Resources\Json\JsonResource; /** - * @mixin FileshareConnection + * @mixin Fileshare */ class FileshareResource extends JsonResource { diff --git a/app/Form/Casts/FieldCollectionCast.php b/app/Form/Casts/FieldCollectionCast.php index 0661dfb9..f4e37950 100644 --- a/app/Form/Casts/FieldCollectionCast.php +++ b/app/Form/Casts/FieldCollectionCast.php @@ -10,7 +10,7 @@ use Spatie\LaravelData\Support\DataProperty; class FieldCollectionCast implements Cast { /** - * @param array> $value + * @param array> $value * @param array $context * @return FieldCollection */ diff --git a/app/Form/Fields/Field.php b/app/Form/Fields/Field.php index 519dd4bf..8ae68ded 100644 --- a/app/Form/Fields/Field.php +++ b/app/Form/Fields/Field.php @@ -79,6 +79,9 @@ abstract class Field extends Data ->toArray(); } + /** + * @return class-string + */ public static function classFromType(string $type): ?string { /** @var class-string */ diff --git a/packages/laravel-nami b/packages/laravel-nami index b8164cd3..84103d40 160000 --- a/packages/laravel-nami +++ b/packages/laravel-nami @@ -1 +1 @@ -Subproject commit b8164cd3d204412cd3be95cbf29b9fcc3d23a77d +Subproject commit 84103d40521d77f936635a7f992cf1ae4b01dafe diff --git a/phpstan.neon b/phpstan.neon index c38e80f6..13723265 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,6 +25,7 @@ parameters: MailgatewayCustomField: 'array{name: string, label: string, type: string, storeValidator: string, updateValidator: string, default: string}' MailgatewayParsedCustomField: 'array{name: string, label: string, type: string, storeValidator: string, updateValidator: string, default: string, is_required: bool}' SluggableConfig: 'array}>' + AddressBookCard: 'array{lastmodified: int, etag: string, uri: string, id: int, size: int}' ignoreErrors: - @@ -32,11 +33,6 @@ parameters: count: 1 path: app/Activity.php - - - message: "#^Method App\\\\Dav\\\\AddressBookBackend\\:\\:getCard\\(\\) should return M of array\\{lastmodified\\: int, etag\\: string, uri\\: string, id\\: int, size\\: int\\} but returns false\\.$#" - count: 1 - path: app/Dav/AddressBookBackend.php - - message: "#^Method App\\\\Dav\\\\AddressBookBackend\\:\\:getMultipleCards\\(\\) has parameter \\$uris with no value type specified in iterable type array\\.$#" count: 1 @@ -162,17 +158,6 @@ parameters: count: 1 path: database/factories/NationalityFactory.php - - - message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy.*#" - - - - message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy.*#" - - - - message: "#^PHPDoc tag @param has invalid value \\(\\ \\$class\\)\\: Unexpected token \"\\<\", expected type at offset 18$#" - count: 1 - path: tests/TestCase.php - - message: "#^Parameter \\#1 \\$api of class App\\\\Initialize\\\\InitializeGroups constructor expects Zoomyboy\\\\LaravelNami\\\\Api, PHPUnit\\\\Framework\\\\MockObject\\\\Stub given\\.$#" count: 6 @@ -463,16 +448,6 @@ parameters: count: 1 path: tests/Feature/Member/DavTest.php - - - message: "#^Return type of call to method Illuminate\\\\Support\\\\Collection\\\\>\\:\\:map\\(\\) contains unresolvable type\\.$#" - count: 1 - path: app/Contribution/ContributionFactory.php - - - - message: "#^Return type of call to method Illuminate\\\\Support\\\\Collection\\\\>\\:\\:map\\(\\) contains unresolvable type\\.$#" - count: 1 - path: app/Setting/SettingFactory.php - - message: "#^Access to an undefined property Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:\\$email\\.$#" count: 2 @@ -542,3 +517,53 @@ parameters: message: "#^Unable to resolve the template type TValue in call to function collect$#" count: 1 path: app/Form/Fields/NamiField.php + + - + message: "#^Method App\\\\Fileshare\\\\ConnectionTypes\\\\ConnectionType\\:\\:types\\(\\) should return Illuminate\\\\Support\\\\Collection\\\\> but returns Illuminate\\\\Support\\\\Collection\\\\.$#" + count: 1 + path: app/Fileshare/ConnectionTypes/ConnectionType.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:check\\(\\)\\.$#" + count: 1 + path: tests/Feature/Mailgateway/IndexTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setCredentials\\(\\)\\.$#" + count: 1 + path: tests/Feature/Mailgateway/IndexTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:check\\(\\)\\.$#" + count: 2 + path: tests/Feature/Mailgateway/MailmanTypeTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setCredentials\\(\\)\\.$#" + count: 2 + path: tests/Feature/Mailgateway/MailmanTypeTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setOwner\\(\\)\\.$#" + count: 1 + path: tests/Feature/Mailgateway/MailmanTypeTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setOwner\\(\\)\\.$#" + count: 2 + path: tests/Feature/Mailgateway/StoreTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:setParams\\(\\)\\.$#" + count: 3 + path: tests/Feature/Mailgateway/StoreTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\StubberProxy\\:\\:works\\(\\)\\.$#" + count: 3 + path: tests/Feature/Mailgateway/StoreTest.php + + - + message: "#^Call to an undefined method Phake\\\\Proxies\\\\VerifierProxy\\:\\:handle\\(\\)\\.$#" + count: 2 + path: tests/Feature/Member/NamiPutMemberActionTest.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 14e5c4dc..8a2cb508 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -93,7 +93,8 @@ abstract class TestCase extends BaseTestCase } /** - * @param $class + * @template M of object + * @param class-string $class */ public function stubIo(string $class, callable $mocker): self { diff --git a/tests/stub/phpstan/TestResponse.stub b/tests/stub/phpstan/TestResponse.stub index 0b80ebda..9ae7e21e 100644 --- a/tests/stub/phpstan/TestResponse.stub +++ b/tests/stub/phpstan/TestResponse.stub @@ -10,7 +10,7 @@ use Symfony\Component\HttpFoundation\File\File; * @method self assertPdfPageCount(int $count) * @method self assertPdfName(string $filename) * @method self assertHasJsonPath(string $path) - * @method self assertComponnet(string $component) + * @method self assertComponent(string $component) * @method File getFile() */ class TestResponse