Skip to content

Commit 1bc3bbb

Browse files
authored
Merge pull request #841 from kukulich/mutants
Improved mutation score
2 parents c47f5bc + bf0d62e commit 1bc3bbb

26 files changed

+633
-378
lines changed

src/NodeCompiler/CompileNodeToValue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class CompileNodeToValue
2727
{
28+
private const TRUE_FALSE_NULL = ['true', 'false', 'null'];
29+
2830
/**
2931
* Compile an expression from a node into a value.
3032
*
@@ -42,7 +44,7 @@ public function __invoke(Node $node, CompilerContext $context): CompiledValue
4244

4345
if (
4446
$node instanceof Node\Expr\ConstFetch
45-
&& ! in_array($node->name->toLowerString(), ['true', 'false', 'null'], true)
47+
&& ! in_array($node->name->toLowerString(), self::TRUE_FALSE_NULL, true)
4648
) {
4749
$constantName = $this->resolveConstantName($node, $context);
4850
} elseif ($node instanceof Node\Expr\ClassConstFetch) {

src/Reflection/Adapter/ReflectionClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ public function getExtension(): ?CoreReflectionExtension
468468
throw new Exception\NotImplemented('Not implemented');
469469
}
470470

471-
public function getExtensionName(): string
471+
public function getExtensionName(): string|false
472472
{
473-
return $this->betterReflectionClass->getExtensionName() ?? '';
473+
return $this->betterReflectionClass->getExtensionName() ?? false;
474474
}
475475

476476
public function inNamespace(): bool

src/Reflection/Adapter/ReflectionEnum.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ public function getTraits(): array
269269
{
270270
$traits = $this->betterReflectionEnum->getTraits();
271271

272-
/**
273-
* @psalm-var array<trait-string> $traitNames
274-
* @phpstan-var array<class-string> $traitNames
275-
*/
272+
/** @var array<trait-string> $traitNames */
276273
$traitNames = array_map(static fn (BetterReflectionClass $trait): string => $trait->getName(), $traits);
277274

278275
return array_combine(
@@ -419,9 +416,9 @@ public function getExtension(): ?CoreReflectionExtension
419416
throw new Exception\NotImplemented('Not implemented');
420417
}
421418

422-
public function getExtensionName(): string
419+
public function getExtensionName(): string|false
423420
{
424-
return $this->betterReflectionEnum->getExtensionName() ?? '';
421+
return $this->betterReflectionEnum->getExtensionName() ?? false;
425422
}
426423

427424
public function inNamespace(): bool

src/Reflection/Adapter/ReflectionFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function invoke(mixed ...$args): mixed
183183
try {
184184
return $this->betterReflectionFunction->invoke(...func_get_args());
185185
} catch (Throwable $e) {
186-
throw new CoreReflectionException($e->getMessage(), 0, $e);
186+
throw new CoreReflectionException($e->getMessage(), previous: $e);
187187
}
188188
}
189189

@@ -195,7 +195,7 @@ public function invokeArgs(array $args): mixed
195195
try {
196196
return $this->betterReflectionFunction->invokeArgs($args);
197197
} catch (Throwable $e) {
198-
throw new CoreReflectionException($e->getMessage(), 0, $e);
198+
throw new CoreReflectionException($e->getMessage(), previous: $e);
199199
}
200200
}
201201

src/Reflection/Adapter/ReflectionMethod.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ public function getClosure(?object $object = null): Closure
226226
try {
227227
return $this->betterReflectionMethod->getClosure($object);
228228
} catch (NoObjectProvided $e) {
229-
throw new ValueError($e->getMessage(), 0, $e);
229+
throw new ValueError($e->getMessage(), previous: $e);
230230
} catch (Throwable $e) {
231-
throw new CoreReflectionException($e->getMessage(), 0, $e);
231+
throw new CoreReflectionException($e->getMessage(), previous: $e);
232232
}
233233
}
234234

@@ -248,7 +248,7 @@ public function invoke(?object $object = null, mixed ...$args): mixed
248248
} catch (NoObjectProvided | TypeError) {
249249
return null;
250250
} catch (Throwable $e) {
251-
throw new CoreReflectionException($e->getMessage(), 0, $e);
251+
throw new CoreReflectionException($e->getMessage(), previous: $e);
252252
}
253253
}
254254

@@ -266,7 +266,7 @@ public function invokeArgs(?object $object = null, array $args = []): mixed
266266
} catch (NoObjectProvided | TypeError) {
267267
return null;
268268
} catch (Throwable $e) {
269-
throw new CoreReflectionException($e->getMessage(), 0, $e);
269+
throw new CoreReflectionException($e->getMessage(), previous: $e);
270270
}
271271
}
272272

src/Reflection/Adapter/ReflectionProperty.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getValue(?object $object = null): mixed
4747
} catch (NoObjectProvided | TypeError) {
4848
return null;
4949
} catch (Throwable $e) {
50-
throw new CoreReflectionException($e->getMessage(), 0, $e);
50+
throw new CoreReflectionException($e->getMessage(), previous: $e);
5151
}
5252
}
5353

@@ -65,7 +65,7 @@ public function setValue(mixed $object, mixed $value = null): void
6565
} catch (NoObjectProvided | NotAnObject) {
6666
return;
6767
} catch (Throwable $e) {
68-
throw new CoreReflectionException($e->getMessage(), 0, $e);
68+
throw new CoreReflectionException($e->getMessage(), previous: $e);
6969
}
7070
}
7171

@@ -148,7 +148,7 @@ public function isInitialized(?object $object = null): bool
148148
try {
149149
return $this->betterReflectionProperty->isInitialized($object);
150150
} catch (Throwable $e) {
151-
throw new CoreReflectionException($e->getMessage(), 0, $e);
151+
throw new CoreReflectionException($e->getMessage(), previous: $e);
152152
}
153153
}
154154

src/Reflection/ReflectionClass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
244244
$methodHash = $this->methodHash($method->getImplementingClass()->getName(), $method->getName());
245245

246246
if (array_key_exists($methodHash, $traitModifiers)) {
247-
$methodAst = clone $methodAst;
248247
$methodAst->flags = ($methodAst->flags & ~ Node\Stmt\Class_::VISIBILITY_MODIFIER_MASK) | $traitModifiers[$methodHash];
249248
}
250249

@@ -543,7 +542,7 @@ public function getMethod(string $methodName): ReflectionMethod
543542
$methods = $this->getMethodsIndexedByName();
544543

545544
if (! isset($methods[$lowercaseMethodName])) {
546-
throw new OutOfBoundsException('Could not find method: ' . $methodName);
545+
throw new OutOfBoundsException(sprintf('Could not find method: %s', $methodName));
547546
}
548547

549548
return $methods[$lowercaseMethodName];

src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,15 @@ private function isSupportedInPhpVersion(Node\Stmt\ClassLike|Node\Stmt\Function_
629629

630630
$docComment = $node->getDocComment();
631631
if ($docComment !== null) {
632-
if (preg_match('~@since\s+(\d+\.\d+(?:\.\d+)?)~', $docComment->getText(), $sinceMatches) === 1) {
632+
if (preg_match('~@since\s+(\d+\.\d+(?:\.\d+)?)\s+~', $docComment->getText(), $sinceMatches) === 1) {
633633
$sincePhpVersion = $this->parsePhpVersion($sinceMatches[1]);
634634

635635
if ($sincePhpVersion > $this->phpVersion) {
636636
return false;
637637
}
638638
}
639639

640-
if (preg_match('~@removed\s+(\d+\.\d+(?:\.\d+)?)~', $docComment->getText(), $removedMatches) === 1) {
640+
if (preg_match('~@removed\s+(\d+\.\d+(?:\.\d+)?)\s+~', $docComment->getText(), $removedMatches) === 1) {
641641
$removedPhpVersion = $this->parsePhpVersion($removedMatches[1]);
642642

643643
if ($removedPhpVersion <= $this->phpVersion) {

src/SourceLocator/SourceStubber/ReflectionSourceStubber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private function addDocComment(
211211
}
212212

213213
if (method_exists($reflection, 'hasTentativeReturnType') && $reflection->hasTentativeReturnType()) {
214-
$annotations[] = '@' . AnnotationHelper::TENTATIVE_RETURN_TYPE_ANNOTATION;
214+
$annotations[] = sprintf('@%s', AnnotationHelper::TENTATIVE_RETURN_TYPE_ANNOTATION);
215215
}
216216
}
217217

src/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use LogicException;
88

9+
use function sprintf;
910
use function stat;
1011
use function stream_wrapper_register;
1112
use function stream_wrapper_restore;
@@ -117,7 +118,7 @@ public function stream_open($path, $mode, $options, &$opened_path): bool
117118
public function url_stat($path, $flags): array|bool
118119
{
119120
if (self::$registeredStreamWrapperProtocols === null) {
120-
throw new LogicException(self::class . ' not registered: cannot operate. Do not call this method directly.');
121+
throw new LogicException(sprintf('%s not registered: cannot operate. Do not call this method directly.', self::class));
121122
}
122123

123124
foreach (self::$registeredStreamWrapperProtocols as $protocol) {

0 commit comments

Comments
 (0)