> */ public function getNodeTypes() : array { return [Ternary::class]; } /** * @param Ternary $node */ public function refactor(Node $node) : ?Node { if ($this->shouldSkip($node)) { return null; } if (!$this->areValuesIdentical($node)) { return null; } /** @var FuncCall|ClassConstFetch $getClassFuncCallOrClassConstFetchClass */ $getClassFuncCallOrClassConstFetchClass = $node->if; $firstExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->getArgs()[0]->value : $getClassFuncCallOrClassConstFetchClass->class; return $this->nodeFactory->createFuncCall('get_debug_type', [$firstExpr]); } private function shouldSkip(Ternary $ternary) : bool { if (!$ternary->cond instanceof FuncCall) { return \true; } if ($ternary->cond->isFirstClassCallable()) { return \true; } if (!isset($ternary->cond->getArgs()[0])) { return \true; } if (!$this->nodeNameResolver->isName($ternary->cond, 'is_object')) { return \true; } if (!$ternary->if instanceof FuncCall) { if (!$ternary->if instanceof ClassConstFetch) { return \true; } return $this->shouldSkipClassConstFetch($ternary->if); } if (!$this->nodeNameResolver->isName($ternary->if, 'get_class')) { return \true; } if (!$ternary->else instanceof FuncCall) { return \true; } if ($ternary->else->isFirstClassCallable()) { return \true; } return !$this->nodeNameResolver->isName($ternary->else, 'gettype'); } private function shouldSkipClassConstFetch(ClassConstFetch $classConstFetch) : bool { if (!$classConstFetch->name instanceof Identifier) { return \true; } return $classConstFetch->name->toString() !== 'class'; } private function areValuesIdentical(Ternary $ternary) : bool { /** @var FuncCall $isObjectFuncCall */ $isObjectFuncCall = $ternary->cond; if ($isObjectFuncCall->isFirstClassCallable()) { return \false; } $firstExpr = $isObjectFuncCall->getArgs()[0]->value; /** @var FuncCall|ClassConstFetch $getClassFuncCallOrClassConstFetchClass */ $getClassFuncCallOrClassConstFetchClass = $ternary->if; if ($getClassFuncCallOrClassConstFetchClass instanceof FuncCall && !$getClassFuncCallOrClassConstFetchClass->args[0] instanceof Arg) { return \false; } $secondExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->getArgs()[0]->value : $getClassFuncCallOrClassConstFetchClass->class; /** @var FuncCall $gettypeFuncCall */ $gettypeFuncCall = $ternary->else; if (!$gettypeFuncCall->args[0] instanceof Arg) { return \false; } $thirdExpr = $gettypeFuncCall->args[0]->value; if (!$this->nodeComparator->areNodesEqual($firstExpr, $secondExpr)) { return \false; } return $this->nodeComparator->areNodesEqual($firstExpr, $thirdExpr); } }