Skip to content

Commit

Permalink
Customize fbt collecting info
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jun 28, 2023
1 parent 68f51e3 commit 185c575
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/fbt/Services/CollectFbtsService.php
Expand Up @@ -40,6 +40,14 @@ class CollectFbtsService
* @var Standard
*/
protected $printer;
/**
* @var int
*/
protected $files = 0;
/**
* @var int
*/
protected $errors = 0;

public function __construct()
{
Expand Down Expand Up @@ -82,7 +90,7 @@ protected function compileCode(Expr $fbtFunctionClassCall): string
{
$code = $this->printer->prettyPrintExpr($fbtFunctionClassCall);

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

protected function matchFbtCalls(Node $node): bool
Expand Down Expand Up @@ -111,6 +119,8 @@ protected function collectFromOneFile(string $source, string $path): bool
return false;
}

$this->files++;

$ast = $this->parser->parse($source);
$ast = $this->traverser->traverse($ast);

Expand Down Expand Up @@ -145,13 +155,32 @@ protected function collectFromOneFile(string $source, string $path): bool
} catch (\Throwable $e) {
$message = $e->getMessage();
$message = preg_replace('/^(.+?) on line .+$/', '$1', $message);
$message = preg_replace('/(called in ).+?\(\d+\)/', '$1' . basename($path) . '(' . $line . ')', $message);

if (! strstr($message, 'called in')) {
$message .= ' called in ' . basename($path) . '(' . $line . ')';
}

echo preg_replace('/(called in ).+?\(\d+\)/', '$1' . $path . '(' . $line . ')', $message);
echo "\033[33m" . $message . "\033[0m" . PHP_EOL;

echo PHP_EOL . PHP_EOL;
$this->errors++;
}
}

return true;
}

public function __destruct()
{
$hashToTexts = array_merge(...array_column(FbtHooks::$sourceStrings['phrases'], 'hashToText'));

echo PHP_EOL;
echo "Fbt collection has been completed!" . PHP_EOL . PHP_EOL;

echo "Source strings: " . count($hashToTexts) . " in " . $this->files . " file(s)" . PHP_EOL;

if ($this->errors) {
echo "\033[33mErrors: " . $this->errors . "\033[0m" . PHP_EOL;
}
}
}

0 comments on commit 185c575

Please sign in to comment.