{"id":376364,"date":"2024-05-21T06:48:54","date_gmt":"2024-05-21T06:48:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=376364"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=376364","title":{"rendered":"<span>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 PHP<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0438 \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u044f PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u043f\u043b\u043e\u0442\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u0430 symfony \u0438 \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043f\u043e\u0440\u043d\u044b\u0435, \u0434\u043b\u044f \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0438 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<\/p>\n<h4>1. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 di \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u044f\u0432\u043d\u043e<\/h4>\n<p>\u042f\u0432\u043d\u043e\u0435 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e. \u041f\u0440\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043c\u0430\u0433\u0438\u044e symfony di. \u0412\u043e\u043e\u0431\u0449\u0435 \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e autowiring \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u0440\u0435\u0434\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430. \u041f\u0440\u0438 \u044f\u0432\u043d\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"yaml\">App\\Services\\MyService: ~ <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@doctrine.orm.entity_manager'         - '@app.services.my_service.dependency' <\/code><\/pre>\n<h4>2. \u0412 DI \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/h4>\n<p>\u0422\u0430\u043a \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u043e\u0449\u0440\u044f\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@App\\OtherService\\Producer\\ProducerInterface'  App\\OtherService\\Producer\\ProducerInterface:     alias: App\\OtherService\\Producer\\Amqp <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@app.other_service.producer'  app.other_service.producer:     class: App\\OtherService\\Producer\\Amqp <\/code><\/pre>\n<h4>3. \u041d\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/h4>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     public function __construct(private readonly ContainerInterface $container) {}     public function doSomething()     {         $producer = $this->container->get('app.other_service.producer');         $producer->publish();     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     public function __construct(private readonly ProducerInterface $producer) {}     public function doSomething()     {         $producer->publish();     } } <\/code><\/pre>\n<h4>4. \u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c<\/h4>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044f\u0441\u044c \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0415\u0441\u043b\u0438 \u0432 \u043c\u0435\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<br \/> \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     \/\/ ... } <\/code><\/pre>\n<h4>5. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435.<\/h4>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">interface SomeEntityInterface {     public function getId(): int;     public function getName(): int;     public function getAge(): int; } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">interface IdAwareInterface {     public function getId(): int; } interface NameAwareInterface {     public function getName(): int; } interface AgeAwareInterface {     public function getAge(): int; } <\/code><\/pre>\n<h4>6. \u0412 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u043a\u0438\u0435 exception \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u044b<\/h4>\n<p>\u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u0438\u0445 exceptions \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b. \u0415\u0441\u043b\u0438 \u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u0430 <a class=\"mention\" href=\"\/users\/throws\">@throws<\/a> &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 exception \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b.<\/p>\n<h4>7. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c strict_types=1. \u0422\u0438\u043f\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0436\u0435\u0441\u0442\u043a\u043e.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">public function doSomething(mixed $id) {     return $id; } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">public function doSomething(int $id) {     return $id; } <\/code><\/pre>\n<h4>8. \u0424\u043b\u0430\u0433\u0438 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h4>\n<p>\u041d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0449\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function doSomething($force = false)     {         if ($force) {             return $this->doForce()         }                  return $this->do()     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class ForceService {     public function doSomething()     {         return $this->doForce();     } } <\/code><\/pre>\n<h4>9. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 3<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0433\u043e &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function doSomething($own, $two, $three, $four)     {     } } <\/code><\/pre>\n<h4>10. \u041d\u0435 \u043c\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\/\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/h4>\n<p>\u042d\u0442\u043e \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$item = new Item(); $this->calculateCount($item);  public function calculateCount(Item $item): void {     $count = 0;     \/\/ some logic     $item->setCount($count); } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$item = new Item(); $item->setCount($this->calculateCount());  public function calculateCount(): int {     $count = 0;     \/\/ some logic     return $count; } <\/code><\/pre>\n<h4>11. \u0417\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 DTO \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, readonly \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438, \u0431\u0435\u0437 get\/set \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h4>\n<p>\u0422\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0430 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0435\u0442 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430 get\/set, \u0442\u0430\u043a\u0430\u044f dto \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0430 \u0437\u0430 \u0441\u0447\u0451\u0442 readonly.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class Item {     public function __construct(         public readonly int $id,         public readonly int $count,         public readonly string $originId,     ) {     } }  $item = new Item(     id: 1,     count: 2,     originId: 'aaa-bbb-ccc', ); <\/code><\/pre>\n<h4>12. \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043c\u0435\u043d\u044c\u0448\u0435 ~150 \u0441\u0442\u0440\u043e\u043a, \u043c\u0435\u0442\u043e\u0434 \u043c\u0435\u043d\u044c\u0448\u0435 ~30 \u0441\u0442\u0440\u043e\u043a. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<h4>13. Unit \u0442\u0435\u0441\u0442\u044b \u0432\u0441\u0435\u0433\u0434\u0430<\/h4>\n<p>\u041d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u0434 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0448\u0435\u043c unit \u0442\u0435\u0441\u0442 (\u043a\u0440\u043e\u043c\u0435 dto). \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c skiptests &#8212; \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e.<\/p>\n<pre><code class=\"php\">\/**  * @skiptests tested in {@see \\App\\SomeOthreService}  *\/ final class SomeServiceTest extends TestCase { } <\/code><\/pre>\n<h4>14. \u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>\u0422\u0435\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<br \/> \u041d\u0435 \u043d\u0430\u0434\u043e \u0432 \u0442\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043b\u043e\u0433\u0433\u0435\u0440\u0430, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430. Stubs \u0438 dummy \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 mocks \u0438 fakes.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeServiceTest extends TestCase {     public function testDoSomething()     {         $logger = $this->createMock(LoggerInterface::class);         $logger->expects($this->once())             ->method('info')             ->with('some message');         $service = new SomeService($logger);                  $service->doSomething();     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class SomeServiceTest extends TestCase {     public function testDoSomething()     {         $service = new SomeService(             $this->createMock(LoggerInterface::class),         );                  $service->doSomething();     } } <\/code><\/pre>\n<h4>15. \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0430 \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438.<br \/> \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService extends BaseLogic { } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function __construct(private readonly BaseLogic $logic) {}     public function execute()     {         $this->logic->doSomething();     } } <\/code><\/pre>\n<h4>16. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c final \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h4>\n<p>\u0422\u0430\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u043e\u0449\u0440\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<pre><code class=\"php\">final class SomeService { } <\/code><\/pre>\n<h4>17. \u041d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438<\/h4>\n<p>\u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c JMS\\Serializer\\SerializerInterface \u0438<br \/> JMS\\Serializer\\ArrayTransformerInterface.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$id = $data['id']; <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$id = $data->getId(); <\/code><\/pre>\n<h4>18. \u0421\u043e\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0437\u0430\u043a\u043e\u043d \u0414\u0435\u043c\u0435\u0442\u0440\u044b<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 \u0435\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u0446\u0430\u043c\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$client = $this->clientFactory->create(); $client->send(); <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$this->clientDecorator->send(); <\/code><\/pre>\n<h4>19. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0438\u043a\u043b\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u041a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0441\u043a\u0438\u043c. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442.<br \/> \u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0436\u0435\u0440\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0440\u0430\u0434\u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">foreach ($items as $item) {     if ($item->isAvailable()) {         $availableItems[] = $item;     }     if ($item->isAcvite()) {         $activeItems[] = $item;     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$availableItems = $this->filterAvailableItems($items); $activeItems = $this->filterActiveItems($items); <\/code><\/pre>\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\/814995\/\"> https:\/\/habr.com\/ru\/articles\/814995\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439 \u0438 \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c\u0441\u044f, \u044f PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0435\u0442 \u043f\u043b\u043e\u0442\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 \u043d\u0430 symfony \u0438 \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043f\u043e\u0440\u043d\u044b\u0435, \u0434\u043b\u044f \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u0438 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.<\/p>\n<h4>1. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 di \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u044f\u0432\u043d\u043e<\/h4>\n<p>\u042f\u0432\u043d\u043e\u0435 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e. \u041f\u0440\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043c\u0430\u0433\u0438\u044e symfony di. \u0412\u043e\u043e\u0431\u0449\u0435 \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e autowiring \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u0440\u0435\u0434\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430. \u041f\u0440\u0438 \u044f\u0432\u043d\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"yaml\">App\\Services\\MyService: ~ <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@doctrine.orm.entity_manager'         - '@app.services.my_service.dependency' <\/code><\/pre>\n<h4>2. \u0412 DI \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/h4>\n<p>\u0422\u0430\u043a \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043f\u043e\u043e\u0449\u0440\u044f\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@App\\OtherService\\Producer\\ProducerInterface'  App\\OtherService\\Producer\\ProducerInterface:     alias: App\\OtherService\\Producer\\Amqp <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"yaml\">app.services.my_service:     class: App\\Services\\MyService     arguments:         - '@app.other_service.producer'  app.other_service.producer:     class: App\\OtherService\\Producer\\Amqp <\/code><\/pre>\n<h4>3. \u041d\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/h4>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     public function __construct(private readonly ContainerInterface $container) {}     public function doSomething()     {         $producer = $this->container->get('app.other_service.producer');         $producer->publish();     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     public function __construct(private readonly ProducerInterface $producer) {}     public function doSomething()     {         $producer->publish();     } } <\/code><\/pre>\n<h4>4. \u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c<\/h4>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044f\u0441\u044c \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0415\u0441\u043b\u0438 \u0432 \u043c\u0435\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<br \/> \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0435\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<pre><code class=\"php\">final class MyService implements MyServiceInterface {     \/\/ ... } <\/code><\/pre>\n<h4>5. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435.<\/h4>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">interface SomeEntityInterface {     public function getId(): int;     public function getName(): int;     public function getAge(): int; } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">interface IdAwareInterface {     public function getId(): int; } interface NameAwareInterface {     public function getName(): int; } interface AgeAwareInterface {     public function getAge(): int; } <\/code><\/pre>\n<h4>6. \u0412 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u043a\u0438\u0435 exception \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u044b<\/h4>\n<p>\u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u0438\u0445 exceptions \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b. \u0415\u0441\u043b\u0438 \u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0435\u0442 \u0431\u043b\u043e\u043a\u0430 <a class=\"mention\" href=\"\/users\/throws\">@throws<\/a> &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435 exception \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b.<\/p>\n<h4>7. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u043e\u0433\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c strict_types=1. \u0422\u0438\u043f\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0436\u0435\u0441\u0442\u043a\u043e.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">public function doSomething(mixed $id) {     return $id; } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">public function doSomething(int $id) {     return $id; } <\/code><\/pre>\n<h4>8. \u0424\u043b\u0430\u0433\u0438 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h4>\n<p>\u041d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u043e\u0449\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function doSomething($force = false)     {         if ($force) {             return $this->doForce()         }                  return $this->do()     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class ForceService {     public function doSomething()     {         return $this->doForce();     } } <\/code><\/pre>\n<h4>9. \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 3<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0433\u043e &#8212; \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u042d\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function doSomething($own, $two, $three, $four)     {     } } <\/code><\/pre>\n<h4>10. \u041d\u0435 \u043c\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\/\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/h4>\n<p>\u042d\u0442\u043e \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$item = new Item(); $this->calculateCount($item);  public function calculateCount(Item $item): void {     $count = 0;     \/\/ some logic     $item->setCount($count); } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$item = new Item(); $item->setCount($this->calculateCount());  public function calculateCount(): int {     $count = 0;     \/\/ some logic     return $count; } <\/code><\/pre>\n<h4>11. \u0417\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 DTO \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, readonly \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438, \u0431\u0435\u0437 get\/set \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h4>\n<p>\u0422\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0430 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0435\u0442 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u043a\u043e\u0434\u0430 get\/set, \u0442\u0430\u043a\u0430\u044f dto \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0430 \u0437\u0430 \u0441\u0447\u0451\u0442 readonly.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class Item {     public function __construct(         public readonly int $id,         public readonly int $count,         public readonly string $originId,     ) {     } }  $item = new Item(     id: 1,     count: 2,     originId: 'aaa-bbb-ccc', ); <\/code><\/pre>\n<h4>12. \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043c\u0435\u0442\u043e\u0434\u044b<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043c\u0435\u043d\u044c\u0448\u0435 ~150 \u0441\u0442\u0440\u043e\u043a, \u043c\u0435\u0442\u043e\u0434 \u043c\u0435\u043d\u044c\u0448\u0435 ~30 \u0441\u0442\u0440\u043e\u043a. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<h4>13. Unit \u0442\u0435\u0441\u0442\u044b \u0432\u0441\u0435\u0433\u0434\u0430<\/h4>\n<p>\u041d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u0434 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0448\u0435\u043c unit \u0442\u0435\u0441\u0442 (\u043a\u0440\u043e\u043c\u0435 dto). \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c skiptests &#8212; \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e.<\/p>\n<pre><code class=\"php\">\/**  * @skiptests tested in {@see \\App\\SomeOthreService}  *\/ final class SomeServiceTest extends TestCase { } <\/code><\/pre>\n<h4>14. \u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>\u0422\u0435\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u043d\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<br \/> \u041d\u0435 \u043d\u0430\u0434\u043e \u0432 \u0442\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043b\u043e\u0433\u0433\u0435\u0440\u0430, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u044d\u0442\u043e\u043c \u043d\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430. Stubs \u0438 dummy \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 mocks \u0438 fakes.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeServiceTest extends TestCase {     public function testDoSomething()     {         $logger = $this->createMock(LoggerInterface::class);         $logger->expects($this->once())             ->method('info')             ->with('some message');         $service = new SomeService($logger);                  $service->doSomething();     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class SomeServiceTest extends TestCase {     public function testDoSomething()     {         $service = new SomeService(             $this->createMock(LoggerInterface::class),         );                  $service->doSomething();     } } <\/code><\/pre>\n<h4>15. \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0430 \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438.<br \/> \u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService extends BaseLogic { } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">final class SomeService {     public function __construct(private readonly BaseLogic $logic) {}     public function execute()     {         $this->logic->doSomething();     } } <\/code><\/pre>\n<h4>16. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c final \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h4>\n<p>\u0422\u0430\u043a\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u043e\u0449\u0440\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<pre><code class=\"php\">final class SomeService { } <\/code><\/pre>\n<h4>17. \u041d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438<\/h4>\n<p>\u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0441\u043b\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c JMS\\Serializer\\SerializerInterface \u0438<br \/> JMS\\Serializer\\ArrayTransformerInterface.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$id = $data['id']; <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$id = $data->getId(); <\/code><\/pre>\n<h4>18. \u0421\u043e\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0437\u0430\u043a\u043e\u043d \u0414\u0435\u043c\u0435\u0442\u0440\u044b<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 \u0435\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u0446\u0430\u043c\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">$client = $this->clientFactory->create(); $client->send(); <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$this->clientDecorator->send(); <\/code><\/pre>\n<h4>19. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0446\u0438\u043a\u043b\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u041a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0441\u043a\u0438\u043c. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442.<br \/> \u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0436\u0435\u0440\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0440\u0430\u0434\u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u043b\u043e\u0445\u043e:<\/p>\n<pre><code class=\"php\">foreach ($items as $item) {     if ($item->isAvailable()) {         $availableItems[] = $item;     }     if ($item->isAcvite()) {         $activeItems[] = $item;     } } <\/code><\/pre>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e:<\/p>\n<pre><code class=\"php\">$availableItems = $this->filterAvailableItems($items); $activeItems = $this->filterActiveItems($items); <\/code><\/pre>\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\/814995\/\"> https:\/\/habr.com\/ru\/articles\/814995\/<\/a><br \/><\/br><\/br><\/p>\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-376364","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376364","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=376364"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376364\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}