Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / FunctionCallDeriver.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
4
5 use Drupal\Core\StringTranslation\TranslationInterface;
6 use Drupal\drupalmoduleupgrader\DeriverBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 class FunctionCallDeriver extends DeriverBase {
10
11   /**
12    * @var array
13    */
14   protected $config;
15
16   public function __construct(TranslationInterface $translator, array $config) {
17     parent::__construct($translator);
18     $this->config = $config;
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public static function create(ContainerInterface $container, $base_plugin_id) {
25     return new static(
26       $container->get('string_translation'),
27       $container->get('config.factory')->get('drupalmoduleupgrader.functions')->get('definitions')
28     );
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getDerivativeDefinitions($base_definition) {
35     $derivatives = [];
36
37     foreach ($this->config as $key => $info) {
38       // $key can either be the name of a single function, or an arbitrary string
39       // identifying a group of functions to handle.
40       if (empty($info['functions'])) {
41         $info['functions'] = [$key];
42       }
43
44       foreach ($info['functions'] as $function) {
45         $variables = ['@function' => $function . '()'];
46
47         $derivative = array_merge($base_definition, $info);
48         $derivative['function'] = $function;
49         $derivative['message'] = $this->t($derivative['message'], $variables);
50         $derivative['description'] = $this->t('Analyzes calls to @function.', $variables);
51         foreach ($derivative['documentation'] as &$doc) {
52           $doc['title'] = $this->t($doc['title'], $variables);
53         }
54         unset($derivative['functions']);
55
56         $derivatives[$function] = $derivative;
57       }
58     }
59
60     return $derivatives;
61   }
62
63 }