Skip to content

Commit

Permalink
Light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jun 11, 2021
1 parent 8d20552 commit 7b8fc09
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 17 deletions.
42 changes: 25 additions & 17 deletions Services/IblockTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ public function __construct(int $iblockId = 0)
$this->iblockId = $iblockId;
}

/**
* @param integer $iblockId
*
* @return $this
*/
public function setIblockId(int $iblockId): self
{
$this->iblockId = $iblockId;

return $this;
}

/**
* Собрать дерево, включающее элементы.
*
Expand All @@ -62,15 +50,27 @@ public function get(): array
}
}

/**
* @param integer $iblockId
*
* @return $this
*/
public function setIblockId(int $iblockId): self
{
$this->iblockId = $iblockId;

return $this;
}

/**
* Получить данные об элементах меню.
*
* @param integer $iblockId ID инфоблока.
* @param integer $sectionId ID секции инфоблока.
* @param integer $iblockId ID инфоблока.
* @param integer|boolean $sectionId ID секции инфоблока.
*
* @return array
*/
private function getItems(int $iblockId, int $sectionId): array
private function getItems(int $iblockId, $sectionId): array
{
$arItems = [];

Expand All @@ -79,15 +79,17 @@ private function getItems(int $iblockId, int $sectionId): array
['IBLOCK_ID' => $iblockId, 'IBLOCK_SECTION_ID' => $sectionId, 'ACTIVE' => 'Y'],
false,
false,
['NAME', 'IBLOCK_SECTION_ID', 'PROPERTY_WEIGHT', 'PREVIEW_TEXT']
[]
);

while ($ob = $res->GetNextElement()) {
$arFields = $ob->GetFields();
$props = $ob->GetProperties();

$arItems[] = [
'NAME' => $arFields['NAME'],
'PREVIEW_TEXT' => $arFields['PREVIEW_TEXT'],
'PROPERTIES' => $props,
'FIELDS' => $arFields,
];
}

Expand Down Expand Up @@ -126,6 +128,8 @@ private function makeTree(int $iblockId) : void

while ($arSection = $section->GetNext(true, false)) {
$arPush = $arSection;
// Костылинг - уравнять элементы и разделы по параметрам.
$arPush['DETAIL_PAGE_URL'] = $arPush['SECTION_PAGE_URL'];

// Подмес элементов (если они существуют)
$arItems = $this->getItems($iblockId, $arSection['ID']);
Expand Down Expand Up @@ -163,6 +167,10 @@ function ($a, $b) {
}
);

// Элементы без подразделов.
$rootElements = $this->getItems($iblockId, false);
$arSectionList = array_merge($arSectionList, $rootElements);

$this->arTree = $arSectionList; // Результат.
}
}
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@
"symfony/config": "~4|~5",
"proklung/cache-proxificator": "^1.1",
"webarchitect609/bitrix-cache": "^1.6"
},
"require-dev": {
"proklung/bitrix-phpunit-testing-tools": "^1.0"
},
"extra": {
"installer-paths": {
"vendor/sheerockoff/bitrix-ci/files/bitrix/modules/{$name}/": ["type:bitrix-module"]
}
}
}
101 changes: 101 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
allowStringToStandInForClass="true"
allowCoercionFromStringToClassConst="true"
findUnusedPsalmSuppress="true"
skipChecksOnUnresolvableIncludes="true"
>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
</plugins>
<projectFiles>
<directory name="/"/>
<ignoreFiles>
<directory name="vendor"/>
<directory name="bitrix/modules/sprint.migration"/>
</ignoreFiles>
</projectFiles>

<extraFiles>
<directory name="vendor/sheerockoff/bitrix-ci/files/bitrix"/>
</extraFiles>

<issueHandlers>
<DeprecatedMethod>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedClass>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</DeprecatedClass>
<UndefinedGlobalVariable>
<errorLevel type="suppress">
<referencedVariable name="$APPLICATION" />
<referencedVariable name="$USER" />
</errorLevel>
</UndefinedGlobalVariable>

<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</PropertyNotSetInConstructor>

<UndefinedConstant>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</UndefinedConstant>

<InvalidArgument>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</InvalidArgument>

<TooFewArguments>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</TooFewArguments>

<ArgumentTypeCoercion>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</ArgumentTypeCoercion>

<LessSpecificReturnStatement>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</LessSpecificReturnStatement>

<UndefinedFunction>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</UndefinedFunction>

<UndefinedMagicPropertyFetch>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</UndefinedMagicPropertyFetch>

<UnresolvableInclude>
<errorLevel type="suppress">
<directory name="/"/>
</errorLevel>
</UnresolvableInclude>
</issueHandlers>
</psalm>
35 changes: 35 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruleset name="RegioStandard">
<description>RegioMedia PHP Coding Standard</description>

<!-- Основа: https://www.php-fig.org/psr/psr-2/ -->
<rule ref="PSR2" />

<!-- Включают обязательность док-блоков для классов и функций -->
<rule ref="Squiz.Commenting.FunctionComment" />
<rule ref="Squiz.Commenting.FunctionCommentThrowTag" />
<rule ref="Squiz.Commenting.ClassComment">
<exclude name="Squiz.Commenting.ClassComment.TagNotAllowed"/>.
</rule>
<rule ref="Squiz.Commenting.VariableComment" />

<!-- увеличивает лимит на длину строки по сравнению с PSR-2 -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="140"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>

<!-- предупреждает об использовании нежелательных функций (устаревшие и отладочные) -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="error" value="false" />
<property name="forbiddenFunctions" type="array"
value="sizeof=>count,delete=>unset,d=>null,var_dump=>null" />
</properties>
</rule>

<!-- запрещает использование двойных кавычек там, где они не нужны -->
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired" />
</ruleset>

0 comments on commit 7b8fc09

Please sign in to comment.