Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / HookPermission.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Analyzer/HookPermission.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Analyzer/HookPermission.php
new file mode 100644 (file)
index 0000000..c012587
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
+
+use Drupal\drupalmoduleupgrader\AnalyzerBase;
+use Drupal\drupalmoduleupgrader\TargetInterface;
+
+/**
+ * @Analyzer(
+ *  id = "hook_permission",
+ *  description = @Translation("Analyzes implementations of hook_permission()."),
+ *  documentation = {
+ *    {
+ *      "url" = "https://www.drupal.org/node/2311427",
+ *      "title" = @Translation("Defining permissions in `MODULE.permissions.yml`")
+ *    }
+ *  },
+ *  tags = {
+ *    "category" = { "system", "user" },
+ *    "error_level" = "warning"
+ *  },
+ *  hook = "hook_permission",
+ *  message = @Translation("Static permissions are now defined in `MODULE.permissions.yml`.")
+ * )
+ */
+class HookPermission extends AnalyzerBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function analyze(TargetInterface $target) {
+    $issues = [];
+    $indexer = $target->getIndexer('function');
+
+    if ($indexer->hasExecutable('hook_permission')) {
+      $issues[] = $this
+        ->buildIssue($target)
+        ->addViolation($indexer->get('hook_permission'), $this)
+        ->addFix('hook_to_YAML', [
+          'hook' => 'permission',
+          'destination' => '~/' . $target->id() . '.permissions.yml',
+        ]);
+    }
+
+    return $issues;
+  }
+
+}