Skip to content

Commit

Permalink
Improve fbt:param collection
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jan 12, 2024
1 parent bea991d commit 0049836
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/fbt/Runtime/Shared/FbtHooks.php
Expand Up @@ -16,7 +16,9 @@ class FbtHooks
/* @var array */
private static $actions = [];
/* @var array */
public static $sourceStrings = [];
public static $sourceStrings = [
'phrases' => [],
];
/* @var array */
public static $sourceHashes = [];
/* @var array */
Expand Down
6 changes: 3 additions & 3 deletions src/fbt/Services/CollectFbtsService.php
Expand Up @@ -63,7 +63,7 @@ public function __construct()
* @throws \fbt\Exceptions\FbtInvalidConfigurationException
* @throws \fbt\Exceptions\FbtParserException
*/
public function collectFromFiles(string $path, string $src, string $fbtCommonPath, bool $cleanCache)
public function collectFromFiles(string $path, string $src, ?string $fbtCommonPath, bool $cleanCache)
{
$fbtDir = $path . '/';
$file = $fbtDir . '.source_strings.json';
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function compileCode(Expr $fbtFunctionClassCall): string
return preg_replace('/(\\\*|\b)(fbt\\\+)fbt/', 'fbt', $code);
}

protected function matchFbtCalls(Node $node): bool
public static function matchFbtCalls(Node $node): bool
{
return ($node instanceof FuncCall
&& $node->name instanceof Name
Expand Down Expand Up @@ -126,7 +126,7 @@ protected function collectFromOneFile(string $source, string $path): bool

/** @var StaticCall[] $fbtFunctionCalls */
$fbtFunctionCalls = $this->nodeFinder->find($ast, function (Node $node) {
return $this->matchFbtCalls($node);
return self::matchFbtCalls($node);
});

echo "\033[15m$path \033[0m" . PHP_EOL;
Expand Down
4 changes: 3 additions & 1 deletion src/fbt/Transform/NodeVisitor.php
Expand Up @@ -2,6 +2,7 @@

namespace fbt\Transform;

use fbt\Services\CollectFbtsService;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
Expand All @@ -18,7 +19,8 @@ public function enterNode(Node $node)
&& in_array($node->class->toString(), ['fbt', 'fbt\fbt'])) {
switch ($node->name->toString()) {
case "param":
if (! ($node->args[1]->value instanceof String_)) {
if (! CollectFbtsService::matchFbtCalls($node->args[1]->value)
&& ! ($node->args[1]->value instanceof String_)) {
$node->args[1] = new String_('value');
}

Expand Down

0 comments on commit 0049836

Please sign in to comment.