Code Duplication    Length = 17-21 lines in 10 locations

src/Assert.php 10 locations

@@ 240-256 (lines=17) @@
237
     * @return Assert
238
     * @throws AssertionFailedException
239
     */
240
    public function greaterThan($value2, $message = null, $propertyPath = null)
241
    {
242
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
243
        {
244
            return $this;
245
        }
246
        if ( ! ( $this->value > $value2 ) )
247
        {
248
            $message = sprintf(
249
                $message ?: 'Value "%s" does not greater then expected value "%s".',
250
                $this->stringify($this->value),
251
                $this->stringify($value2)
252
            );
253
            throw $this->createException($message, self::INVALID_EQ, $propertyPath, ['expected' => $value2]);
254
        }
255
        return $this;
256
    }
257
258
    /**
259
     *
@@ 266-282 (lines=17) @@
263
     * @return Assert
264
     * @throws AssertionFailedException
265
     */
266
    public function greaterThanOrEq($value2, $message = null, $propertyPath = null)
267
    {
268
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
269
        {
270
            return $this;
271
        }
272
        if ( ! ( $this->value >= $value2 ) )
273
        {
274
            $message = sprintf(
275
                $message ?: 'Value "%s" does not greater than or equal to expected value "%s".',
276
                $this->stringify($this->value),
277
                $this->stringify($value2)
278
            );
279
            throw $this->createException($message, self::INVALID_EQ, $propertyPath, ['expected' => $value2]);
280
        }
281
        return $this;
282
    }
283
284
    /**
285
     *
@@ 292-308 (lines=17) @@
289
     * @return Assert
290
     * @throws AssertionFailedException
291
     */
292
    public function lessThan($value2, $message = null, $propertyPath = null)
293
    {
294
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
295
        {
296
            return $this;
297
        }
298
        if ( ! ( $this->value < $value2 ) )
299
        {
300
            $message = sprintf(
301
                $message ?: 'Value "%s" does not less then expected value "%s".',
302
                $this->stringify($this->value),
303
                $this->stringify($value2)
304
            );
305
            throw $this->createException($message, self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]);
306
        }
307
        return $this;
308
    }
309
310
    /**
311
     *
@@ 318-334 (lines=17) @@
315
     * @return Assert
316
     * @throws AssertionFailedException
317
     */
318
    public function lessThanOrEq($value2, $message = null, $propertyPath = null)
319
    {
320
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
321
        {
322
            return $this;
323
        }
324
        if ( ! ( $this->value <= $value2 ) )
325
        {
326
            $message = sprintf(
327
                $message ?: 'Value "%s" does not less than or equal to expected value "%s".',
328
                $this->stringify($this->value),
329
                $this->stringify($value2)
330
            );
331
            throw $this->createException($message, self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]);
332
        }
333
        return $this;
334
    }
335
336
    /**
337
     * Assert that two values are the same (using ===).
@@ 1403-1420 (lines=18) @@
1400
     * @return Assert
1401
     * @throws AssertionFailedException
1402
     */
1403
    public function ascii($message = null, $propertyPath = null)
1404
    {
1405
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1406
        {
1407
            return $this;
1408
        }
1409
        $this->string($message, $propertyPath);
1410
        if ( ! preg_match('/^[ -~]+$/', $this->value) )
1411
        {
1412
            $message = $message
1413
                ?: sprintf(
1414
                    'Value "%s" was expected to be a valid ASCII string',
1415
                    $this->stringify($this->value)
1416
                );
1417
            throw $this->createException($message, self::INVALID_ASCII, $propertyPath);
1418
        }
1419
        return $this;
1420
    }
1421
1422
    /**
1423
     * Assert that key exists in an array/array-accessible object using isset()
@@ 1724-1740 (lines=17) @@
1721
     * @return Assert
1722
     * @throws AssertionFailedException
1723
     */
1724
    public function directory($message = null, $propertyPath = null)
1725
    {
1726
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1727
        {
1728
            return $this;
1729
        }
1730
        $this->string($message, $propertyPath);
1731
        if ( !is_dir($this->value) )
1732
        {
1733
            $message = sprintf(
1734
                $message ?: 'Path "%s" was expected to be a directory.',
1735
                $this->stringify($this->value)
1736
            );
1737
            throw $this->createException($message, self::INVALID_DIRECTORY, $propertyPath);
1738
        }
1739
        return $this;
1740
    }
1741
1742
    /**
1743
     * Assert that the value is something readable
@@ 1750-1766 (lines=17) @@
1747
     * @return Assert
1748
     * @throws AssertionFailedException
1749
     */
1750
    public function readable($message = null, $propertyPath = null)
1751
    {
1752
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1753
        {
1754
            return $this;
1755
        }
1756
        $this->string($message, $propertyPath);
1757
        if ( !is_readable($this->value) )
1758
        {
1759
            $message = sprintf(
1760
                $message ?: 'Path "%s" was expected to be readable.',
1761
                $this->stringify($this->value)
1762
            );
1763
            throw $this->createException($message, self::INVALID_READABLE, $propertyPath);
1764
        }
1765
        return $this;
1766
    }
1767
1768
    /**
1769
     * Assert that the value is something writeable
@@ 1776-1792 (lines=17) @@
1773
     * @return Assert
1774
     * @throws AssertionFailedException
1775
     */
1776
    public function writeable($message = null, $propertyPath = null)
1777
    {
1778
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1779
        {
1780
            return $this;
1781
        }
1782
        $this->string($message, $propertyPath);
1783
        if ( !is_writeable($this->value) )
1784
        {
1785
            $message = sprintf(
1786
                $message ?: 'Path "%s" was expected to be writeable.',
1787
                $this->stringify($this->value)
1788
            );
1789
            throw $this->createException($message, self::INVALID_WRITEABLE, $propertyPath);
1790
        }
1791
        return $this;
1792
    }
1793
1794
    /**
1795
     * Assert that value is an email adress (using
@@ 1932-1952 (lines=21) @@
1929
     * @return Assert
1930
     * @throws AssertionFailedException
1931
     */
1932
    public function alnum($message = null, $propertyPath = null)
1933
    {
1934
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1935
        {
1936
            return $this;
1937
        }
1938
        try
1939
        {
1940
            $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath);
1941
        }
1942
        catch (AssertionFailedException $e)
1943
        {
1944
            $message = sprintf(
1945
                $message
1946
                    ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.',
1947
                $this->stringify($this->value)
1948
            );
1949
            throw $this->createException($message, self::INVALID_ALNUM, $propertyPath);
1950
        }
1951
        return $this;
1952
    }
1953
1954
    /**
1955
     * Assert that the value is boolean True.
@@ 2252-2268 (lines=17) @@
2249
     * @returns Assert
2250
     * @throws
2251
     */
2252
    public function methodExists($object, $message = null, $propertyPath = null)
2253
    {
2254
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
2255
        {
2256
            return $this;
2257
        }
2258
        (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath);
2259
        if ( !method_exists($object, $this->value) )
2260
        {
2261
            $message = sprintf(
2262
                $message ?: 'Expected "%s" does not a exist in provided object.',
2263
                $this->stringify($this->value)
2264
            );
2265
            throw $this->createException($message, self::INVALID_METHOD, $propertyPath);
2266
        }
2267
        return $this;
2268
    }
2269
2270
    /**
2271
     * Determines that the provided value is an object.