Code Duplication    Length = 20-24 lines in 6 locations

src/Assert.php 6 locations

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