Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 compatible #320

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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