{"id":376957,"date":"2024-05-24T15:00:32","date_gmt":"2024-05-24T15:00:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=376957"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-24T15:00:32","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=376957","title":{"rendered":"<span>\u041a\u0430\u043a \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0432\u0430\u0448\u0435\u0433\u043e Laravel-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 0 \u0434\u043e 9 \u0432 Larastan<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/github.com\/larastan\/larastan\">Larastan<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c Laravel-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0435\u0449\u0435 \u0434\u043e \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430. \u041e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 PHPStan, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u0441\u0435\u0439 \u043c\u0430\u0433\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 Laravel.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0430\u0441 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u044d\u0442\u0430\u043f\u044b \u043e\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Larastan \u0434\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f 9 \u0443\u0440\u043e\u0432\u043d\u044f, \u043d\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<p>\u0418\u0437 README Larastan \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0435\u0433\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>composer require larastan\/larastan:^2.0 --dev<\/code><\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b <code>phpstan.neon<\/code> \u0438\u043b\u0438 <code>phpstan.neon.dist<\/code> \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">includes:     - vendor\/larastan\/larastan\/extension.neon  parameters:      paths:         - app\/      # Level 9 is the highest level     level: 5<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d 5-\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 0.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f Larastan \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435:<\/p>\n<ol>\n<li>\n<p>\u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u0437 <code>$this<\/code>, \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u044d\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 <code>__call<\/code> \u0438 <code>__get<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043e \u0432\u0441\u0435\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 (\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <code>$this<\/code>), \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 PHPDocs<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b, \u0442\u0438\u043f\u044b, \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c<\/p>\n<\/li>\n<li>\n<p>\u0431\u0430\u0437\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043c\u0435\u0440\u0442\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>instanceof<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432, \u043c\u0435\u0440\u0442\u0432\u044b\u0435 \u0432\u0435\u0442\u0432\u0438 <code>else<\/code>, \u043d\u0435\u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 <code>return<\/code>; \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e\u0431 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u0445 \u0442\u0438\u043f\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u2014 \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0442\u0438\u043f\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0443\u0440\u043e\u0432\u0435\u043d\u044c 7 \u043e\u0442\u0440\u0430\u043f\u043e\u0440\u0442\u0443\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c; \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a \u0442\u0438\u043f\u0443 <code>mixed<\/code> \u2014 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043d\u0438\u043c, \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 <code>mixed<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 (\u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u0441\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435):<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043a\u043e\u0434 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044f \u043c\u043e\u0433 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.<\/p>\n<pre><code class=\"php\">declare(strict_types=1);  use App\\Http\\Controllers\\Controller; use App\\Models\\Appointment; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Http\\Request;  class User extends Model {     public function appointments()     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public $name,         public $is_active,     ) {     }      public function toArray()     {         return [             'name' => $this->name,             'is_active' => $this->is_active,         ];     } }  class ShowUserQuery {     public function run($id)     {         $this->doSomething();          return User::query()             ->with('appointments')             ->find($id);     } }  class UserController extends Controller {     public function show($id, ShowUserQuery $query)     {         return response()->json($query->run($id)->toArray());     }      public function store(Request $request)     {         $request->validate([             'name' => ['required', 'max:250'],             'is_active' => ['required', 'boolean'],         ]);          if (true) {             return;         }          $isActive = $request->input('is_active');          $userDTO = new UserDTO(             $request->input('name'),             $isActive         );          $user = User::create($userDTO->toArray());          return $user;     } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>.\/vendor\/bin\/phpstan analyze<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<pre><code> 22     Call to an undefined method ShowUserQuery::doSomething().     24     Relation 'appointments' is not found in User model. <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">class User extends Model {     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class ShowUserQuery {     public function run($id)     {         return User::query()             ->with('appointments')             ->find($id);     } } <\/code><\/pre>\n<p>\u0414\u043e 4-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 1, 2 \u0438 3. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0434\u043e \u0443\u0440\u043e\u0432\u043d\u044f 4 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<pre><code class=\"php\"> 43     If condition is always true.                              47     Unreachable statement - code above always terminates.<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 if, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 store \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"php\">public function store(Request $request) {     $data = $request->validate([         'name' => ['required', 'max:250'],         'is_active' => ['required', 'boolean'],     ]);      $isActive = $request->input('is_active');      $userDTO = new UserDTO(         $request->input('name'),         $isActive     );      $user = User::create($userDTO->toArray());      return $user; } <\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e 5-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043d\u043e \u043d\u0430 6-\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code class=\"php\"> 13     Method User::appointments() return type with generic class                            Illuminate\\Database\\Eloquent\\Relations\\HasMany does not specify its types:            TRelatedModel                                                                         ? You can turn this off by setting                                                      checkGenericClassInNonGenericObjectType: false in your                                phpstan.neon.                                                               21     Method ShowUserQuery::run() has no return type specified.                      21     Method ShowUserQuery::run() has parameter $id with no type specified.          31     Method UserController::show() has no return type specified.                    31     Method UserController::show() has parameter $id with no type specified.        36     Method UserController::store() has no return type specified. <\/code><\/pre>\n<p>\u0427\u0442\u043e \u0436, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0432 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">class User extends Model {     \/**      * @return HasMany&lt;Appointment>      *\/     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public string $name,         public bool $is_active,     ) {     }      \/**      * @return array{name: string, is_active: bool}      *\/     public function toArray(): array     {         return [             'name' => $this->name,             'is_active' => $this->is_active,         ];     } }  class ShowUserQuery {     public function run(int $id): ?User     {         return User::query()             ->with('appointments')             ->find($id);     } }  class UserController extends Controller {     public function show(int $id, ShowUserQuery $query): JsonResponse     {         return response()->json($query->run($id)->toArray());     }      public function store(Request $request): User     {         $request->validate([             'name' => ['required', 'max:250'],             'active' => ['required', 'boolean'],         ]);         $isActive = $request->input('is_active');          $userDTO = new UserDTO(             $request->input('name'),             $isActive         );          $user = User::create($userDTO->toArray());          return $user;     } }<\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e 7-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0430 \u0432\u043e\u0442 \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e 8-\u0433\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u0442:<\/p>\n<pre><code class=\"php\">37     Cannot call method toArray() on User|null.  <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u0430\u0445. \u041d\u0430\u0448\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code class=\"php\">public function show(int $id, ShowUserQuery $query): JsonResponse {     $userArray = $query->run($id)?->toArray() ?? [];      return response()->json($userArray); }<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0434\u043e\u0445\u043e\u0434\u0438\u043c \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u0440\u043e\u0432\u043d\u044f 9, \u0438 \u0437\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>mixed<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  <code>$isActive<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>assert<\/code> \u0438 <code>string<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">public function store(Request $request): User {     $request->validate([         'name' => ['required', 'max:250'],         'active' => ['required', 'boolean'],     ]);     $isActive = $request->input('is_active');     assert(is_bool($isActive));      $userDTO = new UserDTO(         $request->string('name')->toString(),         $isActive     );      $user = User::create($userDTO->toArray());      return $user; }<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>string<\/code> \u0438 <code>boolean<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">public function store(Request $request): User {     $request->validate([         'name' => ['required', 'max:250'],         'active' => ['required', 'boolean'],     ]);      $userDTO = new UserDTO(         $request->string('name')->toString(),         $request->boolean('is_active')     );      $user = User::create($userDTO->toArray());      return $user; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441 0 \u043f\u043e 9 \u0443\u0440\u043e\u0432\u0435\u043d\u044c Larastan\/PHPStan \u043d\u0430\u0448 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">&lt;?php  declare(strict_types=1);  use App\\Http\\Controllers\\Controller; use App\\Models\\Appointment; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Database\\Eloquent\\Relations\\HasMany; use Illuminate\\Http\\JsonResponse; use Illuminate\\Http\\Request;  class User extends Model {     \/**      * @return HasMany&lt;Appointment>      *\/     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public string $name,         public bool $is_active,     ) {     }      \/**      * @return array{name: string, is_active: bool}      *\/     public function toArray(): array     {         return [             'name' => $this->name,             'is_active' => $this->is_active,         ];     } }  class ShowUserQuery {     public function run(int $id): ?User     {         return User::query()             ->with('appointments')             ->find($id);     } }  class UserController extends Controller {     public function show(int $id, ShowUserQuery $query): JsonResponse     {         $userArray = $query->run($id)?->toArray() ?? [];          return response()->json($userArray);     }      public function store(Request $request): User     {         $request->validate([             'name' => ['required', 'max:250'],             'active' => ['required', 'boolean'],         ]);          $userDTO = new UserDTO(             $request->string('name')->toString(),             $request->boolean('is_active')         );          $user = User::create($userDTO->toArray());          return $user;     } } <\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Larastan \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0435\u0449\u0435 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e, \u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u0432\u0435\u0441\u044c \u043f\u0443\u0442\u044c \u0434\u043e 9-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<hr\/>\n<p><em>\u0412\u0441\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 Laravel \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c <\/em><a href=\"https:\/\/otus.pw\/8T5H\/\"><em>\u043d\u0430 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u0435<\/em><\/a><em> \u043f\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/816873\/\"> https:\/\/habr.com\/ru\/articles\/816873\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/github.com\/larastan\/larastan\">Larastan<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c Laravel-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0435\u0449\u0435 \u0434\u043e \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430. \u041e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u0435\u0440\u0442\u043a\u0443 PHPStan, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0443\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u0441\u0435\u0439 \u043c\u0430\u0433\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 Laravel.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0430\u0441 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u044d\u0442\u0430\u043f\u044b \u043e\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Larastan \u0434\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f 9 \u0443\u0440\u043e\u0432\u043d\u044f, \u043d\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<p>\u0418\u0437 README Larastan \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0435\u0433\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>composer require larastan\/larastan:^2.0 --dev<\/code><\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b <code>phpstan.neon<\/code> \u0438\u043b\u0438 <code>phpstan.neon.dist<\/code> \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">includes:     - vendor\/larastan\/larastan\/extension.neon  parameters:      paths:         - app\/      # Level 9 is the highest level     level: 5<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d 5-\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0430 0.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f Larastan \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435:<\/p>\n<ol>\n<li>\n<p>\u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u0437 <code>$this<\/code>, \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u044d\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 <code>__call<\/code> \u0438 <code>__get<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043e \u0432\u0441\u0435\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 (\u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f <code>$this<\/code>), \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 PHPDocs<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b, \u0442\u0438\u043f\u044b, \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c<\/p>\n<\/li>\n<li>\n<p>\u0431\u0430\u0437\u043e\u0432\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043c\u0435\u0440\u0442\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 <code>instanceof<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432, \u043c\u0435\u0440\u0442\u0432\u044b\u0435 \u0432\u0435\u0442\u0432\u0438 <code>else<\/code>, \u043d\u0435\u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 <code>return<\/code>; \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e\u0431 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u0445 \u0442\u0438\u043f\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u2014 \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0442\u0438\u043f\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0443\u0440\u043e\u0432\u0435\u043d\u044c 7 \u043e\u0442\u0440\u0430\u043f\u043e\u0440\u0442\u0443\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c; \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u0447\u0435\u0442 \u043e \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a \u0442\u0438\u043f\u0443 <code>mixed<\/code> \u2014 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043d\u0438\u043c, \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443 <code>mixed<\/code><\/p>\n<\/li>\n<\/ol>\n<p>\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u044d\u0442\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 (\u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u0441\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435):<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043a\u043e\u0434 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044f \u043c\u043e\u0433 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438.<\/p>\n<pre><code class=\"php\">declare(strict_types=1);  use App\\Http\\Controllers\\Controller; use App\\Models\\Appointment; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Http\\Request;  class User extends Model {     public function appointments()     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public $name,         public $is_active,     ) {     }      public function toArray()     {         return [             'name' => $this->name,             'is_active' => $this->is_active,         ];     } }  class ShowUserQuery {     public function run($id)     {         $this->doSomething();          return User::query()             ->with('appointments')             ->find($id);     } }  class UserController extends Controller {     public function show($id, ShowUserQuery $query)     {         return response()->json($query->run($id)->toArray());     }      public function store(Request $request)     {         $request->validate([             'name' => ['required', 'max:250'],             'is_active' => ['required', 'boolean'],         ]);          if (true) {             return;         }          $isActive = $request->input('is_active');          $userDTO = new UserDTO(             $request->input('name'),             $isActive         );          $user = User::create($userDTO->toArray());          return $user;     } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>.\/vendor\/bin\/phpstan analyze<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<pre><code> 22     Call to an undefined method ShowUserQuery::doSomething().     24     Relation 'appointments' is not found in User model. <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"php\">class User extends Model {     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class ShowUserQuery {     public function run($id)     {         return User::query()             ->with('appointments')             ->find($id);     } } <\/code><\/pre>\n<p>\u0414\u043e 4-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 1, 2 \u0438 3. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0434\u043e \u0443\u0440\u043e\u0432\u043d\u044f 4 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<pre><code class=\"php\"> 43     If condition is always true.                              47     Unreachable statement - code above always terminates.<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 if, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 store \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"php\">public function store(Request $request) {     $data = $request->validate([         'name' => ['required', 'max:250'],         'is_active' => ['required', 'boolean'],     ]);      $isActive = $request->input('is_active');      $userDTO = new UserDTO(         $request->input('name'),         $isActive     );      $user = User::create($userDTO->toArray());      return $user; } <\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e 5-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043d\u043e \u043d\u0430 6-\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0443\u0447\u0443 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code class=\"php\"> 13     Method User::appointments() return type with generic class                            Illuminate\\Database\\Eloquent\\Relations\\HasMany does not specify its types:            TRelatedModel                                                                         ? You can turn this off by setting                                                      checkGenericClassInNonGenericObjectType: false in your                                phpstan.neon.                                                               21     Method ShowUserQuery::run() has no return type specified.                      21     Method ShowUserQuery::run() has parameter $id with no type specified.          31     Method UserController::show() has no return type specified.                    31     Method UserController::show() has parameter $id with no type specified.        36     Method UserController::store() has no return type specified. <\/code><\/pre>\n<p>\u0427\u0442\u043e \u0436, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0432 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"php\">class User extends Model {     \/**      * @return HasMany&lt;Appointment>      *\/     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public string $name,         public bool $is_active,     ) {     }      \/**      * @return array{name: string, is_active: bool}      *\/     public function toArray(): array     {         return [             'name' => $this->name,             'is_active' => $this->is_active,         ];     } }  class ShowUserQuery {     public function run(int $id): ?User     {         return User::query()             ->with('appointments')             ->find($id);     } }  class UserController extends Controller {     public function show(int $id, ShowUserQuery $query): JsonResponse     {         return response()->json($query->run($id)->toArray());     }      public function store(Request $request): User     {         $request->validate([             'name' => ['required', 'max:250'],             'active' => ['required', 'boolean'],         ]);         $isActive = $request->input('is_active');          $userDTO = new UserDTO(             $request->input('name'),             $isActive         );          $user = User::create($userDTO->toArray());          return $user;     } }<\/code><\/pre>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e 7-\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0430 \u0432\u043e\u0442 \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u043e 8-\u0433\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435\u0442:<\/p>\n<pre><code class=\"php\">37     Cannot call method toArray() on User|null.  <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u0430\u0445. \u041d\u0430\u0448\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c:<\/p>\n<pre><code class=\"php\">public function show(int $id, ShowUserQuery $query): JsonResponse {     $userArray = $query->run($id)?->toArray() ?? [];      return response()->json($userArray); }<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0434\u043e\u0445\u043e\u0434\u0438\u043c \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u0440\u043e\u0432\u043d\u044f 9, \u0438 \u0437\u0434\u0435\u0441\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>mixed<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  <code>$isActive<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<ol>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>assert<\/code> \u0438 <code>string<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">public function store(Request $request): User {     $request->validate([         'name' => ['required', 'max:250'],         'active' => ['required', 'boolean'],     ]);     $isActive = $request->input('is_active');     assert(is_bool($isActive));      $userDTO = new UserDTO(         $request->string('name')->toString(),         $isActive     );      $user = User::create($userDTO->toArray());      return $user; }<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>string<\/code> \u0438 <code>boolean<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">public function store(Request $request): User {     $request->validate([         'name' => ['required', 'max:250'],         'active' => ['required', 'boolean'],     ]);      $userDTO = new UserDTO(         $request->string('name')->toString(),         $request->boolean('is_active')     );      $user = User::create($userDTO->toArray());      return $user; }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0441 0 \u043f\u043e 9 \u0443\u0440\u043e\u0432\u0435\u043d\u044c Larastan\/PHPStan \u043d\u0430\u0448 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">&lt;?php  declare(strict_types=1);  use App\\Http\\Controllers\\Controller; use App\\Models\\Appointment; use Illuminate\\Database\\Eloquent\\Model; use Illuminate\\Database\\Eloquent\\Relations\\HasMany; use Illuminate\\Http\\JsonResponse; use Illuminate\\Http\\Request;  class User extends Model {     \/**      * @return HasMany&lt;Appointment>      *\/     public function appointments(): HasMany     {         return $this->hasMany(Appointment::class);     } }  class UserDTO {     public function __construct(         public string $name,         public bool $is_active,    <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-376957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=376957"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376957\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}