a19c2a1273e45eb2a3f0c4f1676e8a0750e7070e
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Fixer / FormCallbackToMethod.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\FormCallbackToMethod.
6  */
7
8 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer;
9
10 use Drupal\drupalmoduleupgrader\FixerBase;
11
12 /**
13  * @Fixer(
14  *  id = "form_callback_to_method"
15  * )
16  */
17 class FormCallbackToMethod extends FixerBase {
18
19   public function execute() {
20     /** @var \Pharborist\Functions\FunctionDeclarationNode $callback */
21     $callback = $this
22       ->target
23       ->getIndexer('function')
24       ->get($this->configuration['callback']);
25
26     list ($class, $method_name) = explode('::', $this->configuration['destination']);
27     /** @var \Pharborist\Objects\ClassNode $class */
28     $class = $this
29       ->target
30       ->getIndexer('class')
31       ->get($class);
32
33     $method = $callback->cloneAsMethodOf($class)->setName($method_name);
34
35     $form_interface = new \ReflectionClass('\Drupal\Core\Form\FormInterface');
36     if ($form_interface->hasMethod($method_name)) {
37       $method->matchReflector($form_interface->getMethod($method_name));
38     }
39
40     $this->target->save($method);
41   }
42
43 }