Code Duplication    Length = 18-18 lines in 2 locations

src/Assert.php 2 locations

@@ 1480-1497 (lines=18) @@
1477
     * @return Assert
1478
     * @throws AssertionFailedException
1479
     */
1480
    public function utf8($message = null, $propertyPath = null)
1481
    {
1482
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1483
        {
1484
            return $this;
1485
        }
1486
        $this->string($message, $propertyPath);
1487
        if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' )
1488
        {
1489
            $message = $message
1490
                ?: sprintf(
1491
                    'Value "%s" was expected to be a valid UTF8 string',
1492
                    $this->stringify($this->value)
1493
                );
1494
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath);
1495
        }
1496
        return $this;
1497
    }
1498
1499
1500
    /**
@@ 1508-1525 (lines=18) @@
1505
     * @return Assert
1506
     * @throws AssertionFailedException
1507
     */
1508
    public function ascii($message = null, $propertyPath = null)
1509
    {
1510
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1511
        {
1512
            return $this;
1513
        }
1514
        $this->string($message, $propertyPath);
1515
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1516
        {
1517
            $message = $message
1518
                ?: sprintf(
1519
                    'Value "%s" was expected to be a valid ASCII string',
1520
                    $this->stringify($this->value)
1521
                );
1522
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath);
1523
        }
1524
        return $this;
1525
    }
1526
1527
    /**
1528
     * Assert that key exists in an array/array-accessible object using isset()