Skip to content

Commit

Permalink
Merge pull request #1 from antonkanevsky/release-1.1
Browse files Browse the repository at this point in the history
1.1 improvements
  • Loading branch information
antonkanevsky authored Jan 11, 2021
2 parents 7b11056 + 0b0a6a9 commit 56277bb
Show file tree
Hide file tree
Showing 30 changed files with 70 additions and 68 deletions.
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR2"/>
<rule ref="PSR12"/>

</ruleset>
2 changes: 1 addition & 1 deletion src/Controller/HomeController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Controller;

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ItemController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Controller;

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/OrderController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Controller;

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Core;

Expand Down Expand Up @@ -109,11 +109,11 @@ private function initDIContainer(): void
'app.environment' => $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);
}
Expand All @@ -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();
Expand Down
28 changes: 14 additions & 14 deletions src/Core/BaseRepository.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Core;

Expand All @@ -12,23 +12,23 @@ abstract class BaseRepository
/**
* Название таблицы сущности
*/
const TABLE_NAME = '';
public const TABLE_NAME = '';

/**
* Маппинг полей к типам в бд
*/
const FIELDS_TYPE_MAPPING = [];
protected const FIELDS_TYPE_MAPPING = [];

/**
* Первичный ключ по умолчанию
*/
const PRIMARY_KEY = 'id';
protected const PRIMARY_KEY = 'id';

// Типы колонок в БД
const COLUMN_TYPE_INT = 1;
const COLUMN_TYPE_FLOAT = 2;
const COLUMN_TYPE_STRING = 3;
const COLUMN_TYPE_DATE_TIME = 4;
protected const COLUMN_TYPE_INT = 1;
protected const COLUMN_TYPE_FLOAT = 2;
protected const COLUMN_TYPE_STRING = 3;
protected const COLUMN_TYPE_DATE_TIME = 4;

/**
* Поля сущности в бд
Expand Down Expand Up @@ -113,7 +113,7 @@ public function save(EntityInterface $entity)
$data = [];
foreach ($this->fields as $field) {
$property = $this->normalizeToCamelCase($field);
$value = $entity->{'get'.ucfirst($property)}();
$value = $entity->{'get' . ucfirst($property)}();
$data[$field] = $this->formatValueToDBFormat($field, $value);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/DBConnection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Core;

Expand All @@ -15,7 +15,7 @@ class DBConnection
/**
* Объект соединения с БД
*
* @var \PDO
* @var PDO
*/
private $connection;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/RequestAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Core;

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Item.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Entity;

Expand Down
6 changes: 3 additions & 3 deletions src/Entity/Order.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Entity;

Expand All @@ -15,12 +15,12 @@ class Order implements EntityInterface
/**
* Статус "Новый"
*/
const STATUS_NEW = 'new';
public const STATUS_NEW = 'new';

/**
* Статус "Оплачен"
*/
const STATUS_PAID = 'paid';
public const STATUS_PAID = 'paid';

/**
* Статусы заказа
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/ItemRepository.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Repository;

Expand All @@ -19,12 +19,12 @@ class ItemRepository extends BaseRepository
/**
* {@inheritdoc}
*/
const TABLE_NAME = 'items';
public const TABLE_NAME = 'items';

/**
* {@inheritdoc}
*/
const FIELDS_TYPE_MAPPING = [
protected const FIELDS_TYPE_MAPPING = [
'id' => self::COLUMN_TYPE_INT,
'name' => self::COLUMN_TYPE_STRING,
'price' => self::COLUMN_TYPE_FLOAT,
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Repository;

Expand All @@ -20,12 +20,12 @@ class OrderRepository extends BaseRepository
/**
* {@inheritdoc}
*/
const TABLE_NAME = 'orders';
public const TABLE_NAME = 'orders';

/**
* {@inheritdoc}
*/
const FIELDS_TYPE_MAPPING = [
protected const FIELDS_TYPE_MAPPING = [
'id' => self::COLUMN_TYPE_INT,
'created_at' => self::COLUMN_TYPE_DATE_TIME,
'amount' => self::COLUMN_TYPE_FLOAT,
Expand Down
2 changes: 1 addition & 1 deletion src/Service/CreateOrderService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand Down
2 changes: 1 addition & 1 deletion src/Service/CreateOrderServiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand Down
2 changes: 1 addition & 1 deletion src/Service/Exception/APIServiceException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service\Exception;

Expand Down
4 changes: 2 additions & 2 deletions src/Service/ItemGeneratorService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand All @@ -15,7 +15,7 @@ class ItemGeneratorService implements ItemGeneratorServiceInterface
/**
* Лимит товаров для генерации (по умолчанию)
*/
const DEFAULT_LIMIT = 20;
private const DEFAULT_LIMIT = 20;

/**
* Репозиторий товаров
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ItemGeneratorServiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand Down
2 changes: 1 addition & 1 deletion src/Service/OrderPayService.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand Down
2 changes: 1 addition & 1 deletion src/Service/OrderPayServiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Service;

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/ValidatorException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Validator;

Expand Down
2 changes: 1 addition & 1 deletion src/View/ItemViewFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\View;

Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/ItemControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace App\Tests\Controller;

Expand Down Expand Up @@ -59,7 +59,7 @@ public function testGetItemsResponse()
'price' => 150.00,
],
],
ItemRepository::TABLE_NAME
'items'
);

$response = $this->get('/api/items');
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testGetItemsResponse()
/**
* Проверка, что отдается пустой респонс, когда в бд нет товаров
*/
public function testGetItemsEmptyResponse()
public function testGetItemsWithEmptyResponse()
{
$response = $this->get('/api/items');

Expand Down
Loading

0 comments on commit 56277bb

Please sign in to comment.