mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 01:37:21 +01:00
Migrates to Pint
This commit is contained in:
@ -12,7 +12,7 @@ final class Arr
|
||||
/**
|
||||
* Checks if the given array has the given key.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function has(array $array, string|int $key): bool
|
||||
{
|
||||
@ -36,7 +36,7 @@ final class Arr
|
||||
/**
|
||||
* Gets the given key value.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @param array<array-key, mixed> $array
|
||||
*/
|
||||
public static function get(array $array, string|int $key, mixed $default = null): mixed
|
||||
{
|
||||
@ -46,7 +46,7 @@ final class Arr
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
if (!str_contains($key, '.')) {
|
||||
if (! str_contains($key, '.')) {
|
||||
return $array[$key] ?? $default;
|
||||
}
|
||||
|
||||
@ -64,8 +64,7 @@ final class Arr
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
*
|
||||
* @param array<array-key, mixed> $array
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public static function dot(array $array, string $prepend = ''): array
|
||||
@ -74,9 +73,9 @@ final class Arr
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && count($value) > 0) {
|
||||
$results = array_merge($results, static::dot($value, $prepend . $key . '.'));
|
||||
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
|
||||
} else {
|
||||
$results[$prepend . $value] = $value;
|
||||
$results[$prepend.$value] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ final class ChainableClosure
|
||||
public static function from(Closure $closure, Closure $next): Closure
|
||||
{
|
||||
return function () use ($closure, $next): void {
|
||||
if (!is_object($this)) { // @phpstan-ignore-line
|
||||
if (! is_object($this)) { // @phpstan-ignore-line
|
||||
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
|
||||
}
|
||||
|
||||
|
||||
@ -35,13 +35,12 @@ final class Container
|
||||
/**
|
||||
* Gets a dependency from the container.
|
||||
*
|
||||
* @param class-string $id
|
||||
*
|
||||
* @param class-string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
if (!array_key_exists($id, $this->instances)) {
|
||||
if (! array_key_exists($id, $this->instances)) {
|
||||
$this->instances[$id] = $this->build($id);
|
||||
}
|
||||
|
||||
@ -51,7 +50,7 @@ final class Container
|
||||
/**
|
||||
* Adds the given instance to the container.
|
||||
*
|
||||
* @param mixed $instance
|
||||
* @param mixed $instance
|
||||
*/
|
||||
public function add(string $id, $instance): void
|
||||
{
|
||||
@ -61,7 +60,7 @@ final class Container
|
||||
/**
|
||||
* Tries to build the given instance.
|
||||
*
|
||||
* @param class-string $id
|
||||
* @param class-string $id
|
||||
*/
|
||||
private function build(string $id): object
|
||||
{
|
||||
|
||||
@ -11,7 +11,6 @@ use SebastianBergmann\CodeCoverage\Node\File;
|
||||
use SebastianBergmann\Environment\Runtime;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
|
||||
use function Termwind\render;
|
||||
use function Termwind\renderUsing;
|
||||
|
||||
@ -54,7 +53,7 @@ final class Coverage
|
||||
*/
|
||||
public static function report(OutputInterface $output): float
|
||||
{
|
||||
if (!file_exists($reportPath = self::getPath())) {
|
||||
if (! file_exists($reportPath = self::getPath())) {
|
||||
if (self::usingXdebug()) {
|
||||
$output->writeln(
|
||||
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
|
||||
@ -80,10 +79,10 @@ final class Coverage
|
||||
$report = $codeCoverage->getReport();
|
||||
|
||||
foreach ($report->getIterator() as $file) {
|
||||
if (!$file instanceof File) {
|
||||
if (! $file instanceof File) {
|
||||
continue;
|
||||
}
|
||||
$dirname = dirname($file->id());
|
||||
$dirname = dirname($file->id());
|
||||
$basename = basename($file->id(), '.php');
|
||||
|
||||
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
|
||||
@ -106,7 +105,7 @@ final class Coverage
|
||||
? '100.0'
|
||||
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');
|
||||
|
||||
$takenSize = strlen($rawName . $percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
$takenSize = strlen($rawName.$percentage) + 2 + $linesExecutedTakenSize; // adding 3 space and percent sign
|
||||
|
||||
$percentage = sprintf(
|
||||
'<fg=%s>%s</>',
|
||||
@ -146,8 +145,7 @@ final class Coverage
|
||||
* ['11', '20..25', '50', '60..80'];
|
||||
* ```
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @param File $file
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getMissingCoverage($file): array
|
||||
@ -162,7 +160,7 @@ final class Coverage
|
||||
}
|
||||
|
||||
if ($shouldBeNewLine) {
|
||||
$array[] = (string) $line;
|
||||
$array[] = (string) $line;
|
||||
$shouldBeNewLine = false;
|
||||
|
||||
return $array;
|
||||
@ -171,7 +169,7 @@ final class Coverage
|
||||
$lastKey = count($array) - 1;
|
||||
|
||||
if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) {
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
[$from] = explode('..', $array[$lastKey]);
|
||||
$array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from);
|
||||
|
||||
return $array;
|
||||
|
||||
@ -44,7 +44,7 @@ final class ExceptionTrace
|
||||
*/
|
||||
public static function removePestReferences(Throwable $t): void
|
||||
{
|
||||
if (!property_exists($t, 'serializableTrace')) {
|
||||
if (! property_exists($t, 'serializableTrace')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ final class ExpectationPipeline
|
||||
/**
|
||||
* Sets the list of pipes.
|
||||
*
|
||||
* @param array<int, Closure> $pipes
|
||||
* @param array<int, Closure> $pipes
|
||||
*/
|
||||
public function through(array $pipes): self
|
||||
{
|
||||
|
||||
@ -26,7 +26,6 @@ final class HigherOrderCallables
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param (Closure():TValue)|TValue $value
|
||||
*
|
||||
* @return Expectation<TValue>
|
||||
*/
|
||||
public function expect(mixed $value): Expectation
|
||||
@ -42,8 +41,7 @@ final class HigherOrderCallables
|
||||
*
|
||||
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
|
||||
*
|
||||
* @param callable|TValue $value
|
||||
*
|
||||
* @param callable|TValue $value
|
||||
* @return Expectation<(callable(): mixed)|TValue>
|
||||
*/
|
||||
public function and(mixed $value)
|
||||
|
||||
@ -25,7 +25,7 @@ final class HigherOrderMessage
|
||||
/**
|
||||
* Creates a new higher order message.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @param array<int, mixed> $arguments
|
||||
*/
|
||||
public function __construct(
|
||||
public string $filename,
|
||||
@ -41,7 +41,7 @@ final class HigherOrderMessage
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $target
|
||||
* @param TValue $target
|
||||
*/
|
||||
public function call(object $target): mixed
|
||||
{
|
||||
@ -77,7 +77,7 @@ final class HigherOrderMessage
|
||||
/**
|
||||
* Indicates that this message should only be called when the given condition is true.
|
||||
*
|
||||
* @param callable(): bool $condition
|
||||
* @param callable(): bool $condition
|
||||
*/
|
||||
public function when(callable $condition): self
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Adds a new higher order message to the collection.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function add(string $filename, int $line, string $name, ?array $arguments): void
|
||||
{
|
||||
@ -27,7 +27,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Adds a new higher order message to the collection if the callable condition is does not return false.
|
||||
*
|
||||
* @param array<int, mixed>|null $arguments
|
||||
* @param array<int, mixed>|null $arguments
|
||||
*/
|
||||
public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void
|
||||
{
|
||||
@ -58,7 +58,7 @@ final class HigherOrderMessageCollection
|
||||
/**
|
||||
* Count the number of messages with the given name.
|
||||
*
|
||||
* @param string $name A higher order message name (usually a method name)
|
||||
* @param string $name A higher order message name (usually a method name)
|
||||
*/
|
||||
public function count(string $name): int
|
||||
{
|
||||
|
||||
@ -27,7 +27,7 @@ final class HigherOrderTapProxy
|
||||
/**
|
||||
* Dynamically sets properties on the target.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set(string $property, $value): void
|
||||
{
|
||||
@ -60,14 +60,13 @@ final class HigherOrderTapProxy
|
||||
/**
|
||||
* Dynamically pass method calls to the target.
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
*
|
||||
* @param array<int, mixed> $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $methodName, array $arguments)
|
||||
{
|
||||
$filename = Backtrace::file();
|
||||
$line = Backtrace::line();
|
||||
$line = Backtrace::line();
|
||||
|
||||
return (new HigherOrderMessage($filename, $line, $methodName, $arguments))
|
||||
->call($this->target);
|
||||
|
||||
@ -33,7 +33,7 @@ abstract class Printer implements \PHPUnit\Util\Printer
|
||||
|
||||
$this->isPhpStream = str_starts_with($out, 'php://');
|
||||
|
||||
if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) {
|
||||
if (! $this->isPhpStream && ! Filesystem::createDirectory(dirname($out))) {
|
||||
throw new Exception(sprintf('Directory "%s" was not created', dirname($out)));
|
||||
}
|
||||
|
||||
|
||||
@ -22,8 +22,7 @@ final class Reflection
|
||||
/**
|
||||
* Calls the given method with args on the given object.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function call(object $object, string $method, array $args = [])
|
||||
@ -52,8 +51,7 @@ final class Reflection
|
||||
/**
|
||||
* Bind a callable to the TestCase and return the result.
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
*
|
||||
* @param array<int, mixed> $args
|
||||
* @return mixed
|
||||
*/
|
||||
public static function bindCallable(callable $callable, array $args = [])
|
||||
@ -104,7 +102,7 @@ final class Reflection
|
||||
} catch (ReflectionException $reflectionException) {
|
||||
$reflectionClass = $reflectionClass->getParentClass();
|
||||
|
||||
if (!$reflectionClass instanceof ReflectionClass) {
|
||||
if (! $reflectionClass instanceof ReflectionClass) {
|
||||
throw new ShouldNotHappen($reflectionException);
|
||||
}
|
||||
}
|
||||
@ -120,8 +118,8 @@ final class Reflection
|
||||
*
|
||||
* @template TValue of object
|
||||
*
|
||||
* @param TValue $object
|
||||
* @param mixed $value
|
||||
* @param TValue $object
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function setPropertyValue(object $object, string $property, $value): void
|
||||
{
|
||||
@ -137,7 +135,7 @@ final class Reflection
|
||||
} catch (ReflectionException $reflectionException) {
|
||||
$reflectionClass = $reflectionClass->getParentClass();
|
||||
|
||||
if (!$reflectionClass instanceof ReflectionClass) {
|
||||
if (! $reflectionClass instanceof ReflectionClass) {
|
||||
throw new ShouldNotHappen($reflectionException);
|
||||
}
|
||||
}
|
||||
@ -156,7 +154,7 @@ final class Reflection
|
||||
{
|
||||
$type = $parameter->getType();
|
||||
|
||||
if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -183,7 +181,7 @@ final class Reflection
|
||||
public static function getFunctionArguments(Closure $function): array
|
||||
{
|
||||
$parameters = (new ReflectionFunction($function))->getParameters();
|
||||
$arguments = [];
|
||||
$arguments = [];
|
||||
|
||||
foreach ($parameters as $parameter) {
|
||||
/** @var ReflectionNamedType|ReflectionUnionType|null $types */
|
||||
|
||||
@ -19,7 +19,7 @@ final class Str
|
||||
* Create a (unsecure & non-cryptographically safe) random alpha-numeric
|
||||
* string value.
|
||||
*
|
||||
* @param int $length the length of the resulting randomized string
|
||||
* @param int $length the length of the resulting randomized string
|
||||
*
|
||||
* @see https://github.com/laravel/framework/blob/4.2/src/Illuminate/Support/Str.php#L240-L242
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user