Code Duplication    Length = 20-24 lines in 6 locations

src/Assert.php 6 locations

@@ 2150-2169 (lines=20) @@
2147
     * @return Assert
2148
     * @throws AssertionFailedException
2149
     */
2150
    public function directory(string $message='', string $fieldName='') : Assert
2151
    {
2152
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2153
        {
2154
            return $this;
2155
        }
2156
        $this->string($message, $fieldName);
2157
        if ( !is_dir($this->value) )
2158
        {
2159
            $message = $message ?: $this->overrideError;
2160
            $message = sprintf(
2161
                $message ?: 'Path "%s" was expected to be a directory.',
2162
                $this->stringify($this->value)
2163
            );
2164
2165
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_DIRECTORY, $fieldName);
2166
        }
2167
2168
        return $this;
2169
    }
2170
2171
    /**
2172
     * Assert that value is something readable.
@@ 2179-2198 (lines=20) @@
2176
     * @return Assert
2177
     * @throws AssertionFailedException
2178
     */
2179
    public function readable(string $message='', string $fieldName='') : Assert
2180
    {
2181
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2182
        {
2183
            return $this;
2184
        }
2185
        $this->string($message, $fieldName);
2186
        if ( !is_readable($this->value) )
2187
        {
2188
            $message = $message ?: $this->overrideError;
2189
            $message = sprintf(
2190
                $message ?: 'Path "%s" was expected to be readable.',
2191
                $this->stringify($this->value)
2192
            );
2193
2194
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_READABLE, $fieldName);
2195
        }
2196
2197
        return $this;
2198
    }
2199
2200
    /**
2201
     * Assert that value is something writeable.
@@ 2208-2227 (lines=20) @@
2205
     * @return Assert
2206
     * @throws AssertionFailedException
2207
     */
2208
    public function writeable(string $message='', string $fieldName='') : Assert
2209
    {
2210
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2211
        {
2212
            return $this;
2213
        }
2214
        $this->string($message, $fieldName);
2215
        if ( !is_writeable($this->value) )
2216
        {
2217
            $message = $message ?: $this->overrideError;
2218
            $message = sprintf(
2219
                $message ?: 'Path "%s" was expected to be writeable.',
2220
                $this->stringify($this->value)
2221
            );
2222
2223
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_WRITEABLE, $fieldName);
2224
        }
2225
2226
        return $this;
2227
    }
2228
2229
    /**
2230
     * Assert that value is a valid email address (using input_filter/FILTER_VALIDATE_EMAIL).
@@ 2379-2402 (lines=24) @@
2376
     * @return Assert
2377
     * @throws AssertionFailedException
2378
     */
2379
    public function ausMobile(string $message='', string $fieldName='') : Assert
2380
    {
2381
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2382
        {
2383
            return $this;
2384
        }
2385
        try
2386
        {
2387
            $this->regex('/^04[0-9]{8})$/', $message, $fieldName);
2388
        }
2389
        catch ( AssertionFailedException $e )
2390
        {
2391
            $message = $message ?: $this->overrideError;
2392
            $message = sprintf(
2393
                $message
2394
                    ?: 'Value "%s" is not an australian mobile number.',
2395
                $this->stringify($this->value)
2396
            );
2397
2398
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_AUS_MOBILE, $fieldName);
2399
        }
2400
2401
        return $this;
2402
    }
2403
2404
    /**
2405
     * Assert that value is alphanumeric.
@@ 2412-2435 (lines=24) @@
2409
     * @return Assert
2410
     * @throws AssertionFailedException
2411
     */
2412
    public function alnum(string $message='', string $fieldName='') : Assert
2413
    {
2414
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2415
        {
2416
            return $this;
2417
        }
2418
        try
2419
        {
2420
            $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName);
2421
        }
2422
        catch (AssertionFailedException $e)
2423
        {
2424
            $message = $message ?: $this->overrideError;
2425
            $message = sprintf(
2426
                $message
2427
                    ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.',
2428
                $this->stringify($this->value)
2429
            );
2430
2431
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_ALNUM, $fieldName);
2432
        }
2433
2434
        return $this;
2435
    }
2436
2437
    /**
2438
     * Assert that value is boolean True.
@@ 2719-2742 (lines=24) @@
2716
     * @return Assert
2717
     * @throws AssertionFailedException
2718
     */
2719
    public function userPrincipalName(string $message='', string $fieldName='') : Assert
2720
    {
2721
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2722
        {
2723
            return $this;
2724
        }
2725
        try
2726
        {
2727
            $this->email($message, $fieldName);
2728
        }
2729
        catch (AssertionFailedException $e)
2730
        {
2731
            $message = $message ?: $this->overrideError;
2732
            $message = sprintf(
2733
                $message
2734
                    ?: 'Value "%s" is not a valid userPrincipalName.',
2735
                $this->stringify($this->value)
2736
            );
2737
2738
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_USERPRINCIPALNAME, $fieldName);
2739
        }
2740
2741
        return $this;
2742
    }
2743
2744
    /**
2745
     * Assert that the given string is a valid UUID