Code Duplication    Length = 18-22 lines in 4 locations

src/Assert.php 4 locations

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