Skip to content

Commit 40fde17

Browse files
committed
Причесывание
1 parent cb18b90 commit 40fde17

File tree

7 files changed

+58
-68
lines changed

7 files changed

+58
-68
lines changed

Services/FixtureGenerator.php

+3-27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Faker\Generator;
1010
use InvalidArgumentException;
1111
use Prokl\BitrixFixtureGeneratorBundle\Services\Contracts\FixtureGeneratorInterface;
12+
use Prokl\BitrixFixtureGeneratorBundle\Services\Generators\Traits\StringUtilsTrait;
1213
use Prokl\BitrixFixtureGeneratorBundle\Services\Utils\FixtureResolver;
1314
use RuntimeException;
1415
use Symfony\Component\DependencyInjection\ServiceLocator;
@@ -23,6 +24,8 @@
2324
*/
2425
class FixtureGenerator
2526
{
27+
use StringUtilsTrait;
28+
2629
/**
2730
* @var Generator $faker Фэйкер.
2831
*/
@@ -216,36 +219,9 @@ private function getFixtureItemFromDescription(array $schema, array $params = []
216219

217220
if ($typeField === 'bigInt') {
218221
$result[$nameField] = $this->faker->numberBetween(1, 12147483647);
219-
continue;
220222
}
221223
}
222224

223225
return $result;
224226
}
225-
226-
/**
227-
* Случайная строка (Фэйкер отказывается генерить строки меньше 5 символов длиной).
228-
*
229-
* @param integer $length Длина нужной строки.
230-
* @param string $src Альтернативный набор символов.
231-
*
232-
* @return string
233-
* @throws Exception
234-
*/
235-
private function generateRandomString(int $length = 25, string $src = '') : string
236-
{
237-
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
238-
if ($src !== '') {
239-
$characters = $src;
240-
}
241-
242-
$charactersLength = strlen($characters);
243-
244-
$randomString = '';
245-
for ($i = 0; $i < $length; $i++) {
246-
$randomString .= $characters[random_int(0, $charactersLength - 1)];
247-
}
248-
249-
return $randomString;
250-
}
251227
}

Services/Generators/ImageGenerator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public function generate(?array $payload = null)
6969
/** @psalm-suppress PossiblyNullArrayAccess */
7070
$this->ignoreErrors = $payload['ignore_errors'];
7171
/** @psalm-suppress PossiblyNullArrayAccess */
72-
$width = array_key_exists('width', $payload['params'])
72+
$width = array_key_exists('width', (array)$payload['params'])
7373
? $payload['params']['width'] : $this->width;
7474

7575
/** @psalm-suppress PossiblyNullArrayAccess */
76-
$height = array_key_exists('height', $payload['params'])
76+
$height = array_key_exists('height', (array)$payload['params'])
7777
? $payload['params']['height'] : $this->height;
7878

7979
/** @noinspection PhpUndefinedMethodInspection */

Services/Generators/Traits/StringUtilsTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait StringUtilsTrait
1919
* @param string $src Альтернативный набор символов.
2020
*
2121
* @return string
22-
* @throws Exception
22+
* @throws Exception Когда не получилось сгенерировать случайное число.
2323
*/
2424
private function generateRandomString(int $length = 25, string $src = '') : string
2525
{

Services/Iblocks/HighloadBlock.php

+35-32
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
class HighloadBlock
2929
{
3030
/**
31+
* Загружен ли модуль highloadblock.
32+
*
3133
* @return boolean
3234
*/
3335
public function isEnabled() : bool
@@ -136,7 +138,7 @@ public function getPropertyData(string $hlblockName, string $property) : array
136138
$arResult = [];
137139

138140
while ($arUserField = $dbUserFields->fetch()) {
139-
if ($arUserField["USER_TYPE_ID"] === 'enumeration') {
141+
if ($arUserField['USER_TYPE_ID'] === 'enumeration') {
140142
$fieldEnum = new \CUserFieldEnum();
141143
$dbEnums = $fieldEnum->GetList(
142144
array(),
@@ -147,7 +149,7 @@ public function getPropertyData(string $hlblockName, string $property) : array
147149
}
148150
}
149151

150-
$arResult['USER_FIELDS'][$arUserField["FIELD_NAME"]] = $arUserField;
152+
$arResult['USER_FIELDS'][$arUserField['FIELD_NAME']] = $arUserField;
151153
}
152154

153155
return $arResult['USER_FIELDS'][$property] ?? [];
@@ -175,7 +177,7 @@ public function getAllProperties(string $hlblockName) : array
175177
$arResult = [];
176178

177179
while ($arUserField = $dbUserFields->fetch()) {
178-
if ($arUserField["USER_TYPE_ID"] === 'enumeration') {
180+
if ($arUserField['USER_TYPE_ID'] === 'enumeration') {
179181
$fieldEnum = new \CUserFieldEnum();
180182
$dbEnums = $fieldEnum->GetList(
181183
array(),
@@ -186,14 +188,14 @@ public function getAllProperties(string $hlblockName) : array
186188
}
187189
}
188190

189-
$arResult[$arUserField["FIELD_NAME"]] = $arUserField;
191+
$arResult[$arUserField['FIELD_NAME']] = $arUserField;
190192
}
191193

192194
return $arResult;
193195
}
194196

195197
/**
196-
* Получает пользовательские поля у объекта
198+
* Получает пользовательские поля у объекта.
197199
*
198200
* @param mixed $entityId
199201
*
@@ -224,7 +226,7 @@ public function getUserTypeEntities($entityId = false)
224226
*
225227
* @param mixed $fieldId
226228
*
227-
* @return array|bool
229+
* @return array|boolean
228230
*/
229231
public function getUserTypeEntityById($fieldId)
230232
{
@@ -241,6 +243,8 @@ public function getUserTypeEntityById($fieldId)
241243
}
242244

243245
/**
246+
* ID сущности.
247+
*
244248
* @param mixed $hlblockName
245249
*
246250
* @return string
@@ -295,31 +299,13 @@ public function getHlblock($hlblockName)
295299
}
296300

297301
/**
298-
* @param array $item
302+
* Права доступа.
299303
*
300-
* @return array
301-
*/
302-
private function prepareHlblock(array $item) : array
303-
{
304-
if (empty($item['ID'])) {
305-
return $item;
306-
}
307-
308-
$langs = $this->getHblockLangs($item['ID']);
309-
if (!empty($langs)) {
310-
$item['LANG'] = $langs;
311-
}
312-
313-
return $item;
314-
}
315-
316-
317-
/**
318-
* @param string $hlblockId
304+
* @param string $hlblockId Символьный код HL блока.
319305
*
320306
* @return array
321307
*/
322-
protected function getGroupRights(string $hlblockId) : array
308+
public function getGroupRights(string $hlblockId) : array
323309
{
324310
$result = [];
325311
if (!class_exists('\Bitrix\Highloadblock\HighloadBlockRightsTable')) {
@@ -334,7 +320,6 @@ protected function getGroupRights(string $hlblockId) : array
334320
],
335321
]
336322
)->fetchAll();
337-
338323
} catch (Exception $e) {
339324
$items = [];
340325
}
@@ -364,7 +349,26 @@ protected function getGroupRights(string $hlblockId) : array
364349
}
365350

366351
/**
367-
* @param string $hlblockId
352+
* @param array $item
353+
*
354+
* @return array
355+
*/
356+
private function prepareHlblock(array $item) : array
357+
{
358+
if (empty($item['ID'])) {
359+
return $item;
360+
}
361+
362+
$langs = $this->getHblockLangs($item['ID']);
363+
if (!empty($langs)) {
364+
$item['LANG'] = $langs;
365+
}
366+
367+
return $item;
368+
}
369+
370+
/**
371+
* @param string $hlblockId Символьный код HL блока.
368372
*
369373
* @return array
370374
*/
@@ -387,7 +391,6 @@ private function getHblockLangs(string $hlblockId) : array
387391
];
388392
}
389393
} catch (Exception $e) {
390-
391394
}
392395

393396
return $result;
@@ -421,7 +424,7 @@ private function checkModules(array $names = []) : bool
421424
private function getEnumValues($fieldId) : array
422425
{
423426
$obEnum = new CUserFieldEnum;
424-
$dbres = $obEnum->GetList([], ["USER_FIELD_ID" => $fieldId]);
427+
$dbres = $obEnum->GetList([], ['USER_FIELD_ID' => $fieldId]);
425428

426429
return $this->fetchAll($dbres);
427430
}
@@ -454,4 +457,4 @@ private function fetchAll(CDBResult $dbres, $indexKey = false, $valueKey = false
454457

455458
return $result;
456459
}
457-
}
460+
}

Services/Iblocks/IblockProperties.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(CIBlockPropertyEnum $cblockPropertyEnums)
3636
* @param integer|array $code Код или фильтр.
3737
*
3838
* @return array
39-
* @throws RuntimeException
39+
* @throws RuntimeException Когда не получились данные о свойстве.
4040
*/
4141
public function getProperty(int $iblockId, $code)
4242
{
@@ -51,7 +51,7 @@ public function getProperty(int $iblockId, $code)
5151
/* do not use =CODE in filter */
5252
$property = CIBlockProperty::GetList(['SORT' => 'ASC'], $filter)->Fetch();
5353
if ($property === false) {
54-
throw new RuntimeException('Ошибка получения данных о свойстые.');
54+
throw new RuntimeException('Ошибка получения данных о свойстве.');
5555
}
5656

5757
return $this->prepareProperty($property);

Services/Iblocks/IblockSections.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public function getSections(int $iblockId, array $filter = []) : array
8383
$dbres = $this->ciblockSection::GetList(
8484
[
8585
'SORT' => 'ASC',
86-
], $filter, false, [
86+
],
87+
$filter,
88+
false,
89+
[
8790
'ID',
8891
'NAME',
8992
'CODE',
@@ -111,7 +114,7 @@ public function getSections(int $iblockId, array $filter = []) : array
111114
* @param integer $sectionId ID подраздела.
112115
* @param array $fields Поля.
113116
*
114-
* @throws RuntimeException
117+
* @throws RuntimeException Ошибки работы с инфоблоками.
115118
* @return integer
116119
*/
117120
public function updateSection(int $sectionId, array $fields) : int
@@ -177,6 +180,8 @@ public function deleteSection(int $sectionId) : bool
177180
}
178181

179182
/**
183+
* Удалить все подразделы.
184+
*
180185
* @param integer $iblockId ID инфоблока.
181186
*/
182187
public function deleteAllSections(int $iblockId) : void
@@ -188,9 +193,11 @@ public function deleteAllSections(int $iblockId) : void
188193
}
189194

190195
/**
196+
* Получить данные.
197+
*
191198
* @param CDBResult $dbres
192-
* @param boolean $indexKey
193-
* @param boolean $valueKey
199+
* @param mixed $indexKey
200+
* @param mixed $valueKey
194201
*
195202
* @return array
196203
*/

Services/Utils/FixtureClassLocator.php

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function __construct(
5353
*
5454
* @return array
5555
* @throws LogicException Фикстура не найдена.
56+
*
57+
* @psalm-suppress InvalidReturnType
5658
*/
5759
public function locate(string $fixtureId) : array
5860
{
@@ -72,6 +74,8 @@ public function locate(string $fixtureId) : array
7274
*
7375
* @return string
7476
* @throws LogicException Фикстура не найдена.
77+
*
78+
* @psalm-suppress InvalidReturnType
7579
*/
7680
public function getFixtureClass(string $fixtureId) : string
7781
{

0 commit comments

Comments
 (0)