Skip to content

Commit

Permalink
Enable "native_constant_invocation" CS rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 2, 2020
1 parent 0411f10 commit c826cb2
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Command/XliffLintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private function displayJson(SymfonyStyle $io, array $filesInfo)
}
});

$io->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$io->writeln(json_encode($filesInfo, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));

return min($errors, 1);
}
Expand All @@ -207,13 +207,13 @@ private function getFiles($fileOrDirectory)
*/
private function getStdin()
{
if (0 !== ftell(STDIN)) {
if (0 !== ftell(\STDIN)) {
return null;
}

$inputs = '';
while (!feof(STDIN)) {
$inputs .= fread(STDIN, 1024);
while (!feof(\STDIN)) {
$inputs .= fread(\STDIN, 1024);
}

return $inputs;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/TranslatorPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TranslatorPass implements CompilerPassInterface
public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.loader', $loaderTag = 'translation.loader', $debugCommandServiceId = 'console.command.translation_debug', $updateCommandServiceId = 'console.command.translation_update')
{
if ('translation.loader' === $readerServiceId && 2 > \func_num_args()) {
@trigger_error(sprintf('The default value for $readerServiceId in "%s()" will change in 4.0 to "translation.reader".', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('The default value for $readerServiceId in "%s()" will change in 4.0 to "translation.reader".', __METHOD__), \E_USER_DEPRECATED);
}

$this->translatorServiceId = $translatorServiceId;
Expand Down
2 changes: 1 addition & 1 deletion Dumper/FileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function dump(MessageCatalogue $messages, $options = [])
$fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale());
if (file_exists($fullpath)) {
if ($this->backup) {
@trigger_error('Creating a backup while dumping a message catalogue is deprecated since Symfony 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', E_USER_DEPRECATED);
@trigger_error('Creating a backup while dumping a message catalogue is deprecated since Symfony 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', \E_USER_DEPRECATED);
copy($fullpath, $fullpath.'~');
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion Dumper/JsonFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti
if (isset($options['json_encoding'])) {
$flags = $options['json_encoding'];
} else {
$flags = JSON_PRETTY_PRINT;
$flags = \JSON_PRETTY_PRINT;
}

return json_encode($messages->all($domain), $flags);
Expand Down
14 changes: 7 additions & 7 deletions Extractor/PhpExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function seekToNextRelevantToken(\Iterator $tokenIterator)
{
for (; $tokenIterator->valid(); $tokenIterator->next()) {
$t = $tokenIterator->current();
if (T_WHITESPACE !== $t[0]) {
if (\T_WHITESPACE !== $t[0]) {
break;
}
}
Expand Down Expand Up @@ -169,23 +169,23 @@ private function getValue(\Iterator $tokenIterator)
}

switch ($t[0]) {
case T_START_HEREDOC:
case \T_START_HEREDOC:
$docToken = $t[1];
break;
case T_ENCAPSED_AND_WHITESPACE:
case T_CONSTANT_ENCAPSED_STRING:
case \T_ENCAPSED_AND_WHITESPACE:
case \T_CONSTANT_ENCAPSED_STRING:
if ('' === $docToken) {
$message .= PhpStringTokenParser::parse($t[1]);
} else {
$docPart = $t[1];
}
break;
case T_END_HEREDOC:
case \T_END_HEREDOC:
$message .= PhpStringTokenParser::parseDocString($docToken, $docPart);
$docToken = '';
$docPart = '';
break;
case T_WHITESPACE:
case \T_WHITESPACE:
break;
default:
break 2;
Expand Down Expand Up @@ -253,7 +253,7 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
*/
protected function canBeExtracted($file)
{
return $this->isFile($file) && 'php' === pathinfo($file, PATHINFO_EXTENSION);
return $this->isFile($file) && 'php' === pathinfo($file, \PATHINFO_EXTENSION);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions Loader/JsonFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ protected function loadResource($resource)
private function getJSONErrorMessage($errorCode)
{
switch ($errorCode) {
case JSON_ERROR_DEPTH:
case \JSON_ERROR_DEPTH:
return 'Maximum stack depth exceeded';
case JSON_ERROR_STATE_MISMATCH:
case \JSON_ERROR_STATE_MISMATCH:
return 'Underflow or the modes mismatch';
case JSON_ERROR_CTRL_CHAR:
case \JSON_ERROR_CTRL_CHAR:
return 'Unexpected control character found';
case JSON_ERROR_SYNTAX:
case \JSON_ERROR_SYNTAX:
return 'Syntax error, malformed JSON';
case JSON_ERROR_UTF8:
case \JSON_ERROR_UTF8:
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
default:
return 'Unknown error';
Expand Down
2 changes: 1 addition & 1 deletion Loader/PhpFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PhpFileLoader extends FileLoader
*/
protected function loadResource($resource)
{
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOLEAN))) {
self::$cache = null;
}

Expand Down
4 changes: 2 additions & 2 deletions Loader/XliffFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function validateSchema($file, \DOMDocument $dom, $schema)
{
$internalErrors = libxml_use_internal_errors(true);

if (LIBXML_VERSION < 20900) {
if (\LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(false);
$isValid = @$dom->schemaValidateSource($schema);
libxml_disable_entity_loader($disableEntities);
Expand Down Expand Up @@ -264,7 +264,7 @@ private function getXmlErrors($internalErrors)
$errors = [];
foreach (libxml_get_errors() as $error) {
$errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)',
LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
\LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
$error->code,
trim($error->message),
$error->file ?: 'n/a',
Expand Down
2 changes: 1 addition & 1 deletion Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function loadResource($resource)
}

$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($resource, &$prevErrorHandler) {
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$resource.'"$0', $message) : $message;
$message = \E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$resource.'"$0', $message) : $message;

return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
});
Expand Down
20 changes: 10 additions & 10 deletions Resources/bin/translation-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

foreach ($config['original_files'] as $originalFilePath) {
if (!file_exists($originalFilePath)) {
echo sprintf('The following file does not exist. Make sure that you execute this command at the root dir of the Symfony code repository.%s %s', PHP_EOL, $originalFilePath);
echo sprintf('The following file does not exist. Make sure that you execute this command at the root dir of the Symfony code repository.%s %s', \PHP_EOL, $originalFilePath);
exit(1);
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ function findTranslationFiles($originalFilePath, $localeToAnalyze)
$originalFileName = basename($originalFilePath);
$translationFileNamePattern = str_replace('.en.', '.*.', $originalFileName);

$translationFiles = glob($translationsDir.'/'.$translationFileNamePattern, GLOB_NOSORT);
$translationFiles = glob($translationsDir.'/'.$translationFileNamePattern, \GLOB_NOSORT);
sort($translationFiles);
foreach ($translationFiles as $filePath) {
$locale = extractLocaleFromFilePath($filePath);
Expand Down Expand Up @@ -127,7 +127,7 @@ function printTranslationStatus($originalFilePath, $translationStatus, $verboseO
{
printTitle($originalFilePath);
printTable($translationStatus, $verboseOutput);
echo PHP_EOL.PHP_EOL;
echo \PHP_EOL.\PHP_EOL;
}

function extractLocaleFromFilePath($filePath)
Expand All @@ -154,8 +154,8 @@ function extractTranslationKeys($filePath)

function printTitle($title)
{
echo $title.PHP_EOL;
echo str_repeat('=', strlen($title)).PHP_EOL.PHP_EOL;
echo $title.\PHP_EOL;
echo str_repeat('=', strlen($title)).\PHP_EOL.\PHP_EOL;
}

function printTable($translations, $verboseOutput)
Expand All @@ -174,19 +174,19 @@ function printTable($translations, $verboseOutput)
textColorGreen();
}

echo sprintf('| Locale: %-'.$longestLocaleNameLength.'s | Translated: %d/%d', $locale, $translation['translated'], $translation['total']).PHP_EOL;
echo sprintf('| Locale: %-'.$longestLocaleNameLength.'s | Translated: %d/%d', $locale, $translation['translated'], $translation['total']).\PHP_EOL;

textColorNormal();

if (true === $verboseOutput && count($translation['missingKeys']) > 0) {
echo str_repeat('-', 80).PHP_EOL;
echo '| Missing Translations:'.PHP_EOL;
echo str_repeat('-', 80).\PHP_EOL;
echo '| Missing Translations:'.\PHP_EOL;

foreach ($translation['missingKeys'] as $id => $content) {
echo sprintf('| (id=%s) %s', $id, $content).PHP_EOL;
echo sprintf('| (id=%s) %s', $id, $content).\PHP_EOL;
}

echo str_repeat('-', 80).PHP_EOL;
echo str_repeat('-', 80).\PHP_EOL;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Dumper/JsonFileDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function testDumpWithCustomEncoding()

$dumper = new JsonFileDumper();

$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', ['json_encoding' => JSON_HEX_QUOT]));
$this->assertStringEqualsFile(__DIR__.'/../fixtures/resources.dump.json', $dumper->formatCatalogue($catalogue, 'messages', ['json_encoding' => \JSON_HEX_QUOT]));
}
}
4 changes: 2 additions & 2 deletions Tests/Loader/XliffFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function testLoadWithInternalErrorsEnabled()

public function testLoadWithExternalEntitiesDisabled()
{
if (LIBXML_VERSION < 20900) {
if (\LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}

$loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/resources.xlf';
$catalogue = $loader->load($resource, 'en', 'domain1');

if (LIBXML_VERSION < 20900) {
if (\LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}

Expand Down
2 changes: 1 addition & 1 deletion Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct($locale, $formatter = null, $cacheDir = null, $debug

if ($formatter instanceof MessageSelector) {
$formatter = new MessageFormatter($formatter);
@trigger_error(sprintf('Passing a "%s" instance into the "%s()" method as a second argument is deprecated since Symfony 3.4 and will be removed in 4.0. Inject a "%s" implementation instead.', MessageSelector::class, __METHOD__, MessageFormatterInterface::class), E_USER_DEPRECATED);
@trigger_error(sprintf('Passing a "%s" instance into the "%s()" method as a second argument is deprecated since Symfony 3.4 and will be removed in 4.0. Inject a "%s" implementation instead.', MessageSelector::class, __METHOD__, MessageFormatterInterface::class), \E_USER_DEPRECATED);
} elseif (null === $formatter) {
$formatter = new MessageFormatter();
}
Expand Down
2 changes: 1 addition & 1 deletion Writer/TranslationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function write(MessageCatalogue $catalogue, $format, $options = [])
*/
public function writeTranslations(MessageCatalogue $catalogue, $format, $options = [])
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0. Use write() instead.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0. Use write() instead.', __METHOD__), \E_USER_DEPRECATED);
$this->write($catalogue, $format, $options);
}
}

0 comments on commit c826cb2

Please sign in to comment.