Bump version from ^5.0.1 to ^5.2.0.
No backwards incompatible changes except ext-dom was added to requirements, which is bundled with PHP.
Remove redundant check of $base_locale.
The setSource() method already supports passing null as a parameter. So we can just use setSource($base_locale) even if the value is null (otherwise it will be string as defined in parameter type).
Wider exception class
The translate() might throw multiple different exceptions, most of them extend ErrorException, but some of them are extending UnexpectedValueException. Using Exception in catch block to cover all possible situations.
Null coalescing operator
The translate() method of my package might return null. Returning null will cause uncaught TypeError. Added null coalescing operator to handle this situation.
Other
Returning false from method with return type string
One thing that I didn't change is the return false in the catch block. Method has string as return type (as defined in ApiTranslatorContract). Returning false will not cause any errors like in case of null, but it will be converted to an empty string. I'm not sure if it's intended that way so I didn't touch it.
Changes proposed
^5.0.1
to^5.2.0
. No backwards incompatible changes exceptext-dom
was added to requirements, which is bundled with PHP.$base_locale
. ThesetSource()
method already supports passing null as a parameter. So we can just usesetSource($base_locale)
even if the value isnull
(otherwise it will be string as defined in parameter type).translate()
might throw multiple different exceptions, most of them extendErrorException
, but some of them are extendingUnexpectedValueException
. UsingException
in catch block to cover all possible situations.translate()
method of my package might returnnull
. Returningnull
will cause uncaughtTypeError
. Added null coalescing operator to handle this situation.Other
false
from method with return typestring
One thing that I didn't change is thereturn false
in the catch block. Method hasstring
as return type (as defined inApiTranslatorContract
). Returningfalse
will not cause any errors like in case of null, but it will be converted to an empty string. I'm not sure if it's intended that way so I didn't touch it.