Skip to content

Commit 4ce8f19

Browse files
minor #33056 cleanup remaining param $options and internal Intl FullTransformer (Tobion)
This PR was merged into the 4.4 branch. Discussion ---------- cleanup remaining param $options and internal Intl FullTransformer | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets |#... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | Continuation of #33020 and #33019 Commits ------- 5dbcdc6ff4 cleanup remaining param and internal Intl FulLTransformer
2 parents ab5dbe8 + f425594 commit 4ce8f19

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

DateFormatter/DateFormat/FullTransformer.php

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,9 @@ public function __construct(string $pattern, string $timezone)
6969
];
7070
}
7171

72-
/**
73-
* Return the array of Transformer objects.
74-
*
75-
* @return Transformer[] Associative array of Transformer objects (format char => Transformer)
76-
*/
77-
public function getTransformers()
78-
{
79-
return $this->transformers;
80-
}
81-
8272
/**
8373
* Format a DateTime using ICU dateformat pattern.
8474
*
85-
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
86-
*
8775
* @return string The formatted value
8876
*/
8977
public function format(\DateTime $dateTime)
@@ -98,14 +86,9 @@ public function format(\DateTime $dateTime)
9886
/**
9987
* Return the formatted ICU value for the matched date characters.
10088
*
101-
* @param string $dateChars The date characters to be replaced with a formatted ICU value
102-
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
103-
*
104-
* @return string The formatted value
105-
*
10689
* @throws NotImplementedException When it encounters a not implemented date character
10790
*/
108-
public function formatReplace($dateChars, $dateTime)
91+
private function formatReplace(string $dateChars, \DateTime $dateTime): string
10992
{
11093
$length = \strlen($dateChars);
11194

@@ -167,12 +150,10 @@ public function parse(\DateTime $dateTime, $value)
167150
/**
168151
* Retrieve a regular expression to match with a formatted value.
169152
*
170-
* @param string $pattern The pattern to create the reverse matching regular expression
171-
*
172153
* @return string The reverse matching regular expression with named captures being formed by the
173154
* transformer index in the $transformer array
174155
*/
175-
public function getReverseMatchingRegExp($pattern)
156+
private function getReverseMatchingRegExp(string $pattern): string
176157
{
177158
$escapedPattern = preg_quote($pattern, '/');
178159

@@ -189,9 +170,8 @@ public function getReverseMatchingRegExp($pattern)
189170
return $this->replaceQuoteMatch($dateChars);
190171
}
191172

192-
$transformers = $this->getTransformers();
193-
if (isset($transformers[$transformerIndex])) {
194-
$transformer = $transformers[$transformerIndex];
173+
if (isset($this->transformers[$transformerIndex])) {
174+
$transformer = $this->transformers[$transformerIndex];
195175
$captureName = str_repeat($transformerIndex, $length);
196176

197177
return "(?P<$captureName>".$transformer->getReverseMatchingRegExp($length).')';
@@ -203,24 +183,16 @@ public function getReverseMatchingRegExp($pattern)
203183

204184
/**
205185
* Check if the first char of a string is a single quote.
206-
*
207-
* @param string $quoteMatch The string to check
208-
*
209-
* @return bool true if matches, false otherwise
210186
*/
211-
public function isQuoteMatch($quoteMatch)
187+
private function isQuoteMatch(string $quoteMatch): bool
212188
{
213189
return "'" === $quoteMatch[0];
214190
}
215191

216192
/**
217193
* Replaces single quotes at the start or end of a string with two single quotes.
218-
*
219-
* @param string $quoteMatch The string to replace the quotes
220-
*
221-
* @return string A string with the single quotes replaced
222194
*/
223-
public function replaceQuoteMatch($quoteMatch)
195+
private function replaceQuoteMatch(string $quoteMatch): string
224196
{
225197
if (preg_match("/^'+$/", $quoteMatch)) {
226198
return str_replace("''", "'", $quoteMatch);
@@ -231,12 +203,8 @@ public function replaceQuoteMatch($quoteMatch)
231203

232204
/**
233205
* Builds a chars match regular expression.
234-
*
235-
* @param string $specialChars A string of chars to build the regular expression
236-
*
237-
* @return string The chars match regular expression
238206
*/
239-
protected function buildCharsMatch($specialChars)
207+
private function buildCharsMatch(string $specialChars): string
240208
{
241209
$specialCharsArray = str_split($specialChars);
242210

@@ -250,10 +218,8 @@ protected function buildCharsMatch($specialChars)
250218
/**
251219
* Normalize a preg_replace match array, removing the numeric keys and returning an associative array
252220
* with the value and pattern values for the matched Transformer.
253-
*
254-
* @return array
255221
*/
256-
protected function normalizeArray(array $data)
222+
private function normalizeArray(array $data): array
257223
{
258224
$ret = [];
259225

@@ -275,12 +241,9 @@ protected function normalizeArray(array $data)
275241
* Calculates the Unix timestamp based on the matched values by the reverse matching regular
276242
* expression of parse().
277243
*
278-
* @param \DateTime $dateTime The DateTime object to be used to calculate the timestamp
279-
* @param array $options An array with the matched values to be used to calculate the timestamp
280-
*
281244
* @return bool|int The calculated timestamp or false if matched date is invalid
282245
*/
283-
protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
246+
private function calculateUnixTimestamp(\DateTime $dateTime, array $options)
284247
{
285248
$options = $this->getDefaultValueForOptions($options);
286249

DateFormatter/DateFormat/Transformer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ abstract class Transformer
2323
/**
2424
* Format a value using a configured DateTime as date/time source.
2525
*
26-
*
2726
* @param \DateTime $dateTime A DateTime object to be used to generate the formatted value
2827
* @param int $length The formatted value string length
2928
*

0 commit comments

Comments
 (0)