Skip to content

Commit f78a091

Browse files
committed
Warning to ValueError promotion in Intl extension Part 1
Affects: - IntlCalendar - IntlGregorianCalendar - IntlBreakIterator Closes GH-5669
1 parent d3a9e15 commit f78a091

24 files changed

+442
-459
lines changed

ext/intl/breakiterator/breakiterator.stub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function current() {}
3030
/** @return int */
3131
public function first() {}
3232

33-
/** @return int|false */
33+
/** @return int */
3434
public function following(int $offset) {}
3535

3636
/** @return int */
@@ -42,7 +42,7 @@ public function getErrorMessage() {}
4242
/** @return string */
4343
public function getLocale(int $locale_type) {}
4444

45-
/** @return IntlPartsIterator|false */
45+
/** @return IntlPartsIterator */
4646
public function getPartsIterator(string $key_type = IntlPartsIterator::KEY_SEQUENTIAL) {}
4747

4848
/** @return string|null */
@@ -54,10 +54,10 @@ public function isBoundary(int $offset) {}
5454
/** @return int */
5555
public function last() {}
5656

57-
/** @return int|false */
57+
/** @return int */
5858
public function next(?int $offset = null) {}
5959

60-
/** @return int|false */
60+
/** @return int */
6161
public function preceding(int $offset) {}
6262

6363
/** @return int */

ext/intl/breakiterator/breakiterator_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7180c7b167edb3aa8580ae4a600627f28636ac38 */
2+
* Stub hash: 5eeedbbb7d07b0063d7bc19842b863a2c6d6898b */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlBreakIterator_createCharacterInstance, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null")

ext/intl/breakiterator/breakiterator_methods.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static void _breakiter_factory(const char *func_name,
6363

6464
biter = func(Locale::createFromName(locale_str), status);
6565
intl_error_set_code(NULL, status);
66+
// Todo check if this can happen?
6667
if (U_FAILURE(status)) {
6768
spprintf(&msg, 0, "%s: error creating BreakIterator",
6869
func_name);
@@ -170,7 +171,6 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, setText)
170171
}
171172

172173
static void _breakiter_no_args_ret_int32(
173-
const char *func_name,
174174
int32_t (BreakIterator::*func)(),
175175
INTERNAL_FUNCTION_PARAMETERS)
176176
{
@@ -190,11 +190,9 @@ static void _breakiter_no_args_ret_int32(
190190
}
191191

192192
static void _breakiter_int32_ret_int32(
193-
const char *func_name,
194193
int32_t (BreakIterator::*func)(int32_t),
195194
INTERNAL_FUNCTION_PARAMETERS)
196195
{
197-
char *msg;
198196
zend_long arg;
199197
BREAKITER_METHOD_INIT_VARS;
200198
object = ZEND_THIS;
@@ -206,11 +204,8 @@ static void _breakiter_int32_ret_int32(
206204
BREAKITER_METHOD_FETCH_OBJECT;
207205

208206
if (arg < INT32_MIN || arg > INT32_MAX) {
209-
spprintf(&msg, 0, "%s: offset argument is outside bounds of "
210-
"a 32-bit wide integer", func_name);
211-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, msg, 1);
212-
efree(msg);
213-
RETURN_FALSE;
207+
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
208+
RETURN_THROWS();
214209
}
215210

216211
int32_t res = (bio->biter->*func)((int32_t)arg);
@@ -220,22 +215,19 @@ static void _breakiter_int32_ret_int32(
220215

221216
U_CFUNC PHP_METHOD(IntlBreakIterator, first)
222217
{
223-
_breakiter_no_args_ret_int32("breakiter_first",
224-
&BreakIterator::first,
218+
_breakiter_no_args_ret_int32(&BreakIterator::first,
225219
INTERNAL_FUNCTION_PARAM_PASSTHRU);
226220
}
227221

228222
U_CFUNC PHP_METHOD(IntlBreakIterator, last)
229223
{
230-
_breakiter_no_args_ret_int32("breakiter_last",
231-
&BreakIterator::last,
224+
_breakiter_no_args_ret_int32(&BreakIterator::last,
232225
INTERNAL_FUNCTION_PARAM_PASSTHRU);
233226
}
234227

235228
U_CFUNC PHP_METHOD(IntlBreakIterator, previous)
236229
{
237-
_breakiter_no_args_ret_int32("breakiter_previous",
238-
&BreakIterator::previous,
230+
_breakiter_no_args_ret_int32(&BreakIterator::previous,
239231
INTERNAL_FUNCTION_PARAM_PASSTHRU);
240232
}
241233

@@ -253,12 +245,10 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, next)
253245
if (arg == NULL) {
254246
ZEND_NUM_ARGS() = 0; /* pretend we don't have any argument */
255247
no_arg_version:
256-
_breakiter_no_args_ret_int32("breakiter_next",
257-
&BreakIterator::next,
248+
_breakiter_no_args_ret_int32(&BreakIterator::next,
258249
INTERNAL_FUNCTION_PARAM_PASSTHRU);
259250
} else {
260-
_breakiter_int32_ret_int32("breakiter_next",
261-
&BreakIterator::next,
251+
_breakiter_int32_ret_int32(&BreakIterator::next,
262252
INTERNAL_FUNCTION_PARAM_PASSTHRU);
263253
}
264254
}
@@ -281,14 +271,14 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, current)
281271

282272
U_CFUNC PHP_METHOD(IntlBreakIterator, following)
283273
{
284-
_breakiter_int32_ret_int32("breakiter_following",
274+
_breakiter_int32_ret_int32(
285275
&BreakIterator::following,
286276
INTERNAL_FUNCTION_PARAM_PASSTHRU);
287277
}
288278

289279
U_CFUNC PHP_METHOD(IntlBreakIterator, preceding)
290280
{
291-
_breakiter_int32_ret_int32("breakiter_preceding",
281+
_breakiter_int32_ret_int32(
292282
&BreakIterator::preceding,
293283
INTERNAL_FUNCTION_PARAM_PASSTHRU);
294284
}
@@ -305,10 +295,8 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, isBoundary)
305295
}
306296

307297
if (offset < INT32_MIN || offset > INT32_MAX) {
308-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
309-
"breakiter_is_boundary: offset argument is outside bounds of "
310-
"a 32-bit wide integer", 0);
311-
RETURN_FALSE;
298+
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
299+
RETURN_THROWS();
312300
}
313301

314302
BREAKITER_METHOD_FETCH_OBJECT;
@@ -328,6 +316,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getLocale)
328316
RETURN_THROWS();
329317
}
330318

319+
/* Change to ValueError? */
331320
if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) {
332321
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
333322
"breakiter_get_locale: invalid locale type", 0);
@@ -357,9 +346,9 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getPartsIterator)
357346
if (key_type != PARTS_ITERATOR_KEY_SEQUENTIAL
358347
&& key_type != PARTS_ITERATOR_KEY_LEFT
359348
&& key_type != PARTS_ITERATOR_KEY_RIGHT) {
360-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
361-
"breakiter_get_parts_iterator: bad key type", 0);
362-
RETURN_FALSE;
349+
zend_argument_value_error(1, "must be one of IntlPartsIterator::KEY_SEQUENTIAL, "
350+
"IntlPartsIterator::KEY_LEFT, or IntlPartsIterator::KEY_RIGHT");
351+
RETURN_THROWS();
363352
}
364353

365354
BREAKITER_METHOD_FETCH_OBJECT;

ext/intl/calendar/calendar.stub.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function createInstance($timeZone = null, ?string $locale = null)
2020
public function equals(IntlCalendar $calendar) {}
2121

2222
/**
23-
* @return int|false
23+
* @return int
2424
* @alias intlcal_field_difference
2525
*/
2626
public function fieldDifference(float $when, int $field) {}
@@ -57,19 +57,19 @@ public function clear(?int $field = null) {}
5757
public static function fromDateTime($dateTime, ?string $locale = null) {}
5858

5959
/**
60-
* @return int|false
60+
* @return int
6161
* @alias intlcal_get
6262
*/
6363
public function get(int $field) {}
6464

6565
/**
66-
* @return int|false
66+
* @return int
6767
* @alias intlcal_get_actual_maximum
6868
*/
6969
public function getActualMaximum(int $field) {}
7070

7171
/**
72-
* @return int|false
72+
* @return int
7373
* @alias intlcal_get_actual_minimum
7474
*/
7575
public function getActualMinimum(int $field) {}
@@ -81,7 +81,7 @@ public function getActualMinimum(int $field) {}
8181
public static function getAvailableLocales() {}
8282

8383
/**
84-
* @return int|false
84+
* @return int
8585
* @alias intlcal_get_day_of_week_type
8686
*/
8787
public function getDayOfWeekType(int $dayOfWeek) {}
@@ -99,13 +99,13 @@ public function getErrorCode() {}
9999
public function getErrorMessage() {}
100100

101101
/**
102-
* @return int|false
102+
* @return int
103103
* @alias intlcal_get_first_day_of_week
104104
*/
105105
public function getFirstDayOfWeek() {}
106106

107107
/**
108-
* @return int|false
108+
* @return int
109109
* @alias intlcal_get_greatest_minimum
110110
*/
111111
public function getGreatestMinimum(int $field) {}
@@ -117,25 +117,25 @@ public function getGreatestMinimum(int $field) {}
117117
public static function getKeywordValuesForLocale(string $key, string $locale, bool $commonlyUsed) {}
118118

119119
/**
120-
* @return int|false
120+
* @return int
121121
* @alias intlcal_get_least_maximum
122122
*/
123123
public function getLeastMaximum(int $field) {}
124124

125125
/**
126-
* @return string|false
126+
* @return string
127127
* @alias intlcal_get_locale
128128
*/
129129
public function getLocale(int $localeType) {}
130130

131131
/**
132-
* @return int|false
132+
* @return int
133133
* @alias intlcal_get_maximum
134134
*/
135135
public function getMaximum(int $field) {}
136136

137137
/**
138-
* @return int|false
138+
* @return int
139139
* @alias intlcal_get_minimal_days_in_first_week
140140
*/
141141
public function getMinimalDaysInFirstWeek() {}
@@ -147,7 +147,7 @@ public function getMinimalDaysInFirstWeek() {}
147147
public function setMinimalDaysInFirstWeek(int $numberOfDays) {}
148148

149149
/**
150-
* @return int|false
150+
* @return int
151151
* @alias intlcal_get_minimum
152152
*/
153153
public function getMinimum(int $field) {}
@@ -171,7 +171,7 @@ public function getRepeatedWallTimeOption() {}
171171
public function getSkippedWallTimeOption() {}
172172

173173
/**
174-
* @return float|false
174+
* @return float
175175
* @alias intlcal_get_time
176176
*/
177177
public function getTime() {}
@@ -189,7 +189,7 @@ public function getTimeZone() {}
189189
public function getType() {}
190190

191191
/**
192-
* @return int|false
192+
* @return int
193193
* @alias intlcal_get_weekend_transition
194194
*/
195195
public function getWeekendTransition(int $dayOfWeek) {}
@@ -292,7 +292,7 @@ public function __construct($timeZoneOrYear = UNKNOWN, $localeOrMonth = UNKNOWN,
292292
public function setGregorianChange(float $change) {}
293293

294294
/**
295-
* @return float|false
295+
* @return float
296296
* @alias intlgregcal_get_gregorian_change
297297
*/
298298
public function getGregorianChange() {}

ext/intl/calendar/calendar_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7261d52837a7ac393453511d2c29ee9106407236 */
2+
* Stub hash: 8b8a98d5035880031ac42fda5e58bde54c1d85fc */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)