Skip to content

Commit 09b0533

Browse files
committed
Легкое psalm причесывание
1 parent db7e265 commit 09b0533

File tree

17 files changed

+641
-327
lines changed

17 files changed

+641
-327
lines changed

arrilot/BaseMigrations/BitrixMigration.php

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
use CIBlockProperty;
1111
use CUserTypeEntity;
1212

13+
/**
14+
* Class BitrixMigration
15+
* @package Arrilot\BitrixMigrationsFork\BaseMigrations
16+
*/
1317
class BitrixMigration implements MigrationInterface
1418
{
1519
/**
@@ -20,7 +24,7 @@ class BitrixMigration implements MigrationInterface
2024
protected $db;
2125

2226
/**
23-
* @var bool
27+
* @var boolean|null $use_transaction
2428
*/
2529
public $use_transaction = null;
2630

@@ -33,29 +37,25 @@ public function __construct()
3337
}
3438

3539
/**
36-
* Run the migration.
37-
*
38-
* @return mixed
40+
* @inheritDoc
41+
* @psalm-suppress InvalidReturnType
3942
*/
4043
public function up()
4144
{
4245
//
4346
}
4447

4548
/**
46-
* Reverse the migration.
47-
*
48-
* @return mixed
49+
* @inheritDoc
50+
* @psalm-suppress InvalidReturnType
4951
*/
5052
public function down()
5153
{
5254
//
5355
}
5456

5557
/**
56-
* Does migration use transaction
57-
* @param bool $default
58-
* @return bool
58+
* @inheritDoc
5959
*/
6060
public function useTransaction($default = false)
6161
{
@@ -69,14 +69,14 @@ public function useTransaction($default = false)
6969
/**
7070
* Find iblock id by its code.
7171
*
72-
* @param string $code
73-
* @param null|string $iBlockType
72+
* @param string $code Код инфоблока.
73+
* @param null|string $iBlockType Тип инфоблока.
7474
*
7575
* @throws MigrationException
7676
*
77-
* @return int
77+
* @return integer
7878
*/
79-
protected function getIblockIdByCode($code, $iBlockType = null)
79+
protected function getIblockIdByCode(string $code, ?string $iBlockType = null) : int
8080
{
8181
if (!$code) {
8282
throw new MigrationException('Не задан код инфоблока');
@@ -97,19 +97,19 @@ protected function getIblockIdByCode($code, $iBlockType = null)
9797
throw new MigrationException("Не удалось найти инфоблок с кодом '{$code}'");
9898
}
9999

100-
return $iblock['ID'];
100+
return (int)$iblock['ID'];
101101
}
102102

103103
/**
104104
* Delete iblock by its code.
105105
*
106-
* @param string $code
106+
* @param string $code Код инфоблока.
107107
*
108-
* @throws MigrationException
108+
* @throws MigrationException Когда не удалось удалить инфоблок.
109109
*
110110
* @return void
111111
*/
112-
protected function deleteIblockByCode($code)
112+
protected function deleteIblockByCode(string $code) : void
113113
{
114114
$id = $this->getIblockIdByCode($code);
115115

@@ -125,13 +125,12 @@ protected function deleteIblockByCode($code)
125125
/**
126126
* Add iblock element property.
127127
*
128-
* @param array $fields
128+
* @param array $fields Значения полей.
129129
*
130+
* @return integer
130131
* @throws MigrationException
131-
*
132-
* @return int
133132
*/
134-
public function addIblockElementProperty($fields)
133+
public function addIblockElementProperty(array $fields)
135134
{
136135
$ibp = new CIBlockProperty();
137136
$propId = $ibp->add($fields);
@@ -146,12 +145,14 @@ public function addIblockElementProperty($fields)
146145
/**
147146
* Delete iblock element property.
148147
*
149-
* @param string $code
150-
* @param string|int $iblockId
148+
* @param integer $iblockId ID инфоблока.
149+
* @param string $code Код инфоблока.
150+
*
151+
* @return void
151152
*
152153
* @throws MigrationException
153154
*/
154-
public function deleteIblockElementPropertyByCode($iblockId, $code)
155+
public function deleteIblockElementPropertyByCode($iblockId, string $code)
155156
{
156157
if (!$iblockId) {
157158
throw new MigrationException('Не задан ID инфоблока');
@@ -169,13 +170,13 @@ public function deleteIblockElementPropertyByCode($iblockId, $code)
169170
/**
170171
* Add User Field.
171172
*
172-
* @param $fields
173+
* @param array $fields Значения полей.
173174
*
174175
* @throws MigrationException
175176
*
176-
* @return int
177+
* @return integer
177178
*/
178-
public function addUF($fields)
179+
public function addUF(array $fields)
179180
{
180181
if (!$fields['FIELD_NAME']) {
181182
throw new MigrationException('Не заполнен FIELD_NAME');
@@ -190,7 +191,9 @@ public function addUF($fields)
190191
$fieldId = $oUserTypeEntity->Add($fields);
191192

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

196199
return $fieldId;
@@ -199,12 +202,13 @@ public function addUF($fields)
199202
/**
200203
* Get UF by its code.
201204
*
202-
* @param string $entity
203-
* @param string $code
205+
* @param string $entity Сущность свойства.
206+
* @param string $code Код свойства.
204207
*
208+
* @return integer
205209
* @throws MigrationException
206210
*/
207-
public function getUFIdByCode($entity, $code)
211+
public function getUFIdByCode(string $entity, string $code)
208212
{
209213
if (!$entity) {
210214
throw new MigrationException('Не задана сущность свойства');
@@ -228,14 +232,14 @@ public function getUFIdByCode($entity, $code)
228232
}
229233

230234
/**
231-
* @param $code
232-
* @param $iblockId
235+
* @param string $code
236+
* @param integer $iblockId
233237
*
234238
* @throws MigrationException
235239
*
236-
* @return array
240+
* @return integer
237241
*/
238-
protected function getIblockPropIdByCode($code, $iblockId)
242+
protected function getIblockPropIdByCode(string $code, int $iblockId) : int
239243
{
240244
$filter = [
241245
'CODE' => $code,
@@ -247,20 +251,19 @@ protected function getIblockPropIdByCode($code, $iblockId)
247251
throw new MigrationException("Не удалось найти свойство с кодом '{$code}'");
248252
}
249253

250-
return $prop['ID'];
254+
return (int)$prop['ID'];
251255
}
252256

253257
/**
254-
* @param integer $idIblock
255-
* @param integer|string $code
256-
* @param array $fields
258+
* @param integer $idIblock ID инфоблока.
259+
* @param integer|string $code Код свойства.
260+
* @param array $fields Поля.
257261
*
258262
* @return void
259263
* @throws MigrationException
260264
*/
261-
public function updateProperty(int $idIblock, string $code, array $fields) : void
265+
public function updateProperty(int $idIblock, $code, array $fields) : void
262266
{
263-
$idIblock = (int)$idIblock;
264267
if ($idIblock <= 0) {
265268
throw new MigrationException('You must set iblock id due to ambiguity avoiding');
266269
}

arrilot/Constructors/FieldConstructor.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
<?php
22

3-
43
namespace Arrilot\BitrixMigrationsFork\Constructors;
54

6-
5+
/**
6+
* Trait FieldConstructor
7+
* @package Arrilot\BitrixMigrationsFork\Constructors
8+
*/
79
trait FieldConstructor
810
{
9-
/** @var array */
11+
/**
12+
* @var array $fields
13+
*/
1014
public $fields = [];
1115

16+
/**
17+
* @var array $defaultFields
18+
*/
1219
public static $defaultFields = [];
1320

1421
/**
15-
* Получить итоговые настройки полей
22+
* Получить итоговые настройки полей.
1623
*/
17-
public function getFieldsWithDefault()
24+
public function getFieldsWithDefault() : array
1825
{
1926
return array_merge((array)static::$defaultFields[get_called_class()], $this->fields);
2027
}

0 commit comments

Comments
 (0)