Code Duplication    Length = 17-18 lines in 3 locations

src/Assert.php 3 locations

@@ 1543-1560 (lines=18) @@
1540
     * @return Assert
1541
     * @throws AssertionFailedException
1542
     */
1543
    public function utf8($message = null, $propertyPath = null)
1544
    {
1545
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1546
        {
1547
            return $this;
1548
        }
1549
        $this->string($message, $propertyPath);
1550
        if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' )
1551
        {
1552
            $message = $message
1553
                ?: sprintf(
1554
                    'Value "%s" was expected to be a valid UTF8 string',
1555
                    $this->stringify($this->value)
1556
                );
1557
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $propertyPath);
1558
        }
1559
        return $this;
1560
    }
1561
1562
1563
    /**
@@ 1571-1588 (lines=18) @@
1568
     * @return Assert
1569
     * @throws AssertionFailedException
1570
     */
1571
    public function ascii($message = null, $propertyPath = null)
1572
    {
1573
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1574
        {
1575
            return $this;
1576
        }
1577
        $this->string($message, $propertyPath);
1578
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1579
        {
1580
            $message = $message
1581
                ?: sprintf(
1582
                    'Value "%s" was expected to be a valid ASCII string',
1583
                    $this->stringify($this->value)
1584
                );
1585
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $propertyPath);
1586
        }
1587
        return $this;
1588
    }
1589
1590
    /**
1591
     * Assert that key exists in an array/array-accessible object using isset()
@@ 2408-2424 (lines=17) @@
2405
     * @return Assert
2406
     * @throws AssertionFailedException
2407
     */
2408
    public function username($message = null, $propertyPath = null)
2409
    {
2410
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2411
        {
2412
            return $this;
2413
        }
2414
        if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) )
2415
        {
2416
            $message = $message ?: $this->overrideError;
2417
            $message = sprintf(
2418
                $message ?: 'Value "%s" is not a valid username.',
2419
                $this->stringify($this->value)
2420
            );
2421
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERNAME, $propertyPath);
2422
        }
2423
        return $this;
2424
    }
2425
    /**
2426
     * Assert that the count of countable is equal to count.
2427
     *