Code Duplication    Length = 18-22 lines in 6 locations

src/Assert.php 6 locations

@@ 1903-1920 (lines=18) @@
1900
     * @return Assert
1901
     * @throws AssertionFailedException
1902
     */
1903
    public function directory($message = null, $propertyPath = null)
1904
    {
1905
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1906
        {
1907
            return $this;
1908
        }
1909
        $this->string($message, $propertyPath);
1910
        if ( !is_dir($this->value) )
1911
        {
1912
            $message = $message ?: $this->overrideError;
1913
            $message = sprintf(
1914
                $message ?: 'Path "%s" was expected to be a directory.',
1915
                $this->stringify($this->value)
1916
            );
1917
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $propertyPath);
1918
        }
1919
        return $this;
1920
    }
1921
1922
    /**
1923
     * Assert that the value is something readable
@@ 1930-1947 (lines=18) @@
1927
     * @return Assert
1928
     * @throws AssertionFailedException
1929
     */
1930
    public function readable($message = null, $propertyPath = null)
1931
    {
1932
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1933
        {
1934
            return $this;
1935
        }
1936
        $this->string($message, $propertyPath);
1937
        if ( !is_readable($this->value) )
1938
        {
1939
            $message = $message ?: $this->overrideError;
1940
            $message = sprintf(
1941
                $message ?: 'Path "%s" was expected to be readable.',
1942
                $this->stringify($this->value)
1943
            );
1944
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $propertyPath);
1945
        }
1946
        return $this;
1947
    }
1948
1949
    /**
1950
     * Assert that the value is something writeable
@@ 1957-1974 (lines=18) @@
1954
     * @return Assert
1955
     * @throws AssertionFailedException
1956
     */
1957
    public function writeable($message = null, $propertyPath = null)
1958
    {
1959
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1960
        {
1961
            return $this;
1962
        }
1963
        $this->string($message, $propertyPath);
1964
        if ( !is_writeable($this->value) )
1965
        {
1966
            $message = $message ?: $this->overrideError;
1967
            $message = sprintf(
1968
                $message ?: 'Path "%s" was expected to be writeable.',
1969
                $this->stringify($this->value)
1970
            );
1971
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $propertyPath);
1972
        }
1973
        return $this;
1974
    }
1975
1976
    /**
1977
     * Assert that value is an email adress (using
@@ 2118-2139 (lines=22) @@
2115
     * @return Assert
2116
     * @throws AssertionFailedException
2117
     */
2118
    public function ausMobile($message = null, $propertyPath = null)
2119
    {
2120
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2121
        {
2122
            return $this;
2123
        }
2124
        try
2125
        {
2126
            $this->regex('/^04[0-9]{8})$/', $message, $propertyPath);
2127
        }
2128
        catch ( AssertionFailedException $e )
2129
        {
2130
            $message = $message ?: $this->overrideError;
2131
            $message = sprintf(
2132
                $message
2133
                    ?: 'Value "%s" is not an australian mobile number.',
2134
                $this->stringify($this->value)
2135
            );
2136
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $propertyPath);
2137
        }
2138
        return $this;
2139
    }
2140
2141
    /**
2142
     * Assert that value is alphanumeric.
@@ 2149-2170 (lines=22) @@
2146
     * @return Assert
2147
     * @throws AssertionFailedException
2148
     */
2149
    public function alnum($message = null, $propertyPath = null)
2150
    {
2151
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2152
        {
2153
            return $this;
2154
        }
2155
        try
2156
        {
2157
            $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath);
2158
        }
2159
        catch (AssertionFailedException $e)
2160
        {
2161
            $message = $message ?: $this->overrideError;
2162
            $message = sprintf(
2163
                $message
2164
                    ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.',
2165
                $this->stringify($this->value)
2166
            );
2167
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $propertyPath);
2168
        }
2169
        return $this;
2170
    }
2171
2172
    /**
2173
     * Assert that the value is boolean True.
@@ 2435-2453 (lines=19) @@
2432
     * @return Assert
2433
     * @throws AssertionFailedException
2434
     */
2435
    public function userPrincipalName($message = null, $propertyPath = null)
2436
    {
2437
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2438
        {
2439
            return $this;
2440
        }
2441
        try {
2442
            $this->email($message, $propertyPath);
2443
        } catch (AssertionFailedException $e) {
2444
            $message = $message ?: $this->overrideError;
2445
            $message = sprintf(
2446
                $message
2447
                    ?: 'Value "%s" is not a valid userPrincipalName.',
2448
                $this->stringify($this->value)
2449
            );
2450
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $propertyPath);
2451
        }
2452
        return $this;
2453
    }
2454
2455
    /**
2456
     * Assert that the count of countable is equal to count.