Code Duplication    Length = 18-18 lines in 2 locations

src/Assert.php 2 locations

@@ 1541-1558 (lines=18) @@
1538
     * @return Assert
1539
     * @throws AssertionFailedException
1540
     */
1541
    public function utf8($message = null, $propertyPath = null)
1542
    {
1543
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1544
        {
1545
            return $this;
1546
        }
1547
        $this->string($message, $propertyPath);
1548
        if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' )
1549
        {
1550
            $message = $message
1551
                ?: sprintf(
1552
                    'Value "%s" was expected to be a valid UTF8 string',
1553
                    $this->stringify($this->value)
1554
                );
1555
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath);
1556
        }
1557
        return $this;
1558
    }
1559
1560
1561
    /**
@@ 1569-1586 (lines=18) @@
1566
     * @return Assert
1567
     * @throws AssertionFailedException
1568
     */
1569
    public function ascii($message = null, $propertyPath = null)
1570
    {
1571
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1572
        {
1573
            return $this;
1574
        }
1575
        $this->string($message, $propertyPath);
1576
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1577
        {
1578
            $message = $message
1579
                ?: sprintf(
1580
                    'Value "%s" was expected to be a valid ASCII string',
1581
                    $this->stringify($this->value)
1582
                );
1583
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath);
1584
        }
1585
        return $this;
1586
    }
1587
1588
    /**
1589
     * Assert that key exists in an array/array-accessible object using isset()