Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private function isSmallerOrGreater(array $condExprs, string $keyValueName, stri
private function useForeachVariableInStmts(Expr $expr, array $stmts): void
{
if ($this->keyValueName === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->traverseNodesWithCallable($stmts, function (Node $node) use ($expr): ?Expr {
Expand Down
2 changes: 1 addition & 1 deletion packages/CodingStyle/src/Naming/ClassNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getShortName($name): string
if ($name instanceof Name) {
$name = $this->nameResolver->getName($name);
if ($name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private function transformArrayToYieldsOnMethodNode(ClassMethod $classMethod, Ar
// remove whole return node
$parentNode = $arrayNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->removeNode($parentNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function resolveUsedNames(Node $searchNode): void

$parentNode = $nameNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->resolvedNodeNames[$originalName->toString()][] = [$nameNode, $parentNode];
Expand Down
2 changes: 1 addition & 1 deletion packages/DeadCode/src/Data/VariableNodeUseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getParentNode(): Node
{
$parentNode = $this->variable->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return $parentNode;
Expand Down
4 changes: 2 additions & 2 deletions packages/DeadCode/src/Doctrine/DoctrineEntityManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function resolveTargetClass(Property $property): ?string

$relationTag = $this->docBlockManipulator->getTagByName($property, $relationAnnotation);
if (! $relationTag->value instanceof GenericTagValueNode) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$match = Strings::match($relationTag->value->value, self::TARGET_ENTITY_PATTERN);
Expand Down Expand Up @@ -118,7 +118,7 @@ public function resolveOtherProperty(Property $property): ?string

$relationTag = $this->docBlockManipulator->getTagByName($property, $relationAnnotation);
if (! $relationTag->value instanceof GenericTagValueNode) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$match = Strings::match($relationTag->value->value, self::TARGET_PROPERTY_PATTERN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function refactor(Node $node): ?Node
return new MethodCall($propertyFetchNode, $service['non_array_method'], $node->args);
}

throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function processMysqlFetchField(Assign $assign, FuncCall $funcCall): Ass

$previousExpression = $assign->getAttribute(AttributeKey::PREVIOUS_EXPRESSION);
if ($previousExpression === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->addNodeAfterNode($forNode, $previousExpression);
Expand Down
2 changes: 1 addition & 1 deletion packages/NodeTypeResolver/src/ComplexNodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function resolvePropertyTypeInfo(Property $property): ?VarTypeInfo

$classNode = $property->getAttribute(AttributeKey::CLASS_NODE);
if (! $classNode instanceof Class_) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$propertyName = $this->nameResolver->getName($property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private function resolveClassName(ClassLike $classOrInterfaceNode): string
}

if ($classOrInterfaceNode->name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return $classOrInterfaceNode->name->toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function resolveFullyQualifiedName(Node $nameNode, string $name): string
/** @var string|null $class */
$class = $nameNode->getAttribute(AttributeKey::CLASS_NAME);
if ($class === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return $class;
Expand All @@ -59,7 +59,7 @@ private function resolveFullyQualifiedName(Node $nameNode, string $name): string
/** @var string|null $class */
$class = $nameNode->getAttribute(AttributeKey::PARENT_CLASS_NAME);
if ($class === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return $class;
Expand Down
2 changes: 1 addition & 1 deletion packages/NodeTypeResolver/src/Php/AbstractTypeInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getTypeNode(bool $forceFqn = false)

$type = $this->resolveTypeForTypehint($forceFqn);
if ($type === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

// normalize for type-declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function processMysqlFetchField(Assign $assign, FuncCall $funcCall): Ass

$previousExpression = $assign->getAttribute(AttributeKey::PREVIOUS_EXPRESSION);
if ($previousExpression === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->addNodeAfterNode($forNode, $previousExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function refactor(Node $node): ?Node
// load the file!
$fileInfo = $node->getAttribute(AttributeKey::FILE_INFO);
if ($fileInfo === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->undefinedConstants = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function createAnonymousFunctionFromString(Expr $expr): ?Closure
{
if (! $expr instanceof String_) {
// not supported yet
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$phpCode = '<?php ' . $expr->value . ';';
Expand Down
4 changes: 2 additions & 2 deletions packages/PhpSpecToPHPUnit/src/Naming/PhpSpecRenaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function renameClass(Class_ $class): void
{
// anonymous class?
if ($class->name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

// 2. change class name
Expand All @@ -94,7 +94,7 @@ public function resolveObjectPropertyName(Class_ $class): string
{
// anonymous class?
if ($class->name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$bareClassName = RectorStrings::removeSuffixes($class->name->toString(), ['Spec', 'Test']);
Expand Down
4 changes: 2 additions & 2 deletions packages/PhpSpecToPHPUnit/src/PhpSpecMockCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getTypeForClassAndVariable(Class_ $node, string $variable): stri
$className = $this->nameResolver->getName($node);

if (! isset($this->mocksWithsTypes[$className][$variable])) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return $this->mocksWithsTypes[$className][$variable];
Expand All @@ -112,7 +112,7 @@ private function addMockFromParam(Param $param): void
$this->mocks[$class][$variable][] = $param->getAttribute(AttributeKey::METHOD_NAME);

if ($param->type === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$paramType = (string) ($param->type->getAttribute('originalName') ?: $param->type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function createMockVarDoc(Param $param, Name $name): string
$variableName = $this->getName($param->var);

if ($variableName === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

return sprintf(
Expand All @@ -127,7 +127,7 @@ private function processMethodParamsToMocks(ClassMethod $classMethod): void
$assigns = [];
foreach ((array) $classMethod->params as $param) {
if (! $param->type instanceof Name) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$createMockCall = $this->createCreateMockCall($param, $param->type);
Expand All @@ -146,12 +146,12 @@ private function processMethodCall(MethodCall $methodCall): ?MethodCall
{
if ($this->isName($methodCall, 'shouldBeCalled')) {
if (! $methodCall->var instanceof MethodCall) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$mockMethodName = $this->getName($methodCall->var);
if ($mockMethodName === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$expectedArg = $methodCall->var->args[0]->value ?? null;
Expand Down Expand Up @@ -218,7 +218,7 @@ private function createPropertyFetchMockVariableAssign(Param $param, Name $name)
{
$variable = $this->getName($param->var);
if ($variable === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$propertyFetch = new PropertyFetch(new Variable('this'), $variable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private function prepare(Node $node): void
private function processDuring(MethodCall $methodCall): MethodCall
{
if (! isset($methodCall->args[0])) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$name = $this->getValue($methodCall->args[0]->value);
Expand Down
4 changes: 2 additions & 2 deletions packages/RemovingStatic/src/Printer/FactoryClassPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ private function createFactoryClassFilePath(Class_ $oldClass): string
/** @var SmartFileInfo|null $classFileInfo */
$classFileInfo = $oldClass->getAttribute(AttributeKey::FILE_INFO);
if ($classFileInfo === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$directoryPath = Strings::before($classFileInfo->getRealPath(), DIRECTORY_SEPARATOR, -1);
$resolvedOldClass = $this->nameResolver->getName($oldClass);
if ($resolvedOldClass === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$bareClassName = Strings::after($resolvedOldClass, '\\', -1) . 'Factory.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private function resolveClassesUsingTypes(): array
if ($hasTypes) {
$name = $this->getName($class);
if ($name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}
$this->classesUsingTypes[] = $name;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/RemovingStatic/src/UniqueObjectFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function createFactoryClass(Class_ $class, array $staticTypesInClass): Cl
$factoryClassBuilder->addStmt($constructMethod);

if ($className === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

// create
Expand Down
6 changes: 3 additions & 3 deletions packages/Sensio/src/Helper/TemplateGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public function resolveFromClassMethodNode(ClassMethod $classMethod, int $versio
{
$namespace = $classMethod->getAttribute(AttributeKey::NAMESPACE_NAME);
if (! is_string($namespace)) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$class = $classMethod->getAttribute(AttributeKey::CLASS_NAME);
if (! is_string($class)) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$method = $this->nameResolver->getName($classMethod);
if ($method === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

if ($version === 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function processMethodCallNode(MethodCall $methodCall): ?Node
$propertyName = $this->propertyNaming->fqnToVariableName($serviceType);
$classNode = $methodCall->getAttribute(AttributeKey::CLASS_NODE);
if (! $classNode instanceof Class_) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->addPropertyToClass($classNode, $serviceType, $propertyName);
Expand Down
2 changes: 1 addition & 1 deletion packages/Symfony/src/Rector/Yaml/ParseFileRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private function isArgumentYamlFile(StaticCall $staticCall): bool
// try to detect current value
$nodeScope = $possibleFileNode->getAttribute(AttributeKey::SCOPE);
if ($nodeScope === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$nodeType = $nodeScope->getType($possibleFileNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function create(array $types, Param $param): AttributeAwarePhpDocTagNode
} elseif (count($types) === 1) {
$typeNode = new IdentifierTypeNode($types[0]);
} else {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$arrayTypeNode = new ArrayTypeNode($typeNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function resolveChildType(
if ($nakedType->toString() === 'self') {
$className = $node->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$type = new FullyQualified($className);
Expand All @@ -195,7 +195,7 @@ protected function resolveChildType(
if ($nakedType->toString() === 'parent') {
$parentClassName = $node->getAttribute(AttributeKey::PARENT_CLASS_NAME);
if ($parentClassName === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$type = new FullyQualified($parentClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ private function populateChildren(Node $node, ReturnTypeInfo $returnTypeInfo): v

$methodName = $this->getName($node);
if ($methodName === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$className = $node->getAttribute(AttributeKey::CLASS_NAME);
if (! is_string($className)) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$childrenClassLikes = $this->parsedNodesByType->findClassesAndInterfacesByType($className);
Expand Down
6 changes: 3 additions & 3 deletions src/NodeContainer/ParsedNodesByType.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function collect(Node $node): void
if ($node instanceof Interface_ || $node instanceof Trait_ || $node instanceof Function_) {
$name = $this->nameResolver->getName($node);
if ($name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$nodeClass = get_class($node);
Expand Down Expand Up @@ -465,7 +465,7 @@ private function addClass(Class_ $classNode): void

$name = $classNode->getAttribute(AttributeKey::CLASS_NAME);
if ($name === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$this->classes[$name] = $classNode;
Expand All @@ -475,7 +475,7 @@ private function addClassConstant(ClassConst $classConst): void
{
$className = $classConst->getAttribute(AttributeKey::CLASS_NAME);
if ($className === null) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

$constantName = $this->nameResolver->getName($classConst);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Node/Commander/NodeAddingCommander.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function resolveNearestExpressionPosition(Node $node): string
if ($parentNode instanceof ClassLike) {
$foundNode = $node;
} else {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/Node/Manipulator/BinaryOpManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function validateCondition($firstCondition): void
return;
}

throw new ShouldNotHappenException();
throw new ShouldNotHappenException(__METHOD__ . '() on line ' . __LINE__);
}

/**
Expand Down
Loading