Skip to content

Commit

Permalink
Легкое psalm причесывание
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jun 28, 2021
1 parent db7e265 commit 09b0533
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 327 deletions.
87 changes: 45 additions & 42 deletions arrilot/BaseMigrations/BitrixMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use CIBlockProperty;
use CUserTypeEntity;

/**
* Class BitrixMigration
* @package Arrilot\BitrixMigrationsFork\BaseMigrations
*/
class BitrixMigration implements MigrationInterface
{
/**
Expand All @@ -20,7 +24,7 @@ class BitrixMigration implements MigrationInterface
protected $db;

/**
* @var bool
* @var boolean|null $use_transaction
*/
public $use_transaction = null;

Expand All @@ -33,29 +37,25 @@ public function __construct()
}

/**
* Run the migration.
*
* @return mixed
* @inheritDoc
* @psalm-suppress InvalidReturnType
*/
public function up()
{
//
}

/**
* Reverse the migration.
*
* @return mixed
* @inheritDoc
* @psalm-suppress InvalidReturnType
*/
public function down()
{
//
}

/**
* Does migration use transaction
* @param bool $default
* @return bool
* @inheritDoc
*/
public function useTransaction($default = false)
{
Expand All @@ -69,14 +69,14 @@ public function useTransaction($default = false)
/**
* Find iblock id by its code.
*
* @param string $code
* @param null|string $iBlockType
* @param string $code Код инфоблока.
* @param null|string $iBlockType Тип инфоблока.
*
* @throws MigrationException
*
* @return int
* @return integer
*/
protected function getIblockIdByCode($code, $iBlockType = null)
protected function getIblockIdByCode(string $code, ?string $iBlockType = null) : int
{
if (!$code) {
throw new MigrationException('Не задан код инфоблока');
Expand All @@ -97,19 +97,19 @@ protected function getIblockIdByCode($code, $iBlockType = null)
throw new MigrationException("Не удалось найти инфоблок с кодом '{$code}'");
}

return $iblock['ID'];
return (int)$iblock['ID'];
}

/**
* Delete iblock by its code.
*
* @param string $code
* @param string $code Код инфоблока.
*
* @throws MigrationException
* @throws MigrationException Когда не удалось удалить инфоблок.
*
* @return void
*/
protected function deleteIblockByCode($code)
protected function deleteIblockByCode(string $code) : void
{
$id = $this->getIblockIdByCode($code);

Expand All @@ -125,13 +125,12 @@ protected function deleteIblockByCode($code)
/**
* Add iblock element property.
*
* @param array $fields
* @param array $fields Значения полей.
*
* @return integer
* @throws MigrationException
*
* @return int
*/
public function addIblockElementProperty($fields)
public function addIblockElementProperty(array $fields)
{
$ibp = new CIBlockProperty();
$propId = $ibp->add($fields);
Expand All @@ -146,12 +145,14 @@ public function addIblockElementProperty($fields)
/**
* Delete iblock element property.
*
* @param string $code
* @param string|int $iblockId
* @param integer $iblockId ID инфоблока.
* @param string $code Код инфоблока.
*
* @return void
*
* @throws MigrationException
*/
public function deleteIblockElementPropertyByCode($iblockId, $code)
public function deleteIblockElementPropertyByCode($iblockId, string $code)
{
if (!$iblockId) {
throw new MigrationException('Не задан ID инфоблока');
Expand All @@ -169,13 +170,13 @@ public function deleteIblockElementPropertyByCode($iblockId, $code)
/**
* Add User Field.
*
* @param $fields
* @param array $fields Значения полей.
*
* @throws MigrationException
*
* @return int
* @return integer
*/
public function addUF($fields)
public function addUF(array $fields)
{
if (!$fields['FIELD_NAME']) {
throw new MigrationException('Не заполнен FIELD_NAME');
Expand All @@ -190,7 +191,9 @@ public function addUF($fields)
$fieldId = $oUserTypeEntity->Add($fields);

if (!$fieldId) {
throw new MigrationException("Не удалось создать пользовательское свойство с FIELD_NAME = {$fields['FIELD_NAME']} и ENTITY_ID = {$fields['ENTITY_ID']}");
throw new MigrationException(
"Не удалось создать пользовательское свойство с FIELD_NAME = {$fields['FIELD_NAME']} и ENTITY_ID = {$fields['ENTITY_ID']}"
);
}

return $fieldId;
Expand All @@ -199,12 +202,13 @@ public function addUF($fields)
/**
* Get UF by its code.
*
* @param string $entity
* @param string $code
* @param string $entity Сущность свойства.
* @param string $code Код свойства.
*
* @return integer
* @throws MigrationException
*/
public function getUFIdByCode($entity, $code)
public function getUFIdByCode(string $entity, string $code)
{
if (!$entity) {
throw new MigrationException('Не задана сущность свойства');
Expand All @@ -228,14 +232,14 @@ public function getUFIdByCode($entity, $code)
}

/**
* @param $code
* @param $iblockId
* @param string $code
* @param integer $iblockId
*
* @throws MigrationException
*
* @return array
* @return integer
*/
protected function getIblockPropIdByCode($code, $iblockId)
protected function getIblockPropIdByCode(string $code, int $iblockId) : int
{
$filter = [
'CODE' => $code,
Expand All @@ -247,20 +251,19 @@ protected function getIblockPropIdByCode($code, $iblockId)
throw new MigrationException("Не удалось найти свойство с кодом '{$code}'");
}

return $prop['ID'];
return (int)$prop['ID'];
}

/**
* @param integer $idIblock
* @param integer|string $code
* @param array $fields
* @param integer $idIblock ID инфоблока.
* @param integer|string $code Код свойства.
* @param array $fields Поля.
*
* @return void
* @throws MigrationException
*/
public function updateProperty(int $idIblock, string $code, array $fields) : void
public function updateProperty(int $idIblock, $code, array $fields) : void
{
$idIblock = (int)$idIblock;
if ($idIblock <= 0) {
throw new MigrationException('You must set iblock id due to ambiguity avoiding');
}
Expand Down
17 changes: 12 additions & 5 deletions arrilot/Constructors/FieldConstructor.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<?php


namespace Arrilot\BitrixMigrationsFork\Constructors;


/**
* Trait FieldConstructor
* @package Arrilot\BitrixMigrationsFork\Constructors
*/
trait FieldConstructor
{
/** @var array */
/**
* @var array $fields
*/
public $fields = [];

/**
* @var array $defaultFields
*/
public static $defaultFields = [];

/**
* Получить итоговые настройки полей
* Получить итоговые настройки полей.
*/
public function getFieldsWithDefault()
public function getFieldsWithDefault() : array
{
return array_merge((array)static::$defaultFields[get_called_class()], $this->fields);
}
Expand Down
Loading

0 comments on commit 09b0533

Please sign in to comment.