Skip to content

Commit

Permalink
Правки кода
Browse files Browse the repository at this point in the history
  • Loading branch information
Elnadrion committed May 8, 2024
1 parent 007610a commit 9a18a73
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
7 changes: 6 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
LevelSetList::UP_TO_PHP_82,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::TYPE_DECLARATION,
]);

$rectorConfig->skip([
\Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class,
]);

$rectorConfig->parallel();
};
16 changes: 6 additions & 10 deletions src/Elnadrion/Tools/Twig/BitrixLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public function normalizeName(string $name): string
$name = preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name));
}

$isComponentPath = str_contains((string) $name, ':');
$isGlobalPath = str_starts_with((string) $name, '/');
$isComponentPath = str_contains((string)$name, ':');
$isGlobalPath = str_starts_with((string)$name, '/');

if (($isComponentPath || $isGlobalPath) && isset(static::$normalized[ $name ])) {
return static::$normalized[ $name ];
Expand All @@ -174,11 +174,11 @@ public function normalizeName(string $name): string
if ($isComponentPath) {
[$siteTemplate, $namespace, $component, $template, $file] = explode(':', (string) $name);

if (strlen($template) === 0) {
if (empty($template)) {
$template = '.default';
}

if (strlen($file) === 0) {
if (empty($file)) {
$file = 'template';
}

Expand All @@ -187,13 +187,9 @@ public function normalizeName(string $name): string
$normalizedName = $name;
} else {
$lastRendered = $this->getLastRenderedTemplate();
if ($lastRendered) {
$normalizedName = dirname($lastRendered) . '/' . $name;
} else {
$normalizedName = $name;
}
$normalizedName = $lastRendered ? dirname($lastRendered) . '/' . $name : $name;
}

return static::$normalized[ $name ] = $normalizedName;
return static::$normalized[$name] = $normalizedName;
}
}
2 changes: 1 addition & 1 deletion src/Elnadrion/Tools/Twig/TemplateEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static function render(
'component' => $component,
'templateFolder' => $templateFolder,
'parentTemplateFolder' => $parentTemplateFolder,
'render' => compact('templateName', 'engine'),
'render' => ['templateName' => $templateName, 'engine' => $engine],
] + $context;

echo self::getInstance()->getEngine()->render($templateName, $context);
Expand Down
4 changes: 2 additions & 2 deletions src/Elnadrion/Tools/Twig/TwigCacheCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ private function checkCacheEngine(): void
*/
public function clearByName(string $name): int
{
if (strlen($name) === 0) {
if (empty($name)) {
throw new ArgumentException('Имя шаблона не задано');
}

$counter = 0;

$templateClass = $this->engine->getTemplateClass($name);
if (strlen($name) === 0) {
if (empty($name)) {
throw new ArgumentException("Шаблон с именем '{$name}' не найден");
}

Expand Down
4 changes: 2 additions & 2 deletions src/Elnadrion/Tools/Twig/TwigOptionsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDefaultOptions(): array
'debug' => false,
'charset' => 'UTF-8',
'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/elnadrion/tools.twig',
'auto_reload' => isset($_GET['clear_cache']) && strtoupper((string)$_GET['clear_cache']) == 'Y',
'auto_reload' => isset($_GET['clear_cache']) && strtoupper((string)$_GET['clear_cache']) === 'Y',
'autoescape' => false,
'extract_result' => false,
'use_by_default' => false,
Expand Down Expand Up @@ -85,7 +85,7 @@ public function getUsedByDefault(): bool

public function setExtractResult($value): TwigOptionsStorage
{
$this->options['extract_result'] = !!$value;
$this->options['extract_result'] = (bool)$value;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testRenderComponent($component, $template, $additionalContext =
{
global $APPLICATION;
ob_start();
$APPLICATION->IncludeComponent($component, $template, compact('additionalContext'));
$APPLICATION->IncludeComponent($component, $template, ['additionalContext' => $additionalContext]);
$output = ob_get_clean();

$this->assertSame(self::EXPECTED, $output);
Expand Down

0 comments on commit 9a18a73

Please sign in to comment.