From 0b0a6a9d46b02b43b47acf622c07cfc8f44a9116 Mon Sep 17 00:00:00 2001 From: Anton Kanevskiy Date: Tue, 12 Jan 2021 02:40:39 +0300 Subject: [PATCH] 1.1 improvements: - upped dependencies - update rules for phpcs to PSR12 --- composer.json | 20 +++++++------ phpcs.xml | 2 +- src/Controller/HomeController.php | 2 +- src/Controller/ItemController.php | 2 +- src/Controller/OrderController.php | 2 +- src/Core/Application.php | 8 +++--- src/Core/BaseRepository.php | 28 +++++++++---------- src/Core/DBConnection.php | 4 +-- src/Core/RequestAwareInterface.php | 2 +- src/Entity/Item.php | 2 +- src/Entity/Order.php | 6 ++-- src/Repository/ItemRepository.php | 6 ++-- src/Repository/OrderRepository.php | 6 ++-- src/Service/CreateOrderService.php | 2 +- src/Service/CreateOrderServiceInterface.php | 2 +- src/Service/Exception/APIServiceException.php | 2 +- src/Service/ItemGeneratorService.php | 4 +-- src/Service/ItemGeneratorServiceInterface.php | 2 +- src/Service/OrderPayService.php | 2 +- src/Service/OrderPayServiceInterface.php | 2 +- src/Validator/ValidatorException.php | 2 +- src/View/ItemViewFactory.php | 2 +- tests/Controller/ItemControllerTest.php | 6 ++-- tests/Controller/OrderControllerTest.php | 10 +++---- tests/FixturesTrait.php | 2 +- tests/RestTestCase.php | 2 +- tests/SchemaTrait.php | 2 +- tests/Service/CreateOrderServiceTest.php | 2 +- tests/Service/OrderPayServiceTest.php | 2 +- tests/TestCase.php | 2 +- 30 files changed, 70 insertions(+), 68 deletions(-) diff --git a/composer.json b/composer.json index 614f5e9..3a9f5c1 100644 --- a/composer.json +++ b/composer.json @@ -7,17 +7,19 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.1.3", - "symfony/http-foundation": "^4.3", - "symfony/routing": "^4.3", - "symfony/yaml": "^4.3", - "symfony/dependency-injection": "^4.3", - "symfony/config": "^4.3", - "symfony/expression-language": "^4.3", - "guzzlehttp/guzzle": "^6.3" + "php": "^7.3", + "ext-json": "*", + "ext-pdo": "*", + "symfony/http-foundation": "^4.4", + "symfony/routing": "^4.4", + "symfony/yaml": "^4.4", + "symfony/dependency-injection": "^4.4", + "symfony/config": "^4.4", + "symfony/expression-language": "^4.4", + "guzzlehttp/guzzle": "^6.5" }, "require-dev": { - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "*" }, "autoload": { diff --git a/phpcs.xml b/phpcs.xml index 3264fda..deb147a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -11,6 +11,6 @@ - + diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index b914c9a..6795e97 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -1,6 +1,6 @@ $this->environment, ]); - $confDir = $this->rootDir.'/config'; + $confDir = $this->rootDir . '/config'; $loader = new DIYamlFileLoader($container, new FileLocator($confDir)); $loader->load('services.yaml'); // Настройка сервисов для конкретного окружения - $environmentConfigFile = sprintf($confDir.'/services_%s.yaml', $this->environment); + $environmentConfigFile = sprintf($confDir . '/services_%s.yaml', $this->environment); if (file_exists($environmentConfigFile)) { $loader->load($environmentConfigFile); } @@ -130,7 +130,7 @@ private function initDIContainer(): void */ private function initURLMatcher(Request $request): void { - $loader = new YamlFileLoader(new FileLocator($this->rootDir.'/config')); + $loader = new YamlFileLoader(new FileLocator($this->rootDir . '/config')); $routes = $loader->load('routes.yaml'); $context = new RequestContext(); diff --git a/src/Core/BaseRepository.php b/src/Core/BaseRepository.php index eee45e6..e72b1a7 100644 --- a/src/Core/BaseRepository.php +++ b/src/Core/BaseRepository.php @@ -1,6 +1,6 @@ fields as $field) { $property = $this->normalizeToCamelCase($field); - $value = $entity->{'get'.ucfirst($property)}(); + $value = $entity->{'get' . ucfirst($property)}(); $data[$field] = $this->formatValueToDBFormat($field, $value); } @@ -123,7 +123,7 @@ public function save(EntityInterface $entity) if (empty($id)) { $id = $this->insertRow($data); // TODO сделать проставление св-ва id через ReflectionProperty - $idSetter = 'set'.ucfirst(static::PRIMARY_KEY); + $idSetter = 'set' . ucfirst(static::PRIMARY_KEY); $entity->{$idSetter}((int)$id); } else { $this->updateRow((int)$id, $data); @@ -217,14 +217,14 @@ private function checkEntityClassStructure() ); } - $getterMethod = 'get'.ucfirst($property); + $getterMethod = 'get' . ucfirst($property); if (!$entityClass->hasMethod($getterMethod)) { throw new \LogicException( sprintf('You should specify %s::%s', $this->entityClass, $getterMethod) ); } - $setterMethod = 'set'.ucfirst($property); + $setterMethod = 'set' . ucfirst($property); if (!$entityClass->hasMethod($setterMethod)) { throw new \LogicException( sprintf('You should specify %s::%s', $this->entityClass, $setterMethod) @@ -265,7 +265,7 @@ private function makeEntity(array $data): EntityInterface foreach ($data as $key => $value) { $value = $this->formatValueToEntityFormat($key, $value); $property = $this->normalizeToCamelCase($key); - $entity->{'set'.ucfirst($property)}($value); + $entity->{'set' . ucfirst($property)}($value); } return $entity; @@ -360,7 +360,7 @@ private function camelToSnakeCase(string $propertyName) private function normalizeToCamelCase(string $column): string { $camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { - return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); + return ('.' === $match[1] ? '_' : '') . strtoupper($match[2]); }, $column); return lcfirst($camelCasedName); diff --git a/src/Core/DBConnection.php b/src/Core/DBConnection.php index 7a3ba2d..9cab527 100644 --- a/src/Core/DBConnection.php +++ b/src/Core/DBConnection.php @@ -1,6 +1,6 @@ self::COLUMN_TYPE_INT, 'name' => self::COLUMN_TYPE_STRING, 'price' => self::COLUMN_TYPE_FLOAT, diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php index 1525281..c9ade16 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/OrderRepository.php @@ -1,6 +1,6 @@ self::COLUMN_TYPE_INT, 'created_at' => self::COLUMN_TYPE_DATE_TIME, 'amount' => self::COLUMN_TYPE_FLOAT, diff --git a/src/Service/CreateOrderService.php b/src/Service/CreateOrderService.php index 2a29562..634ff52 100644 --- a/src/Service/CreateOrderService.php +++ b/src/Service/CreateOrderService.php @@ -1,6 +1,6 @@ 150.00, ], ], - ItemRepository::TABLE_NAME + 'items' ); $response = $this->get('/api/items'); @@ -88,7 +88,7 @@ public function testGetItemsResponse() /** * Проверка, что отдается пустой респонс, когда в бд нет товаров */ - public function testGetItemsEmptyResponse() + public function testGetItemsWithEmptyResponse() { $response = $this->get('/api/items'); diff --git a/tests/Controller/OrderControllerTest.php b/tests/Controller/OrderControllerTest.php index e989539..cf46e39 100644 --- a/tests/Controller/OrderControllerTest.php +++ b/tests/Controller/OrderControllerTest.php @@ -1,6 +1,6 @@ post( '/api/order/create', @@ -79,11 +79,11 @@ public function testCreateOrderBadRequestResponse(string $content) } /** - * Данные ревеста для testCreateOrderBadRequestResponse + * Данные ревеста для testCreateOrderWithBadRequestResponse * * @return array */ - public function provideTestCreateOrderBadRequestResponse(): array + public function provideTestCreateOrderWithBadRequestResponse(): array { return [ [ diff --git a/tests/FixturesTrait.php b/tests/FixturesTrait.php index bebfbc5..c7d91a1 100644 --- a/tests/FixturesTrait.php +++ b/tests/FixturesTrait.php @@ -1,6 +1,6 @@