Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / CommentLoad.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
4
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Objects\ClassMethodCallNode;
8
9 /**
10  * @Converter(
11  *  id = "comment_load",
12  *  description = @Translation("Rewrites calls to comment_load()."),
13  *  fixme = @Translation("comment_load() is now EntityStorageInterface::load().")
14  * )
15  */
16 class CommentLoad extends FunctionCallModifier {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function rewrite(FunctionCallNode $call, TargetInterface $target) {
22     $arguments = $call->getArguments();
23
24     // If there were three arguments, the call is affecting the internal
25     // comment_load() cache. Unfortunately, it's pretty much impossible to
26     // reliably determine whether or not they wanted to reset the cache,
27     // so let's just leave a FIXME.
28     if (sizeof($arguments) == 2) {
29       $this->buildFixMe('To reset the comment cache, use EntityStorageInterface::resetCache().')->insertBefore($call);
30     }
31
32     return ClassMethodCallNode::create('\Drupal', 'entityManager')
33       ->appendMethodCall('getStorage')
34       ->appendArgument('comment')
35       ->appendMethodCall('load')
36       ->appendArgument(clone $arguments[0]);
37   }
38
39 }