Code Duplication    Length = 18-22 lines in 5 locations

src/Assert.php 5 locations

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