Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ protected function canBeExtracted($file)
}

/**
* @param string|array $directory
*
* @return array
* {@inheritdoc}
*/
protected function extractFromDirectory($directory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Translation\DataCollectorTranslator;
use Symfony\Component\VarDumper\Cloner\Data;

/**
* @author Abdellatif Ait boudad <[email protected]>
Expand Down Expand Up @@ -60,11 +61,11 @@ public function reset()
}

/**
* @return array
* @return Data
*/
public function getMessages()
{
return isset($this->data['messages']) ? $this->data['messages'] : [];
return isset($this->data['messages']) ? $this->data['messages'] : new Data([]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might change an if (message) in the twig template, can you please confirm this doesn't break anything?
otherwise I'm good with array|Data - other collector do it I think

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig
+++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig
@@ -71,7 +71,7 @@
 
     <h2>Messages</h2>
 
-    {% if collector.messages is empty %}
+    {% if not collector.messages|length %}
         <div class="empty">
             <p>No translations have been called.</p>
         </div>

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
abstract class AbstractFileExtractor
{
/**
* @param string|array $resource Files, a file or a directory
* @param string|iterable $resource Files, a file or a directory
*
* @return array
* @return iterable
*/
protected function extractFiles($resource)
{
if (\is_array($resource) || $resource instanceof \Traversable) {
if (\is_iterable($resource)) {
$files = [];
foreach ($resource as $file) {
if ($this->canBeExtracted($file)) {
Expand Down Expand Up @@ -74,7 +74,7 @@ abstract protected function canBeExtracted($file);
/**
* @param string|array $resource Files, a file or a directory
*
* @return array files to be extracted
* @return iterable files to be extracted
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both implementations return a Finder object.

*/
abstract protected function extractFromDirectory($resource);
}
4 changes: 1 addition & 3 deletions src/Symfony/Component/Translation/Extractor/PhpExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ protected function canBeExtracted($file)
}

/**
* @param string|array $directory
*
* @return array
* {@inheritdoc}
*/
protected function extractFromDirectory($directory)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Translation/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ protected function loadResource($resource)
}

try {
$messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT);
$messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT) ?? [];
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
}

if (!\is_array($messages)) {
throw new InvalidResourceException(sprintf('Unable to load file "%s".', $resource));
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony\Component\Translation\Loader\FileLoader::load() performs the same check on the result of loadResource(). We could either duplicate the check here or change the return type to mixed.


return $messages;
}
}