Skip to content

Commit

Permalink
PHP 8.1 compatible (#320)
Browse files Browse the repository at this point in the history
Co-authored-by: Frank van Hest <[email protected]>
  • Loading branch information
frankvanhest and Frank van Hest authored Dec 16, 2021
1 parent 5e721d7 commit dbc94e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']

steps:
- name: Checkout
Expand Down
15 changes: 10 additions & 5 deletions lib/Assert/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public static function startsWith($string, $needle, $message = null, string $pro
{
static::string($string, $message, $propertyPath);

if (0 !== \mb_strpos($string, $needle, null, $encoding)) {
if (0 !== \mb_strpos($string, $needle, 0, $encoding)) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" does not start with "%s".'),
static::stringify($string),
Expand Down Expand Up @@ -987,7 +987,7 @@ public static function endsWith($string, $needle, $message = null, string $prope

$stringPosition = \mb_strlen($string, $encoding) - \mb_strlen($needle, $encoding);

if (\mb_strripos($string, $needle, null, $encoding) !== $stringPosition) {
if (\mb_strripos($string, $needle, 0, $encoding) !== $stringPosition) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" does not end with "%s".'),
static::stringify($string),
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public static function contains($string, $needle, $message = null, string $prope
{
static::string($string, $message, $propertyPath);

if (false === \mb_strpos($string, $needle, null, $encoding)) {
if (false === \mb_strpos($string, $needle, 0, $encoding)) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" does not contain "%s".'),
static::stringify($string),
Expand Down Expand Up @@ -1051,7 +1051,7 @@ public static function notContains($string, $needle, $message = null, string $pr
{
static::string($string, $message, $propertyPath);

if (false !== \mb_strpos($string, $needle, null, $encoding)) {
if (false !== \mb_strpos($string, $needle, 0, $encoding)) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" contains "%s".'),
static::stringify($string),
Expand Down Expand Up @@ -2620,7 +2620,12 @@ public static function satisfy($value, $callback, $message = null, string $prope
public static function ip($value, $flag = null, $message = null, string $propertyPath = null): bool
{
static::string($value, $message, $propertyPath);
if (!\filter_var($value, FILTER_VALIDATE_IP, $flag)) {
if ($flag === null) {
$filterVarResult = \filter_var($value, FILTER_VALIDATE_IP);
} else {
$filterVarResult = \filter_var($value, FILTER_VALIDATE_IP, $flag);
}
if (!$filterVarResult) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" was expected to be a valid IP address.'),
static::stringify($value)
Expand Down

0 comments on commit dbc94e5

Please sign in to comment.