[5.0] [Translator] Add parameter type-hints where possible
This commit is contained in:
parent
c10ad18c5a
commit
470996f708
@ -88,7 +88,7 @@ abstract class AbstractOperation implements OperationInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMessages($domain)
|
||||
public function getMessages(string $domain)
|
||||
{
|
||||
if (!\in_array($domain, $this->getDomains())) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
|
||||
@ -104,7 +104,7 @@ abstract class AbstractOperation implements OperationInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNewMessages($domain)
|
||||
public function getNewMessages(string $domain)
|
||||
{
|
||||
if (!\in_array($domain, $this->getDomains())) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
|
||||
@ -120,7 +120,7 @@ abstract class AbstractOperation implements OperationInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getObsoleteMessages($domain)
|
||||
public function getObsoleteMessages(string $domain)
|
||||
{
|
||||
if (!\in_array($domain, $this->getDomains())) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
|
||||
@ -153,5 +153,5 @@ abstract class AbstractOperation implements OperationInterface
|
||||
*
|
||||
* @param string $domain The domain which the operation will be performed for
|
||||
*/
|
||||
abstract protected function processDomain($domain);
|
||||
abstract protected function processDomain(string $domain);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class MergeOperation extends AbstractOperation
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processDomain($domain)
|
||||
protected function processDomain(string $domain)
|
||||
{
|
||||
$this->messages[$domain] = [
|
||||
'all' => [],
|
||||
|
@ -44,29 +44,23 @@ interface OperationInterface
|
||||
/**
|
||||
* Returns all valid messages ('all') after operation.
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages($domain);
|
||||
public function getMessages(string $domain);
|
||||
|
||||
/**
|
||||
* Returns new messages ('new') after operation.
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNewMessages($domain);
|
||||
public function getNewMessages(string $domain);
|
||||
|
||||
/**
|
||||
* Returns obsolete messages ('obsolete') after operation.
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getObsoleteMessages($domain);
|
||||
public function getObsoleteMessages(string $domain);
|
||||
|
||||
/**
|
||||
* Returns resulting catalogue ('result').
|
||||
|
@ -28,7 +28,7 @@ class TargetOperation extends AbstractOperation
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processDomain($domain)
|
||||
protected function processDomain(string $domain)
|
||||
{
|
||||
$this->messages[$domain] = [
|
||||
'all' => [],
|
||||
|
@ -74,7 +74,7 @@ class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInter
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCatalogue($locale = null)
|
||||
public function getCatalogue(string $locale = null)
|
||||
{
|
||||
return $this->translator->getCatalogue($locale);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class CsvFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$handle = fopen('php://memory', 'r+b');
|
||||
|
||||
@ -43,11 +43,8 @@ class CsvFileDumper extends FileDumper
|
||||
|
||||
/**
|
||||
* Sets the delimiter and escape character for CSV.
|
||||
*
|
||||
* @param string $delimiter Delimiter character
|
||||
* @param string $enclosure Enclosure character
|
||||
*/
|
||||
public function setCsvControl($delimiter = ';', $enclosure = '"')
|
||||
public function setCsvControl(string $delimiter = ';', string $enclosure = '"')
|
||||
{
|
||||
$this->delimiter = $delimiter;
|
||||
$this->enclosure = $enclosure;
|
||||
|
@ -27,5 +27,5 @@ interface DumperInterface
|
||||
* @param MessageCatalogue $messages The message catalogue
|
||||
* @param array $options Options that are used by the dumper
|
||||
*/
|
||||
public function dump(MessageCatalogue $messages, $options = []);
|
||||
public function dump(MessageCatalogue $messages, array $options = []);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ abstract class FileDumper implements DumperInterface
|
||||
*
|
||||
* @param string $relativePathTemplate A template for the relative paths to files
|
||||
*/
|
||||
public function setRelativePathTemplate($relativePathTemplate)
|
||||
public function setRelativePathTemplate(string $relativePathTemplate)
|
||||
{
|
||||
$this->relativePathTemplate = $relativePathTemplate;
|
||||
}
|
||||
@ -45,7 +45,7 @@ abstract class FileDumper implements DumperInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dump(MessageCatalogue $messages, $options = [])
|
||||
public function dump(MessageCatalogue $messages, array $options = [])
|
||||
{
|
||||
if (!\array_key_exists('path', $options)) {
|
||||
throw new InvalidArgumentException('The file dumper needs a path option.');
|
||||
@ -87,13 +87,9 @@ abstract class FileDumper implements DumperInterface
|
||||
/**
|
||||
* Transforms a domain of a message catalogue to its string representation.
|
||||
*
|
||||
* @param MessageCatalogue $messages
|
||||
* @param string $domain
|
||||
* @param array $options
|
||||
*
|
||||
* @return string representation
|
||||
*/
|
||||
abstract public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = []);
|
||||
abstract public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []);
|
||||
|
||||
/**
|
||||
* Gets the file extension of the dumper.
|
||||
|
@ -28,7 +28,7 @@ class IcuResFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$data = $indexes = $resources = '';
|
||||
|
||||
@ -82,7 +82,7 @@ class IcuResFileDumper extends FileDumper
|
||||
return $header.$root.$data;
|
||||
}
|
||||
|
||||
private function writePadding($data)
|
||||
private function writePadding(string $data)
|
||||
{
|
||||
$padding = \strlen($data) % 4;
|
||||
|
||||
@ -91,7 +91,7 @@ class IcuResFileDumper extends FileDumper
|
||||
}
|
||||
}
|
||||
|
||||
private function getPosition($data)
|
||||
private function getPosition(string $data)
|
||||
{
|
||||
return (\strlen($data) + 28) / 4;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class IniFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$output = '';
|
||||
|
||||
|
@ -23,7 +23,7 @@ class JsonFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$flags = $options['json_encoding'] ?? JSON_PRETTY_PRINT;
|
||||
|
||||
|
@ -24,7 +24,7 @@ class MoFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$sources = $targets = $sourceOffsets = $targetOffsets = '';
|
||||
$offsets = [];
|
||||
|
@ -23,7 +23,7 @@ class PhpFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
return "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class PoFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$output = 'msgid ""'."\n";
|
||||
$output .= 'msgstr ""'."\n";
|
||||
|
@ -23,7 +23,7 @@ class QtFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
$dom->formatOutput = true;
|
||||
|
@ -24,7 +24,7 @@ class XliffFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
$xliffVersion = '1.2';
|
||||
if (\array_key_exists('xliff_version', $options)) {
|
||||
|
@ -33,7 +33,7 @@ class YamlFileDumper extends FileDumper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
|
||||
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = [])
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
|
||||
throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
|
||||
|
@ -49,13 +49,11 @@ abstract class AbstractFileExtractor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function isFile($file)
|
||||
protected function isFile(string $file)
|
||||
{
|
||||
if (!is_file($file)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
|
||||
@ -65,11 +63,9 @@ abstract class AbstractFileExtractor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canBeExtracted($file);
|
||||
abstract protected function canBeExtracted(string $file);
|
||||
|
||||
/**
|
||||
* @param string|array $resource Files, a file or a directory
|
||||
|
@ -33,7 +33,7 @@ class ChainExtractor implements ExtractorInterface
|
||||
* @param string $format The format of the loader
|
||||
* @param ExtractorInterface $extractor The loader
|
||||
*/
|
||||
public function addExtractor($format, ExtractorInterface $extractor)
|
||||
public function addExtractor(string $format, ExtractorInterface $extractor)
|
||||
{
|
||||
$this->extractors[$format] = $extractor;
|
||||
}
|
||||
@ -41,7 +41,7 @@ class ChainExtractor implements ExtractorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
public function setPrefix(string $prefix)
|
||||
{
|
||||
foreach ($this->extractors as $extractor) {
|
||||
$extractor->setPrefix($prefix);
|
||||
|
@ -34,5 +34,5 @@ interface ExtractorInterface
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
*/
|
||||
public function setPrefix($prefix);
|
||||
public function setPrefix(string $prefix);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
public function setPrefix(string $prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class PhpStringTokenParser
|
||||
*
|
||||
* @return string The parsed string
|
||||
*/
|
||||
public static function parse($str)
|
||||
public static function parse(string $str)
|
||||
{
|
||||
$bLength = 0;
|
||||
if ('b' === $str[0]) {
|
||||
@ -93,7 +93,7 @@ class PhpStringTokenParser
|
||||
*
|
||||
* @return string String with escape sequences parsed
|
||||
*/
|
||||
public static function parseEscapeSequences($str, $quote)
|
||||
public static function parseEscapeSequences(string $str, string $quote = null)
|
||||
{
|
||||
if (null !== $quote) {
|
||||
$str = str_replace('\\'.$quote, $quote, $str);
|
||||
@ -127,7 +127,7 @@ class PhpStringTokenParser
|
||||
*
|
||||
* @return string Parsed string
|
||||
*/
|
||||
public static function parseDocString($startToken, $str)
|
||||
public static function parseDocString(string $startToken, string $str)
|
||||
{
|
||||
// strip last newline (thanks tokenizer for sticking it into the string!)
|
||||
$str = preg_replace('~(\r\n|\n|\r)$~', '', $str);
|
||||
|
@ -34,7 +34,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format($message, $locale, array $parameters = [])
|
||||
public function format(string $message, string $locale, array $parameters = [])
|
||||
{
|
||||
if ($this->translator instanceof TranslatorInterface) {
|
||||
return $this->translator->trans($message, $parameters, null, $locale);
|
||||
|
@ -26,5 +26,5 @@ interface MessageFormatterInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format($message, $locale, array $parameters = []);
|
||||
public function format(string $message, string $locale, array $parameters = []);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class ArrayLoader implements LoaderInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
$resource = $this->flatten($resource);
|
||||
$catalogue = new MessageCatalogue($locale);
|
||||
|
@ -51,12 +51,8 @@ class CsvFileLoader extends FileLoader
|
||||
|
||||
/**
|
||||
* Sets the delimiter, enclosure, and escape character for CSV.
|
||||
*
|
||||
* @param string $delimiter Delimiter character
|
||||
* @param string $enclosure Enclosure character
|
||||
* @param string $escape Escape character
|
||||
*/
|
||||
public function setCsvControl($delimiter = ';', $enclosure = '"', $escape = '\\')
|
||||
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '\\')
|
||||
{
|
||||
$this->delimiter = $delimiter;
|
||||
$this->enclosure = $enclosure;
|
||||
|
@ -23,7 +23,7 @@ abstract class FileLoader extends ArrayLoader
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
if (!stream_is_local($resource)) {
|
||||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
||||
|
@ -26,7 +26,7 @@ class IcuDatFileLoader extends IcuResFileLoader
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
if (!stream_is_local($resource.'.dat')) {
|
||||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
||||
|
@ -26,7 +26,7 @@ class IcuResFileLoader implements LoaderInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
if (!stream_is_local($resource)) {
|
||||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
||||
@ -75,7 +75,7 @@ class IcuResFileLoader implements LoaderInterface
|
||||
*
|
||||
* @return array the flattened ResourceBundle
|
||||
*/
|
||||
protected function flatten(\ResourceBundle $rb, array &$messages = [], $path = null)
|
||||
protected function flatten(\ResourceBundle $rb, array &$messages = [], string $path = null)
|
||||
{
|
||||
foreach ($rb as $key => $value) {
|
||||
$nodePath = $path ? $path.'.'.$key : $key;
|
||||
|
@ -44,7 +44,7 @@ class JsonFileLoader extends FileLoader
|
||||
*
|
||||
* @return string Message string
|
||||
*/
|
||||
private function getJSONErrorMessage($errorCode)
|
||||
private function getJSONErrorMessage(int $errorCode)
|
||||
{
|
||||
switch ($errorCode) {
|
||||
case JSON_ERROR_DEPTH:
|
||||
|
@ -34,5 +34,5 @@ interface LoaderInterface
|
||||
* @throws NotFoundResourceException when the resource cannot be found
|
||||
* @throws InvalidResourceException when the resource cannot be loaded
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages');
|
||||
public function load($resource, string $locale, string $domain = 'messages');
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class QtFileLoader implements LoaderInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
if (!stream_is_local($resource)) {
|
||||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
||||
|
@ -28,7 +28,7 @@ class XliffFileLoader implements LoaderInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $locale, $domain = 'messages')
|
||||
public function load($resource, string $locale, string $domain = 'messages')
|
||||
{
|
||||
if (!stream_is_local($resource)) {
|
||||
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
|
||||
@ -48,7 +48,7 @@ class XliffFileLoader implements LoaderInterface
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
private function extract($resource, MessageCatalogue $catalogue, $domain)
|
||||
private function extract($resource, MessageCatalogue $catalogue, string $domain)
|
||||
{
|
||||
try {
|
||||
$dom = XmlUtils::loadFile($resource);
|
||||
|
@ -78,7 +78,7 @@ class LoggingTranslator implements TranslatorInterface, TranslatorBagInterface,
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCatalogue($locale = null)
|
||||
public function getCatalogue(string $locale = null)
|
||||
{
|
||||
return $this->translator->getCatalogue($locale);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all($domain = null)
|
||||
public function all(string $domain = null)
|
||||
{
|
||||
if (null !== $domain) {
|
||||
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []);
|
||||
@ -89,7 +89,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($id, $translation, $domain = 'messages')
|
||||
public function set(string $id, string $translation, string $domain = 'messages')
|
||||
{
|
||||
$this->add([$id => $translation], $domain);
|
||||
}
|
||||
@ -97,7 +97,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($id, $domain = 'messages')
|
||||
public function has(string $id, string $domain = 'messages')
|
||||
{
|
||||
if (isset($this->messages[$domain][$id]) || isset($this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id])) {
|
||||
return true;
|
||||
@ -113,7 +113,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defines($id, $domain = 'messages')
|
||||
public function defines(string $id, string $domain = 'messages')
|
||||
{
|
||||
return isset($this->messages[$domain][$id]) || isset($this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id]);
|
||||
}
|
||||
@ -121,7 +121,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id, $domain = 'messages')
|
||||
public function get(string $id, string $domain = 'messages')
|
||||
{
|
||||
if (isset($this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id])) {
|
||||
return $this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id];
|
||||
@ -141,7 +141,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function replace($messages, $domain = 'messages')
|
||||
public function replace(array $messages, string $domain = 'messages')
|
||||
{
|
||||
unset($this->messages[$domain], $this->messages[$domain.self::INTL_DOMAIN_SUFFIX]);
|
||||
|
||||
@ -151,7 +151,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($messages, $domain = 'messages')
|
||||
public function add(array $messages, string $domain = 'messages')
|
||||
{
|
||||
if (!isset($this->messages[$domain])) {
|
||||
$this->messages[$domain] = $messages;
|
||||
@ -246,7 +246,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = '', $domain = 'messages')
|
||||
public function getMetadata(string $key = '', string $domain = 'messages')
|
||||
{
|
||||
if ('' == $domain) {
|
||||
return $this->metadata;
|
||||
@ -266,7 +266,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMetadata($key, $value, $domain = 'messages')
|
||||
public function setMetadata(string $key, $value, string $domain = 'messages')
|
||||
{
|
||||
$this->metadata[$domain][$key] = $value;
|
||||
}
|
||||
@ -274,7 +274,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMetadata($key = '', $domain = 'messages')
|
||||
public function deleteMetadata(string $key = '', string $domain = 'messages')
|
||||
{
|
||||
if ('' == $domain) {
|
||||
$this->metadata = [];
|
||||
|
@ -45,7 +45,7 @@ interface MessageCatalogueInterface
|
||||
*
|
||||
* @return array An array of messages
|
||||
*/
|
||||
public function all($domain = null);
|
||||
public function all(string $domain = null);
|
||||
|
||||
/**
|
||||
* Sets a message translation.
|
||||
@ -54,7 +54,7 @@ interface MessageCatalogueInterface
|
||||
* @param string $translation The messages translation
|
||||
* @param string $domain The domain name
|
||||
*/
|
||||
public function set($id, $translation, $domain = 'messages');
|
||||
public function set(string $id, string $translation, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Checks if a message has a translation.
|
||||
@ -64,7 +64,7 @@ interface MessageCatalogueInterface
|
||||
*
|
||||
* @return bool true if the message has a translation, false otherwise
|
||||
*/
|
||||
public function has($id, $domain = 'messages');
|
||||
public function has(string $id, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Checks if a message has a translation (it does not take into account the fallback mechanism).
|
||||
@ -74,7 +74,7 @@ interface MessageCatalogueInterface
|
||||
*
|
||||
* @return bool true if the message has a translation, false otherwise
|
||||
*/
|
||||
public function defines($id, $domain = 'messages');
|
||||
public function defines(string $id, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Gets a message translation.
|
||||
@ -84,7 +84,7 @@ interface MessageCatalogueInterface
|
||||
*
|
||||
* @return string The message translation
|
||||
*/
|
||||
public function get($id, $domain = 'messages');
|
||||
public function get(string $id, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Sets translations for a given domain.
|
||||
@ -92,7 +92,7 @@ interface MessageCatalogueInterface
|
||||
* @param array $messages An array of translations
|
||||
* @param string $domain The domain name
|
||||
*/
|
||||
public function replace($messages, $domain = 'messages');
|
||||
public function replace(array $messages, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Adds translations for a given domain.
|
||||
@ -100,7 +100,7 @@ interface MessageCatalogueInterface
|
||||
* @param array $messages An array of translations
|
||||
* @param string $domain The domain name
|
||||
*/
|
||||
public function add($messages, $domain = 'messages');
|
||||
public function add(array $messages, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Merges translations from the given Catalogue into the current one.
|
||||
|
@ -30,7 +30,7 @@ interface MetadataAwareInterface
|
||||
*
|
||||
* @return mixed The value that was set or an array with the domains/keys or null
|
||||
*/
|
||||
public function getMetadata($key = '', $domain = 'messages');
|
||||
public function getMetadata(string $key = '', string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Adds metadata to a message domain.
|
||||
@ -39,7 +39,7 @@ interface MetadataAwareInterface
|
||||
* @param mixed $value The value
|
||||
* @param string $domain The domain name
|
||||
*/
|
||||
public function setMetadata($key, $value, $domain = 'messages');
|
||||
public function setMetadata(string $key, $value, string $domain = 'messages');
|
||||
|
||||
/**
|
||||
* Deletes metadata for the given key and domain.
|
||||
@ -50,5 +50,5 @@ interface MetadataAwareInterface
|
||||
* @param string $key The key
|
||||
* @param string $domain The domain name
|
||||
*/
|
||||
public function deleteMetadata($key = '', $domain = 'messages');
|
||||
public function deleteMetadata(string $key = '', string $domain = 'messages');
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class TranslationReader implements TranslationReaderInterface
|
||||
* @param string $format The format of the loader
|
||||
* @param LoaderInterface $loader
|
||||
*/
|
||||
public function addLoader($format, LoaderInterface $loader)
|
||||
public function addLoader(string $format, LoaderInterface $loader)
|
||||
{
|
||||
$this->loaders[$format] = $loader;
|
||||
}
|
||||
@ -43,7 +43,7 @@ class TranslationReader implements TranslationReaderInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($directory, MessageCatalogue $catalogue)
|
||||
public function read(string $directory, MessageCatalogue $catalogue)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
return;
|
||||
|
@ -22,9 +22,6 @@ interface TranslationReaderInterface
|
||||
{
|
||||
/**
|
||||
* Reads translation messages from a directory to the catalogue.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param MessageCatalogue $catalogue
|
||||
*/
|
||||
public function read($directory, MessageCatalogue $catalogue);
|
||||
public function read(string $directory, MessageCatalogue $catalogue);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
* @param string $format The name of the loader (@see addResource())
|
||||
* @param LoaderInterface $loader A LoaderInterface instance
|
||||
*/
|
||||
public function addLoader($format, LoaderInterface $loader)
|
||||
public function addLoader(string $format, LoaderInterface $loader)
|
||||
{
|
||||
$this->loaders[$format] = $loader;
|
||||
}
|
||||
@ -124,7 +124,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
*
|
||||
* @throws InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function addResource($format, $resource, $locale, $domain = null)
|
||||
public function addResource(string $format, $resource, string $locale, string $domain = null)
|
||||
{
|
||||
if (null === $domain) {
|
||||
$domain = 'messages';
|
||||
@ -220,7 +220,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCatalogue($locale = null)
|
||||
public function getCatalogue(string $locale = null)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$locale = $this->getLocale();
|
||||
@ -248,7 +248,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
/**
|
||||
* @param string $locale
|
||||
*/
|
||||
protected function loadCatalogue($locale)
|
||||
protected function loadCatalogue(string $locale)
|
||||
{
|
||||
if (null === $this->cacheDir) {
|
||||
$this->initializeCatalogue($locale);
|
||||
@ -260,7 +260,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
/**
|
||||
* @param string $locale
|
||||
*/
|
||||
protected function initializeCatalogue($locale)
|
||||
protected function initializeCatalogue(string $locale)
|
||||
{
|
||||
$this->assertValidLocale($locale);
|
||||
|
||||
|
@ -29,5 +29,5 @@ interface TranslatorBagInterface
|
||||
*
|
||||
* @throws InvalidArgumentException If the locale contains invalid characters
|
||||
*/
|
||||
public function getCatalogue($locale = null);
|
||||
public function getCatalogue(string $locale = null);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class ArrayConverter
|
||||
return $elem;
|
||||
}
|
||||
|
||||
private static function cancelExpand(array &$tree, $prefix, array $node)
|
||||
private static function cancelExpand(array &$tree, string $prefix, array $node)
|
||||
{
|
||||
$prefix .= '.';
|
||||
|
||||
|
@ -55,7 +55,7 @@ class TranslationWriter implements TranslationWriterInterface
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function write(MessageCatalogue $catalogue, $format, $options = [])
|
||||
public function write(MessageCatalogue $catalogue, string $format, array $options = [])
|
||||
{
|
||||
if (!isset($this->dumpers[$format])) {
|
||||
throw new InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
|
||||
|
@ -30,5 +30,5 @@ interface TranslationWriterInterface
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function write(MessageCatalogue $catalogue, $format, $options = []);
|
||||
public function write(MessageCatalogue $catalogue, string $format, array $options = []);
|
||||
}
|
||||
|
Reference in New Issue
Block a user