Code Duplication    Length = 18-18 lines in 2 locations

src/Assert.php 2 locations

@@ 1519-1536 (lines=18) @@
1516
     * @return Assert
1517
     * @throws AssertionFailedException
1518
     */
1519
    public function utf8($message = null, $propertyPath = null)
1520
    {
1521
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1522
        {
1523
            return $this;
1524
        }
1525
        $this->string($message, $propertyPath);
1526
        if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' )
1527
        {
1528
            $message = $message
1529
                ?: sprintf(
1530
                    'Value "%s" was expected to be a valid UTF8 string',
1531
                    $this->stringify($this->value)
1532
                );
1533
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath);
1534
        }
1535
        return $this;
1536
    }
1537
1538
1539
    /**
@@ 1547-1564 (lines=18) @@
1544
     * @return Assert
1545
     * @throws AssertionFailedException
1546
     */
1547
    public function ascii($message = null, $propertyPath = null)
1548
    {
1549
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1550
        {
1551
            return $this;
1552
        }
1553
        $this->string($message, $propertyPath);
1554
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1555
        {
1556
            $message = $message
1557
                ?: sprintf(
1558
                    'Value "%s" was expected to be a valid ASCII string',
1559
                    $this->stringify($this->value)
1560
                );
1561
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath);
1562
        }
1563
        return $this;
1564
    }
1565
1566
    /**
1567
     * Assert that key exists in an array/array-accessible object using isset()