|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bart Visscher <[email protected]> |
|
6
|
|
|
* @author Bernhard Posselt <[email protected]> |
|
7
|
|
|
* @author Jakob Sack <[email protected]> |
|
8
|
|
|
* @author Joas Schilling <[email protected]> |
|
9
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
10
|
|
|
* @author Morris Jobke <[email protected]> |
|
11
|
|
|
* @author Thomas Müller <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @license AGPL-3.0 |
|
14
|
|
|
* |
|
15
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
16
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
17
|
|
|
* as published by the Free Software Foundation. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace OC\L10N; |
|
30
|
|
|
|
|
31
|
|
|
class L10NString implements \JsonSerializable { |
|
32
|
|
|
/** @var \OC\L10N\L10N */ |
|
33
|
|
|
protected $l10n; |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
protected $text; |
|
37
|
|
|
|
|
38
|
|
|
/** @var array */ |
|
39
|
|
|
protected $parameters; |
|
40
|
|
|
|
|
41
|
|
|
/** @var integer */ |
|
42
|
|
|
protected $count; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \OC\L10N\L10N $l10n |
|
46
|
|
|
* @param string|string[] $text |
|
47
|
|
|
* @param array $parameters |
|
48
|
|
|
* @param int $count |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) { |
|
51
|
|
|
$this->l10n = $l10n; |
|
52
|
|
|
$this->text = $text; |
|
|
|
|
|
|
53
|
|
|
$this->parameters = $parameters; |
|
54
|
|
|
$this->count = $count; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __toString() { |
|
61
|
|
|
$translations = $this->l10n->getTranslations(); |
|
62
|
|
|
|
|
63
|
|
|
$text = $this->text; |
|
64
|
|
|
if(array_key_exists($this->text, $translations)) { |
|
65
|
|
|
if(is_array($translations[$this->text])) { |
|
66
|
|
|
$fn = $this->l10n->getPluralFormFunction(); |
|
67
|
|
|
$id = $fn($this->count); |
|
68
|
|
|
$text = $translations[$this->text][$id]; |
|
69
|
|
|
} |
|
70
|
|
|
else{ |
|
71
|
|
|
$text = $translations[$this->text]; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// Replace %n first (won't interfere with vsprintf) |
|
76
|
|
|
$text = str_replace('%n', $this->count, $text); |
|
77
|
|
|
return vsprintf($text, $this->parameters); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function jsonSerialize() { |
|
85
|
|
|
return $this->__toString(); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.