mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Add DatasetInfo support class
This commit is contained in:
38
src/Support/DatasetInfo.php
Normal file
38
src/Support/DatasetInfo.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class DatasetInfo
|
||||
{
|
||||
public const DATASETS_DIR_NAME = 'Datasets';
|
||||
|
||||
public const DATASETS_FILE_NAME = 'Datasets.php';
|
||||
|
||||
public static function isInsideADatasetsDirectory(string $file): bool
|
||||
{
|
||||
return basename(dirname($file)) === self::DATASETS_DIR_NAME;
|
||||
}
|
||||
|
||||
public static function isADatasetsFile(string $file): bool
|
||||
{
|
||||
return basename($file) === self::DATASETS_FILE_NAME;
|
||||
}
|
||||
|
||||
public static function scope(string $file): string
|
||||
{
|
||||
if (self::isInsideADatasetsDirectory($file)) {
|
||||
return dirname($file, 2);
|
||||
}
|
||||
|
||||
if (self::isADatasetsFile($file)) {
|
||||
return dirname($file);
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
@ -59,24 +59,6 @@ final class Str
|
||||
return (string) preg_replace('/[^A-Z_a-z0-9\\\\]/', '', $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the remainder of a string after the last occurrence of a given value.
|
||||
*/
|
||||
public static function afterLast(string $subject, string $search): string
|
||||
{
|
||||
if ($search === '') {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
$position = strrpos($subject, $search);
|
||||
|
||||
if ($position === false) {
|
||||
return $subject;
|
||||
}
|
||||
|
||||
return substr($subject, $position + strlen($search));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the portion of a string before the last occurrence of a given value.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user