Skip to content

Commit

Permalink
Separate file/directory/exists assertions
Browse files Browse the repository at this point in the history
There is no need to use `file_exists` before using `is_file` and `is_dir`, this makes for confusing errors.
  • Loading branch information
shadowhand authored Sep 21, 2023
1 parent 11cb219 commit fba1781
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,11 +1426,9 @@ public static function lengthBetween($value, $min, $max, $message = '')
*/
public static function fileExists($value, $message = '')
{
static::string($value);

if (!\file_exists($value)) {
static::reportInvalidArgument(\sprintf(
$message ?: 'The file %s does not exist.',
$message ?: 'The path %s does not exist.',
static::valueToString($value)
));
}
Expand All @@ -1444,8 +1442,6 @@ public static function fileExists($value, $message = '')
*/
public static function file($value, $message = '')
{
static::fileExists($value, $message);

if (!\is_file($value)) {
static::reportInvalidArgument(\sprintf(
$message ?: 'The path %s is not a file.',
Expand All @@ -1462,11 +1458,9 @@ public static function file($value, $message = '')
*/
public static function directory($value, $message = '')
{
static::fileExists($value, $message);

if (!\is_dir($value)) {
static::reportInvalidArgument(\sprintf(
$message ?: 'The path %s is no directory.',
$message ?: 'The path %s is not a directory.',
static::valueToString($value)
));
}
Expand Down

0 comments on commit fba1781

Please sign in to comment.