Skip to content

Commit

Permalink
Refactor EloquentVersionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin255 committed Sep 9, 2024
1 parent 681437c commit 8f40a8f
Show file tree
Hide file tree
Showing 29 changed files with 170 additions and 112 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"coverage": "vendor/bin/phpunit --configuration phpunit.xml.dist --coverage-html=tests/coverage",
"fixer": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -vv --allow-risky=yes",
"linter": [
"vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -vv --dry-run --stop-on-violation --allow-risky=yes",
"vendor/bin/psalm --show-info=true --php-version=$(php -r \"echo phpversion();\")"
"vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -vv --dry-run --stop-on-violation --allow-risky=yes",
"vendor/bin/psalm --show-info=true --php-version=$(php -r \"echo phpversion();\")"
],
"entities": [
"php -f generator/generate_entities.php",
"vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes -q"
"php -f generator/generate_entities.php",
"vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes -q"
]
},
"extra": {
Expand Down
6 changes: 4 additions & 2 deletions generator/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected function decorateClass(ClassType $class, EntityDescriptor $descriptor)
$class->addComment("{$description}.\n");
}

$class->addComment('@psalm-consistent-constructor');

$isPrimaryIsUuid = false;
$primaryName = null;
$fill = [];
Expand Down Expand Up @@ -106,7 +108,7 @@ protected function decorateClass(ClassType $class, EntityDescriptor $descriptor)
$fillableValue = new Literal("[\n '" . implode("',\n '", $fill) . "',\n]");
$class->addProperty('fillable', $fillableValue)
->setVisibility('protected')
->addComment('@var string[]')
->addComment('@var array<int, string>')
;

$castValue = new Literal($this->createCastValue($descriptor));
Expand All @@ -116,7 +118,7 @@ protected function decorateClass(ClassType $class, EntityDescriptor $descriptor)
;

$connectionMethod = "\$connection = \$this->connection;\n";
$connectionMethod .= "if (\\function_exists('app') && app()->has('config')) {\n";
$connectionMethod .= "if (\\function_exists('app') && app()->has('config') === true) {\n";
$connectionMethod .= " /** @var string|null */\n";
$connectionMethod .= " \$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: \$this->connection;\n";
$connectionMethod .= "}\n\n";
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<testsuites>
<testsuite name="LiquetsoftFiasBundle tests suit">
<directory>./tests</directory>
Expand All @@ -17,4 +12,9 @@
<env name="DB_PASSWORD" value=""/>
<env name="DB_NAME" value=""/>
</php>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
6 changes: 4 additions & 2 deletions src/Entity/AddrObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения классификатора адресообразующих элементов.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор адресного объекта типа INTEGER
* @property string $objectguid Глобальный уникальный идентификатор адресного объекта типа UUID
Expand Down Expand Up @@ -39,7 +41,7 @@ class AddrObj extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -85,7 +87,7 @@ class AddrObj extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/AddrObjDivision.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по операциям переподчинения.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $parentid Родительский ID
* @property int $childid Дочерний ID
Expand All @@ -28,7 +30,7 @@ class AddrObjDivision extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'parentid',
Expand All @@ -52,7 +54,7 @@ class AddrObjDivision extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/AddrObjTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по типам адресных объектов.
*
* @psalm-consistent-constructor
*
* @property int $id Идентификатор записи
* @property int $level Уровень адресного объекта
* @property string $shortname Краткое наименование типа объекта
Expand All @@ -33,7 +35,7 @@ class AddrObjTypes extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'level',
Expand Down Expand Up @@ -67,7 +69,7 @@ class AddrObjTypes extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/AdmHierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по иерархии в административном делении.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор объекта
* @property int|null $parentobjid Идентификатор родительского объекта
Expand Down Expand Up @@ -41,7 +43,7 @@ class AdmHierarchy extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -91,7 +93,7 @@ class AdmHierarchy extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/ApartmentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по типам помещений.
*
* @psalm-consistent-constructor
*
* @property int $id Идентификатор типа (ключ)
* @property string $name Наименование
* @property string|null $shortname Краткое наименование
Expand All @@ -32,7 +34,7 @@ class ApartmentTypes extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'name',
Expand Down Expand Up @@ -64,7 +66,7 @@ class ApartmentTypes extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Apartments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по помещениям.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор объекта типа INTEGER
* @property string $objectguid Глобальный уникальный идентификатор адресного объекта типа UUID
Expand Down Expand Up @@ -38,7 +40,7 @@ class Apartments extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -82,7 +84,7 @@ class Apartments extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Carplaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по машино-местам.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор объекта типа INTEGER
* @property string $objectguid Глобальный уникальный идентификатор адресного объекта типа UUID
Expand Down Expand Up @@ -37,7 +39,7 @@ class Carplaces extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -79,7 +81,7 @@ class Carplaces extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/ChangeHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по истории изменений.
*
* @psalm-consistent-constructor
*
* @property int $changeid ID изменившей транзакции
* @property int $objectid Уникальный ID объекта
* @property string $adrobjectid Уникальный ID изменившей транзакции (GUID)
Expand All @@ -30,7 +32,7 @@ class ChangeHistory extends Model
/** @var string */
protected $primaryKey = 'changeid';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'changeid',
'objectid',
Expand Down Expand Up @@ -58,7 +60,7 @@ class ChangeHistory extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/FiasVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Модель, которая хранит историю версий ФИАС.
*
* @psalm-consistent-constructor
*
* @property int $version Номер версии ФИАС
* @property string $fullurl Ссылка для загрузки полной версии ФИАС
* @property string $deltaurl Ссылка для загрузки обновления до версии ФИАС
Expand All @@ -28,7 +30,7 @@ class FiasVersion extends Model
/** @var string */
protected $primaryKey = 'version';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'version',
'fullurl',
Expand All @@ -52,7 +54,7 @@ class FiasVersion extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/HouseTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по типам домов.
*
* @psalm-consistent-constructor
*
* @property int $id Идентификатор
* @property string $name Наименование
* @property string|null $shortname Краткое наименование
Expand All @@ -32,7 +34,7 @@ class HouseTypes extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'name',
Expand Down Expand Up @@ -64,7 +66,7 @@ class HouseTypes extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/Houses.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по номерам домов улиц городов и населенных пунктов.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор объекта типа INTEGER
* @property string $objectguid Глобальный уникальный идентификатор адресного объекта типа UUID
Expand Down Expand Up @@ -42,7 +44,7 @@ class Houses extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -94,7 +96,7 @@ class Houses extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/MunHierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* Сведения по иерархии в муниципальном делении.
*
* @psalm-consistent-constructor
*
* @property int $id Уникальный идентификатор записи. Ключевое поле
* @property int $objectid Глобальный уникальный идентификатор адресного объекта
* @property int|null $parentobjid Идентификатор родительского объекта
Expand Down Expand Up @@ -36,7 +38,7 @@ class MunHierarchy extends Model
/** @var string */
protected $primaryKey = 'id';

/** @var string[] */
/** @var array<int, string> */
protected $fillable = [
'id',
'objectid',
Expand Down Expand Up @@ -76,7 +78,7 @@ class MunHierarchy extends Model
public function getConnectionName()
{
$connection = $this->connection;
if (\function_exists('app') && app()->has('config')) {
if (\function_exists('app') && app()->has('config') === true) {
/** @var string|null */
$connection = app('config')->get('liquetsoft_fias.eloquent_connection') ?: $this->connection;
}
Expand Down
Loading

0 comments on commit 8f40a8f

Please sign in to comment.