Skip to content

Commit 96e6ad9

Browse files
committed
minor #32786 add parameter type declarations to private methods (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- add parameter type declarations to private methods | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 1b2aaa4a06 add parameter type declarations to private methods
2 parents e40aa57 + 8113265 commit 96e6ad9

File tree

5 files changed

+29
-65
lines changed

5 files changed

+29
-65
lines changed

Data/Bundle/Writer/TextBundleWriter.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ public function write($path, $locale, $data, $fallback = true)
4343
/**
4444
* Writes a "resourceBundle" node.
4545
*
46-
* @param resource $file The file handle to write to
47-
* @param string $bundleName The name of the bundle
48-
* @param mixed $value The value of the node
49-
* @param bool $fallback Whether the resource bundle should be merged
50-
* with the fallback locale
46+
* @param resource $file The file handle to write to
47+
* @param mixed $value The value of the node
5148
*
5249
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
5350
*/
54-
private function writeResourceBundle($file, $bundleName, $value, $fallback)
51+
private function writeResourceBundle($file, string $bundleName, $value, bool $fallback)
5552
{
5653
fwrite($file, $bundleName);
5754

@@ -63,14 +60,12 @@ private function writeResourceBundle($file, $bundleName, $value, $fallback)
6360
/**
6461
* Writes a "resource" node.
6562
*
66-
* @param resource $file The file handle to write to
67-
* @param mixed $value The value of the node
68-
* @param int $indentation The number of levels to indent
69-
* @param bool $requireBraces Whether to require braces to be printedaround the value
63+
* @param resource $file The file handle to write to
64+
* @param mixed $value The value of the node
7065
*
7166
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
7267
*/
73-
private function writeResource($file, $value, $indentation, $requireBraces = true)
68+
private function writeResource($file, $value, int $indentation, bool $requireBraces = true)
7469
{
7570
if (\is_int($value)) {
7671
$this->writeInteger($file, $value);
@@ -117,26 +112,23 @@ private function writeResource($file, $value, $indentation, $requireBraces = tru
117112
/**
118113
* Writes an "integer" node.
119114
*
120-
* @param resource $file The file handle to write to
121-
* @param int $value The value of the node
115+
* @param resource $file The file handle to write to
122116
*
123117
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
124118
*/
125-
private function writeInteger($file, $value)
119+
private function writeInteger($file, int $value)
126120
{
127121
fprintf($file, ':int{%d}', $value);
128122
}
129123

130124
/**
131125
* Writes an "intvector" node.
132126
*
133-
* @param resource $file The file handle to write to
134-
* @param array $value The value of the node
135-
* @param int $indentation The number of levels to indent
127+
* @param resource $file The file handle to write to
136128
*
137129
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
138130
*/
139-
private function writeIntVector($file, array $value, $indentation)
131+
private function writeIntVector($file, array $value, int $indentation)
140132
{
141133
fwrite($file, ":intvector{\n");
142134

@@ -150,14 +142,11 @@ private function writeIntVector($file, array $value, $indentation)
150142
/**
151143
* Writes a "string" node.
152144
*
153-
* @param resource $file The file handle to write to
154-
* @param string $value The value of the node
155-
* @param bool $requireBraces Whether to require braces to be printed
156-
* around the value
145+
* @param resource $file The file handle to write to
157146
*
158147
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
159148
*/
160-
private function writeString($file, $value, $requireBraces = true)
149+
private function writeString($file, string $value, bool $requireBraces = true)
161150
{
162151
if ($requireBraces) {
163152
fprintf($file, '{"%s"}', $value);
@@ -171,13 +160,11 @@ private function writeString($file, $value, $requireBraces = true)
171160
/**
172161
* Writes an "array" node.
173162
*
174-
* @param resource $file The file handle to write to
175-
* @param array $value The value of the node
176-
* @param int $indentation The number of levels to indent
163+
* @param resource $file The file handle to write to
177164
*
178165
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
179166
*/
180-
private function writeArray($file, array $value, $indentation)
167+
private function writeArray($file, array $value, int $indentation)
181168
{
182169
fwrite($file, "{\n");
183170

@@ -195,16 +182,12 @@ private function writeArray($file, array $value, $indentation)
195182
/**
196183
* Writes a "table" node.
197184
*
198-
* @param resource $file The file handle to write to
199-
* @param iterable $value The value of the node
200-
* @param int $indentation The number of levels to indent
201-
* @param bool $fallback Whether the table should be merged
202-
* with the fallback locale
185+
* @param resource $file The file handle to write to
203186
*
204187
* @throws UnexpectedTypeException when $value is not an array and not a
205188
* \Traversable instance
206189
*/
207-
private function writeTable($file, $value, $indentation, $fallback = true)
190+
private function writeTable($file, iterable $value, int $indentation, bool $fallback = true)
208191
{
209192
if (!\is_array($value) && !$value instanceof \Traversable) {
210193
throw new UnexpectedTypeException($value, 'array or \Traversable');

Data/Generator/LocaleDataGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, $temp
151151
/**
152152
* @return string
153153
*/
154-
private function generateLocaleName(BundleEntryReaderInterface $reader, $tempDir, $locale, $displayLocale, $pattern, $separator)
154+
private function generateLocaleName(BundleEntryReaderInterface $reader, string $tempDir, string $locale, string $displayLocale, string $pattern, string $separator)
155155
{
156156
// Apply generic notation using square brackets as described per http://cldr.unicode.org/translation/language-names
157157
$name = str_replace(['(', ')'], ['[', ']'], $reader->readEntry($tempDir.'/lang', $displayLocale, ['Languages', \Locale::getPrimaryLanguage($locale)]));

NumberFormatter/NumberFormatter.php

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,12 @@ protected function resetError()
672672
*
673673
* The only actual rounding data as of this writing, is CHF.
674674
*
675-
* @param float $value The numeric currency value
676-
* @param string $currency The 3-letter ISO 4217 currency code indicating the currency to use
677-
*
678675
* @return float The rounded numeric currency value
679676
*
680677
* @see http://en.wikipedia.org/wiki/Swedish_rounding
681678
* @see http://www.docjar.com/html/api/com/ibm/icu/util/Currency.java.html#1007
682679
*/
683-
private function roundCurrency($value, $currency)
680+
private function roundCurrency(float $value, string $currency)
684681
{
685682
$fractionDigits = Currencies::getFractionDigits($currency);
686683
$roundingIncrement = Currencies::getRoundingIncrement($currency);
@@ -700,12 +697,11 @@ private function roundCurrency($value, $currency)
700697
/**
701698
* Rounds a value.
702699
*
703-
* @param int|float $value The value to round
704-
* @param int $precision The number of decimal digits to round to
700+
* @param int|float $value The value to round
705701
*
706702
* @return int|float The rounded value
707703
*/
708-
private function round($value, $precision)
704+
private function round($value, int $precision)
709705
{
710706
$precision = $this->getUninitializedPrecision($value, $precision);
711707

@@ -741,12 +737,11 @@ private function round($value, $precision)
741737
/**
742738
* Formats a number.
743739
*
744-
* @param int|float $value The numeric value to format
745-
* @param int $precision The number of decimal digits to use
740+
* @param int|float $value The numeric value to format
746741
*
747742
* @return string The formatted number
748743
*/
749-
private function formatNumber($value, $precision)
744+
private function formatNumber($value, int $precision)
750745
{
751746
$precision = $this->getUninitializedPrecision($value, $precision);
752747

@@ -756,12 +751,11 @@ private function formatNumber($value, $precision)
756751
/**
757752
* Returns the precision value if the DECIMAL style is being used and the FRACTION_DIGITS attribute is uninitialized.
758753
*
759-
* @param int|float $value The value to get the precision from if the FRACTION_DIGITS attribute is uninitialized
760-
* @param int $precision The precision value to returns if the FRACTION_DIGITS attribute is initialized
754+
* @param int|float $value The value to get the precision from if the FRACTION_DIGITS attribute is uninitialized
761755
*
762756
* @return int The precision value
763757
*/
764-
private function getUninitializedPrecision($value, $precision)
758+
private function getUninitializedPrecision($value, int $precision)
765759
{
766760
if (self::CURRENCY == $this->style) {
767761
return $precision;
@@ -780,11 +774,9 @@ private function getUninitializedPrecision($value, $precision)
780774
/**
781775
* Check if the attribute is initialized (value set by client code).
782776
*
783-
* @param string $attr The attribute name
784-
*
785777
* @return bool true if the value was set by client, false otherwise
786778
*/
787-
private function isInitializedAttribute($attr)
779+
private function isInitializedAttribute(string $attr)
788780
{
789781
return isset($this->initializedAttributes[$attr]);
790782
}
@@ -793,11 +785,10 @@ private function isInitializedAttribute($attr)
793785
* Returns the numeric value using the $type to convert to the right data type.
794786
*
795787
* @param mixed $value The value to be converted
796-
* @param int $type The type to convert. Can be TYPE_DOUBLE (float) or TYPE_INT32 (int)
797788
*
798789
* @return int|float|false The converted value
799790
*/
800-
private function convertValueDataType($value, $type)
791+
private function convertValueDataType($value, int $type)
801792
{
802793
if (self::TYPE_DOUBLE == $type) {
803794
$value = (float) $value;
@@ -813,8 +804,6 @@ private function convertValueDataType($value, $type)
813804
/**
814805
* Convert the value data type to int or returns false if the value is out of the integer value range.
815806
*
816-
* @param mixed $value The value to be converted
817-
*
818807
* @return int|false The converted value
819808
*/
820809
private function getInt32Value($value)
@@ -829,8 +818,6 @@ private function getInt32Value($value)
829818
/**
830819
* Convert the value data type to int or returns false if the value is out of the integer value range.
831820
*
832-
* @param mixed $value The value to be converted
833-
*
834821
* @return int|float|false The converted value
835822
*/
836823
private function getInt64Value($value)
@@ -849,11 +836,9 @@ private function getInt64Value($value)
849836
/**
850837
* Check if the rounding mode is invalid.
851838
*
852-
* @param int $value The rounding mode value to check
853-
*
854839
* @return bool true if the rounding mode is invalid, false otherwise
855840
*/
856-
private function isInvalidRoundingMode($value)
841+
private function isInvalidRoundingMode(int $value)
857842
{
858843
if (\in_array($value, self::$roundingModes, true)) {
859844
return false;
@@ -866,8 +851,6 @@ private function isInvalidRoundingMode($value)
866851
* Returns the normalized value for the GROUPING_USED attribute. Any value that can be converted to int will be
867852
* cast to Boolean and then to int again. This way, negative values are converted to 1 and string values to 0.
868853
*
869-
* @param mixed $value The value to be normalized
870-
*
871854
* @return int The normalized value for the attribute (0 or 1)
872855
*/
873856
private function normalizeGroupingUsedValue($value)
@@ -878,8 +861,6 @@ private function normalizeGroupingUsedValue($value)
878861
/**
879862
* Returns the normalized value for the FRACTION_DIGITS attribute.
880863
*
881-
* @param mixed $value The value to be normalized
882-
*
883864
* @return int The normalized value for the attribute
884865
*/
885866
private function normalizeFractionDigitsValue($value)

Tests/NumberFormatter/NumberFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testSetAttributeWithUnsupportedAttribute()
5959
public function testSetAttributeInvalidRoundingMode()
6060
{
6161
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
62-
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
62+
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, -1);
6363
}
6464

6565
public function testConstructWithoutLocale()

Util/GitRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function checkout($branch)
8585
$this->execInPath(sprintf('git checkout %s', escapeshellarg($branch)));
8686
}
8787

88-
private function execInPath($command)
88+
private function execInPath(string $command)
8989
{
9090
return self::exec(sprintf('cd %s && %s', escapeshellarg($this->path), $command));
9191
}

0 commit comments

Comments
 (0)