Code Duplication    Length = 18-22 lines in 6 locations

src/Assert.php 6 locations

@@ 2008-2025 (lines=18) @@
2005
     * @return Assert
2006
     * @throws AssertionFailedException
2007
     */
2008
    public function directory($message = null, $fieldName = null)
2009
    {
2010
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2011
        {
2012
            return $this;
2013
        }
2014
        $this->string($message, $fieldName);
2015
        if ( !is_dir($this->value) )
2016
        {
2017
            $message = $message ?: $this->overrideError;
2018
            $message = sprintf(
2019
                $message ?: 'Path "%s" was expected to be a directory.',
2020
                $this->stringify($this->value)
2021
            );
2022
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $fieldName);
2023
        }
2024
        return $this;
2025
    }
2026
2027
    /**
2028
     * Assert that value is something readable.
@@ 2035-2052 (lines=18) @@
2032
     * @return Assert
2033
     * @throws AssertionFailedException
2034
     */
2035
    public function readable($message = null, $fieldName = null)
2036
    {
2037
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2038
        {
2039
            return $this;
2040
        }
2041
        $this->string($message, $fieldName);
2042
        if ( !is_readable($this->value) )
2043
        {
2044
            $message = $message ?: $this->overrideError;
2045
            $message = sprintf(
2046
                $message ?: 'Path "%s" was expected to be readable.',
2047
                $this->stringify($this->value)
2048
            );
2049
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $fieldName);
2050
        }
2051
        return $this;
2052
    }
2053
2054
    /**
2055
     * Assert that value is something writeable.
@@ 2062-2079 (lines=18) @@
2059
     * @return Assert
2060
     * @throws AssertionFailedException
2061
     */
2062
    public function writeable($message = null, $fieldName = null)
2063
    {
2064
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2065
        {
2066
            return $this;
2067
        }
2068
        $this->string($message, $fieldName);
2069
        if ( !is_writeable($this->value) )
2070
        {
2071
            $message = $message ?: $this->overrideError;
2072
            $message = sprintf(
2073
                $message ?: 'Path "%s" was expected to be writeable.',
2074
                $this->stringify($this->value)
2075
            );
2076
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $fieldName);
2077
        }
2078
        return $this;
2079
    }
2080
2081
    /**
2082
     * Assert that value is a valid email address (using input_filter/FILTER_VALIDATE_EMAIL).
@@ 2224-2245 (lines=22) @@
2221
     * @return Assert
2222
     * @throws AssertionFailedException
2223
     */
2224
    public function ausMobile($message = null, $fieldName = null)
2225
    {
2226
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2227
        {
2228
            return $this;
2229
        }
2230
        try
2231
        {
2232
            $this->regex('/^04[0-9]{8})$/', $message, $fieldName);
2233
        }
2234
        catch ( AssertionFailedException $e )
2235
        {
2236
            $message = $message ?: $this->overrideError;
2237
            $message = sprintf(
2238
                $message
2239
                    ?: 'Value "%s" is not an australian mobile number.',
2240
                $this->stringify($this->value)
2241
            );
2242
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $fieldName);
2243
        }
2244
        return $this;
2245
    }
2246
2247
    /**
2248
     * Assert that value is alphanumeric.
@@ 2255-2276 (lines=22) @@
2252
     * @return Assert
2253
     * @throws AssertionFailedException
2254
     */
2255
    public function alnum($message = null, $fieldName = null)
2256
    {
2257
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2258
        {
2259
            return $this;
2260
        }
2261
        try
2262
        {
2263
            $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName);
2264
        }
2265
        catch (AssertionFailedException $e)
2266
        {
2267
            $message = $message ?: $this->overrideError;
2268
            $message = sprintf(
2269
                $message
2270
                    ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.',
2271
                $this->stringify($this->value)
2272
            );
2273
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $fieldName);
2274
        }
2275
        return $this;
2276
    }
2277
2278
    /**
2279
     * Assert that value is boolean True.
@@ 2544-2562 (lines=19) @@
2541
     * @return Assert
2542
     * @throws AssertionFailedException
2543
     */
2544
    public function userPrincipalName($message = null, $fieldName = null)
2545
    {
2546
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2547
        {
2548
            return $this;
2549
        }
2550
        try
2551
        {
2552
            $this->email($message, $fieldName);
2553
        }
2554
        catch (AssertionFailedException $e)
2555
        {
2556
            $message = $message ?: $this->overrideError;
2557
            $message = sprintf(
2558
                $message
2559
                    ?: 'Value "%s" is not a valid userPrincipalName.',
2560
                $this->stringify($this->value)
2561
            );
2562
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $fieldName);
2563
        }
2564
        return $this;
2565
    }