PhpStormMetadata - Define registerArgumentsSet() and addExpectedArguments()
authorTim Otten <totten@civicrm.org>
Sat, 26 Aug 2023 00:41:58 +0000 (17:41 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 26 Aug 2023 02:02:19 +0000 (19:02 -0700)
tools/extensions/phpstorm/Civi/PhpStorm/PhpStormMetadata.php

index 854e8643eff0eae7f9a5c8b192d56b6b985ff8a5..260f0ebd2e4d182a9938462c43adc2841bffff1b 100644 (file)
@@ -44,6 +44,30 @@ class PhpStormMetadata {
     $this->buffer = '';
   }
 
+  public function registerArgumentsSet(string $name, ...$args) {
+    $escapedName = var_export($name, 1);
+    $escapedArgs = implode(', ', array_map(function($arg) {
+      return var_export($arg, 1);
+    }, $args));
+    $this->buffer .= "registerArgumentsSet($escapedName, $escapedArgs);\n";
+    return $this;
+  }
+
+  /**
+   * @param string $for
+   *   Ex: '\Civi\Core\SettingsBag::get()'
+   * @param int $index
+   *   The positional offset among the arguments
+   * @param string $argumentSet
+   *   Name of the argument set. (This should already be defined by `registerArgumentsSet()`.)
+   * @return $this
+   */
+  public function addExpectedArguments(string $for, int $index, string $argumentSet) {
+    $escapedSet = var_export($argumentSet, 1);
+    $this->buffer .= "expectedArguments($for, $index, argumentsSet($escapedSet));\n";
+    return $this;
+  }
+
   /**
    * @param string $for
    * @param array $map