Skip to content

Commit

Permalink
Reduce the number of fbt namespaces during collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jun 27, 2023
1 parent fbd7510 commit 68f51e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/fbt/Services/CollectFbtsService.php
Expand Up @@ -11,6 +11,7 @@

use fbt\Transform\NodeVisitor;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Ternary;
Expand Down Expand Up @@ -77,6 +78,13 @@ public function collectFromFiles(string $path, string $src, string $fbtCommonPat
FbtHooks::storePhrases();
}

protected function compileCode(Expr $fbtFunctionClassCall): string
{
$code = $this->printer->prettyPrintExpr($fbtFunctionClassCall);

return preg_replace('/\b(fbt\\\+)fbt/', 'fbt', $code);
}

protected function matchFbtCalls(Node $node): bool
{
return ($node instanceof FuncCall
Expand Down Expand Up @@ -114,7 +122,7 @@ protected function collectFromOneFile(string $source, string $path): bool
echo "\033[15m$path \033[0m" . PHP_EOL;

foreach ($fbtFunctionCalls as $fbtFunctionCall) {
$code = $this->printer->prettyPrintExpr($fbtFunctionCall);
$code = $this->compileCode($fbtFunctionCall);
$line = $fbtFunctionCall->getLine();

try {
Expand Down
4 changes: 2 additions & 2 deletions src/fbt/Services/TranslationsGeneratorService.php
Expand Up @@ -251,8 +251,8 @@ public function generateTranslations(string $source, $translationsPath, $inputPa
{
"fb-locale": "sk_SK",
"translations": []
},
}
}
]
}'
);
}
Expand Down

0 comments on commit 68f51e3

Please sign in to comment.