-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate file/directory/exists assertions #291
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically incorrect, since return is_file($path) || is_dir($path); |
||
static::valueToString($value) | ||
)); | ||
} | ||
|
@@ -1444,8 +1442,6 @@ public static function fileExists($value, $message = '') | |
*/ | ||
public static function file($value, $message = '') | ||
{ | ||
static::fileExists($value, $message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pointless check. |
||
|
||
if (!\is_file($value)) { | ||
static::reportInvalidArgument(\sprintf( | ||
$message ?: 'The path %s is not a file.', | ||
|
@@ -1462,11 +1458,9 @@ public static function file($value, $message = '') | |
*/ | ||
public static function directory($value, $message = '') | ||
{ | ||
static::fileExists($value, $message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pointless check. If the directory does not exist, the next assertion will never run. If the directory does exist, then it duplicates work. |
||
|
||
if (!\is_dir($value)) { | ||
static::reportInvalidArgument(\sprintf( | ||
$message ?: 'The path %s is no directory.', | ||
$message ?: 'The path %s is not a directory.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made this message consistent with |
||
static::valueToString($value) | ||
)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see other assertions doing this, so I removed it.