1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Catalogue; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
15
|
|
|
use Symfony\Component\Translation\Writer\TranslationWriter; |
16
|
|
|
use Symfony\Component\Translation\Writer\TranslationWriterInterface; |
17
|
|
|
use Translation\Bundle\Model\Configuration; |
18
|
|
|
use Translation\SymfonyStorage\LegacyTranslationWriter; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Write catalogues back to disk. |
22
|
|
|
* |
23
|
|
|
* This should be considered as a "WriteToCache" service. |
24
|
|
|
* |
25
|
|
|
* @author Tobias Nyholm <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class CatalogueWriter |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var TranslationWriterInterface |
31
|
|
|
*/ |
32
|
|
|
private $writer; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $defaultLocale; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param TranslationWriter $writer |
41
|
|
|
* @param string $defaultLocale |
42
|
|
|
*/ |
43
|
|
|
public function __construct(TranslationWriter $writer, $defaultLocale) |
44
|
|
|
{ |
45
|
|
|
if (!$writer instanceof TranslationWriterInterface) { |
46
|
|
|
$writer = new LegacyTranslationWriter($writer); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->writer = $writer; |
|
|
|
|
50
|
|
|
$this->defaultLocale = $defaultLocale; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Configuration $config |
55
|
|
|
* @param MessageCatalogue[] $catalogues |
56
|
|
|
*/ |
57
|
|
|
public function writeCatalogues(Configuration $config, array $catalogues) |
58
|
|
|
{ |
59
|
|
|
foreach ($catalogues as $catalogue) { |
60
|
|
|
$this->writer->write( |
61
|
|
|
$catalogue, |
62
|
|
|
$config->getOutputFormat(), |
63
|
|
|
[ |
64
|
|
|
'path' => $config->getOutputDir(), |
65
|
|
|
'default_locale' => $this->defaultLocale, |
66
|
|
|
'xliff_version' => $config->getXliffVersion(), |
67
|
|
|
] |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.