Code Duplication    Length = 19-20 lines in 3 locations

src/Assert.php 3 locations

@@ 1762-1781 (lines=20) @@
1759
     * @return Assert
1760
     * @throws AssertionFailedException
1761
     */
1762
    public function utf8(string $message='', string $fieldName='') : Assert
1763
    {
1764
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1765
        {
1766
            return $this;
1767
        }
1768
        $this->string($message, $fieldName);
1769
        if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' )
1770
        {
1771
            $message = $message
1772
                ?: sprintf(
1773
                    'Value "%s" was expected to be a valid UTF8 string',
1774
                    $this->stringify($this->value)
1775
                );
1776
1777
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_UTF8, $fieldName);
1778
        }
1779
1780
        return $this;
1781
    }
1782
1783
1784
    /**
@@ 1792-1811 (lines=20) @@
1789
     * @return Assert
1790
     * @throws AssertionFailedException
1791
     */
1792
    public function ascii(string $message='', string $fieldName='') : Assert
1793
    {
1794
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1795
        {
1796
            return $this;
1797
        }
1798
        $this->string($message, $fieldName);
1799
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1800
        {
1801
            $message = $message
1802
                ?: sprintf(
1803
                    'Value "%s" was expected to be a valid ASCII string',
1804
                    $this->stringify($this->value)
1805
                );
1806
1807
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ASCII, $fieldName);
1808
        }
1809
1810
        return $this;
1811
    }
1812
1813
    /**
1814
     * Assert that key exists in an array/array-accessible object
@@ 2697-2715 (lines=19) @@
2694
     * @return Assert
2695
     * @throws AssertionFailedException
2696
     */
2697
    public function samAccountName(string $message='', string $fieldName='') : Assert
2698
    {
2699
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2700
        {
2701
            return $this;
2702
        }
2703
        if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) )
2704
        {
2705
            $message = $message ?: $this->overrideError;
2706
            $message = sprintf(
2707
                $message ?: 'Value "%s" is not a valid samAccountName.',
2708
                $this->stringify($this->value)
2709
            );
2710
2711
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAMACCOUNTNAME, $fieldName);
2712
        }
2713
2714
        return $this;
2715
    }
2716
2717
    /**
2718
     * Assert that value is a valid userPrincipalName.