From 2b3fa0476b632a2daaa670ff5c466677e9a100d1 Mon Sep 17 00:00:00 2001
From: "Alex. Plokhikh" <a.plohih@iqdev.digital>
Date: Mon, 15 Apr 2024 15:29:30 +0500
Subject: [PATCH] sumplify solution

---
 src/Actions/InterfaceAction.php    | 14 ----------
 src/Entity/InterfaceDataEntity.php | 15 -----------
 src/Entity/PricesEntity.php        | 39 ----------------------------
 src/Service/ValidationService.php  | 41 ------------------------------
 4 files changed, 109 deletions(-)
 delete mode 100644 src/Actions/InterfaceAction.php
 delete mode 100644 src/Entity/InterfaceDataEntity.php
 delete mode 100644 src/Entity/PricesEntity.php
 delete mode 100644 src/Service/ValidationService.php

diff --git a/src/Actions/InterfaceAction.php b/src/Actions/InterfaceAction.php
deleted file mode 100644
index f4dcce0..0000000
--- a/src/Actions/InterfaceAction.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-namespace App\Actions;
-
-use App\Entity\InterfaceDataEntity;
-
-interface InterfaceAction
-{
-    /**
-     * абстрактная функция испольняет описаный функционал в контроллере
-     * @param array $array массив тела реквеста
-     */
-    public function act(InterfaceDataEntity $model): mixed;
-}
diff --git a/src/Entity/InterfaceDataEntity.php b/src/Entity/InterfaceDataEntity.php
deleted file mode 100644
index 9580e66..0000000
--- a/src/Entity/InterfaceDataEntity.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-namespace App\Entity;
-
-use Symfony\Component\HttpFoundation\Request;
-
-interface InterfaceDataEntity
-{
-    /**
-     * преобразование реквеста в модель
-     * @param Request $request
-     * @return void
-     */
-    public function serialise(Request $request): void;
-}
diff --git a/src/Entity/PricesEntity.php b/src/Entity/PricesEntity.php
deleted file mode 100644
index 2b3257f..0000000
--- a/src/Entity/PricesEntity.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-namespace App\Entity;
-
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Validator\Constraints\All;
-use Symfony\Component\Validator\Constraints\Collection;
-use Symfony\Component\Validator\Constraints\NotBlank;
-use Symfony\Component\Validator\Constraints\Type;
-use Symfony\Contracts\Service\Attribute\Required;
-
-class PricesEntity implements InterfaceDataEntity
-{
-    #[Type('array')]
-    #[NotBlank()]
-    #[Required()]
-    #[All(
-        constraints: [
-            new Collection(
-                fields: [
-                    'price' => [
-                        new NotBlank(),
-                        new Type('integer'),
-                    ],
-                    'count' => [
-                        new NotBlank(),
-                        new Type('integer'),
-                    ],
-                ],
-            )
-        ]
-    )]
-    public $prices;
-
-    public function serialise(Request $request): void
-    {
-        $this->prices = $request->toArray()['prices'];
-    }
-}
diff --git a/src/Service/ValidationService.php b/src/Service/ValidationService.php
deleted file mode 100644
index cd9df8c..0000000
--- a/src/Service/ValidationService.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Entity\InterfaceDataEntity;
-use Symfony\Component\HttpFoundation\JsonResponse;
-use Symfony\Component\Validator\Validation;
-
-class ValidationService
-{
-    /**
-     * Валидирование содержимого модели согласно атрибутам парамтров
-     * @param InterfaceDataEntity $model
-     * @return void
-     */
-    public function validate(InterfaceDataEntity $model): void
-    {
-        $validator = Validation::createValidator();
-        $errors = $validator->validate($model);
-
-        $messages = [
-            'message' => 'validation_fail',
-            'errors' => [],
-        ];
-
-        foreach ($errors as $error) {
-            $messages['errors'][] = [
-                'property' => $error->getPropertyPath(),
-                'value' => $error->getInvalidValue(),
-                'message' => $error->getMessage(),
-            ];
-        }
-
-        if (count($messages['errors']) > 0) {
-            $response = new JsonResponse($messages, 400);
-            $response->send();
-
-            exit;
-        }
-    }
-}
\ No newline at end of file
-- 
GitLab