Skip to editor
Psalm
Docs
Playground
Plugins
Blog
Paid support
Share
Fix issues
Show original
PHP
Settings
<?php class Http { public const STATUS_OK = 200; public const STATUS_BAD_REQUEST = 400; } /** * @template D * @template S of Http::STATUS_* */ class JsonResponse { /** @var S */ private int $status; /** * @param D $data * @param S $status */ public function __construct($data, int $status) { $this->status = $status; } } /** * @psalm-type Dog = array{'barks': bool} * @psalm-type Cat = array{'meows': bool} */ class ResponseDefinitions {} /** * @psalm-import-type Dog from ResponseDefinitions * @psalm-import-type Cat from ResponseDefinitions */ class TestController { /** * @return JsonResponse<array{'barks': bool}, 400>|JsonResponse<array{'meows': bool}, 200> */ function getPet1(): JsonResponse { if (1+1==2) { return new JsonResponse(['meows' => true], 200); } else { return new JsonResponse(['barks' => false], 400); } } /** * @return JsonResponse<Dog, 400>|JsonResponse<Cat, 200> */ function getPet2(): JsonResponse { if (1+1==2) { return new JsonResponse(['meows' => true], 200); } else { return new JsonResponse(['barks' => false], 400); } } }
Issues
Types
idle
Saved Feb 14 2023 15:10 UTC
⌘/Ctrl+Enter
run
⌘/Ctrl+S
share
F8
/
⇧F8
next/prev issue