Code Duplication    Length = 18-22 lines in 6 locations

src/Assert.php 6 locations

@@ 1926-1943 (lines=18) @@
1923
     * @return Assert
1924
     * @throws AssertionFailedException
1925
     */
1926
    public function directory($message = null, $propertyPath = null)
1927
    {
1928
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1929
        {
1930
            return $this;
1931
        }
1932
        $this->string($message, $propertyPath);
1933
        if ( !is_dir($this->value) )
1934
        {
1935
            $message = $message ?: $this->overrideError;
1936
            $message = sprintf(
1937
                $message ?: 'Path "%s" was expected to be a directory.',
1938
                $this->stringify($this->value)
1939
            );
1940
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $propertyPath);
1941
        }
1942
        return $this;
1943
    }
1944
1945
    /**
1946
     * Assert that the value is something readable
@@ 1953-1970 (lines=18) @@
1950
     * @return Assert
1951
     * @throws AssertionFailedException
1952
     */
1953
    public function readable($message = null, $propertyPath = null)
1954
    {
1955
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1956
        {
1957
            return $this;
1958
        }
1959
        $this->string($message, $propertyPath);
1960
        if ( !is_readable($this->value) )
1961
        {
1962
            $message = $message ?: $this->overrideError;
1963
            $message = sprintf(
1964
                $message ?: 'Path "%s" was expected to be readable.',
1965
                $this->stringify($this->value)
1966
            );
1967
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $propertyPath);
1968
        }
1969
        return $this;
1970
    }
1971
1972
    /**
1973
     * Assert that the value is something writeable
@@ 1980-1997 (lines=18) @@
1977
     * @return Assert
1978
     * @throws AssertionFailedException
1979
     */
1980
    public function writeable($message = null, $propertyPath = null)
1981
    {
1982
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1983
        {
1984
            return $this;
1985
        }
1986
        $this->string($message, $propertyPath);
1987
        if ( !is_writeable($this->value) )
1988
        {
1989
            $message = $message ?: $this->overrideError;
1990
            $message = sprintf(
1991
                $message ?: 'Path "%s" was expected to be writeable.',
1992
                $this->stringify($this->value)
1993
            );
1994
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $propertyPath);
1995
        }
1996
        return $this;
1997
    }
1998
1999
    /**
2000
     * Assert that value is an email adress (using
@@ 2141-2162 (lines=22) @@
2138
     * @return Assert
2139
     * @throws AssertionFailedException
2140
     */
2141
    public function ausMobile($message = null, $propertyPath = null)
2142
    {
2143
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2144
        {
2145
            return $this;
2146
        }
2147
        try
2148
        {
2149
            $this->regex('/^04[0-9]{8})$/', $message, $propertyPath);
2150
        }
2151
        catch ( AssertionFailedException $e )
2152
        {
2153
            $message = $message ?: $this->overrideError;
2154
            $message = sprintf(
2155
                $message
2156
                    ?: 'Value "%s" is not an australian mobile number.',
2157
                $this->stringify($this->value)
2158
            );
2159
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $propertyPath);
2160
        }
2161
        return $this;
2162
    }
2163
2164
    /**
2165
     * Assert that value is alphanumeric.
@@ 2172-2193 (lines=22) @@
2169
     * @return Assert
2170
     * @throws AssertionFailedException
2171
     */
2172
    public function alnum($message = null, $propertyPath = null)
2173
    {
2174
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2175
        {
2176
            return $this;
2177
        }
2178
        try
2179
        {
2180
            $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath);
2181
        }
2182
        catch (AssertionFailedException $e)
2183
        {
2184
            $message = $message ?: $this->overrideError;
2185
            $message = sprintf(
2186
                $message
2187
                    ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.',
2188
                $this->stringify($this->value)
2189
            );
2190
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $propertyPath);
2191
        }
2192
        return $this;
2193
    }
2194
2195
    /**
2196
     * Assert that the value is boolean True.
@@ 2458-2476 (lines=19) @@
2455
     * @return Assert
2456
     * @throws AssertionFailedException
2457
     */
2458
    public function userPrincipalName($message = null, $propertyPath = null)
2459
    {
2460
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2461
        {
2462
            return $this;
2463
        }
2464
        try {
2465
            $this->email($message, $propertyPath);
2466
        } catch (AssertionFailedException $e) {
2467
            $message = $message ?: $this->overrideError;
2468
            $message = sprintf(
2469
                $message
2470
                    ?: 'Value "%s" is not a valid userPrincipalName.',
2471
                $this->stringify($this->value)
2472
            );
2473
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $propertyPath);
2474
        }
2475
        return $this;
2476
    }
2477
2478
    /**
2479
     * Assert that the count of countable is equal to count.