public function Watchdog::rewrite in Drupal 7 to 8/9 Module Upgrader 8
Tries to rewrite the original function call.
Parameters
\Pharborist\Functions\FunctionCallNode $call: The original function call.
\Drupal\drupalmoduleupgrader\TargetInterface $target: The target module.
Return value
\Pharborist\Node|null If the original function call is returned (determined by object identity), the function call is not replaced. If a different node is returned, it will replace the original call. And if nothing is returned, the original call is commented out with a FIXME.
Overrides FunctionCallModifier::rewrite
File
- src/
Plugin/ DMU/ Converter/ Functions/ Watchdog.php, line 33
Class
- Watchdog
- Plugin annotation @Converter( id = "watchdog", description = @Translation("Converts calls to watchdog() to \Drupal::logger().") )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\FunctionsCode
public function rewrite(FunctionCallNode $call, TargetInterface $target) {
$arguments = $call
->getArguments();
// We'll call a specific method on the logger object, depending on the
// severity passed in the original function call (if any). If there are
// at least four arguments, a severity was passed. We check $arguments[3]
// to ensure it's a valid severity constant, and if it's not, we default
// to the notice() severity.
//
// @TODO Leave a FIXME for an invalid severity, since changing it to a
// notice alters the intent of the original code.
//
if (sizeof($arguments) > 3 && $arguments[3] instanceof ConstantNode && in_array($arguments[3]
->getConstantName()
->getText(), static::$severityConstants)) {
$method = strtolower(substr($arguments[3], 9));
}
else {
$method = 'notice';
}
// If there is a third argument, and it's an array, a context array
// was passed.
$context = sizeof($arguments) > 2 && $arguments[2] instanceof ArrayNode ? clone $arguments[2] : ArrayNode::create([]);
return ClassMethodCallNode::create('\\Drupal', 'logger')
->appendArgument(clone $arguments[0])
->appendMethodCall($method)
->appendArgument(clone $arguments[1])
->appendArgument($context);
}