Watchdog.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Functions/Watchdog.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Pharborist\Constants\ConstantNode;
use Pharborist\Functions\FunctionCallNode;
use Pharborist\Objects\ClassMethodCallNode;
use Pharborist\Types\ArrayNode;
class Watchdog extends FunctionCallModifier {
protected static $severityConstants = [
'WATCHDOG_EMERGENCY',
'WATCHDOG_ALERT',
'WATCHDOG_CRITICAL',
'WATCHDOG_ERROR',
'WATCHDOG_WARNING',
'WATCHDOG_NOTICE',
'WATCHDOG_INFO',
'WATCHDOG_DEBUG',
];
public function rewrite(FunctionCallNode $call, TargetInterface $target) {
$arguments = $call
->getArguments();
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';
}
$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);
}
}
Classes
Name |
Description |
Watchdog |
Plugin annotation
@Converter(
id = "watchdog",
description = @Translation("Converts calls to watchdog() to \Drupal::logger().")
) |