[NFC] Code cleanup - use use statements, hints
[civicrm-core.git] / CRM / Core / TokenTrait.php
index 26110155eff60f3b96140e65f0cd8087da1df0b5..e861915be46f31c9a2e8d090bb156d6f9177a576 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+use Civi\Token\Event\TokenValueEvent;
+use Civi\Token\TokenProcessor;
+
 trait CRM_Core_TokenTrait {
 
   private $basicTokens;
@@ -18,7 +21,7 @@ trait CRM_Core_TokenTrait {
   /**
    * @inheritDoc
    */
-  public function checkActive(\Civi\Token\TokenProcessor $processor) {
+  public function checkActive(TokenProcessor $processor) {
     return in_array($this->getEntityContextSchema(), $processor->context['schema']) ||
       (!empty($processor->context['actionMapping'])
         && $processor->context['actionMapping']->getEntity() === $this->getEntityTableName());
@@ -27,7 +30,7 @@ trait CRM_Core_TokenTrait {
   /**
    * @inheritDoc
    */
-  public function getActiveTokens(\Civi\Token\Event\TokenValueEvent $e) {
+  public function getActiveTokens(TokenValueEvent $e) {
     $messageTokens = $e->getTokenProcessor()->getMessageTokens();
     if (!isset($messageTokens[$this->entity])) {
       return NULL;
@@ -51,16 +54,18 @@ trait CRM_Core_TokenTrait {
 
   /**
    * Find the fields that we need to get to construct the tokens requested.
-   * @param  array $tokens list of tokens
+   * @param  array $activeTokens list of active tokens
    * @return array         list of fields needed to generate those tokens
    */
-  public function getReturnFields($tokens) {
+  public function getReturnFields($activeTokens) {
     // Make sure we always return something
     $fields = ['id'];
 
-    foreach (array_intersect($tokens,
+    $tokensInUse = array_intersect(
+      $activeTokens,
       array_merge(array_keys(self::getBasicTokens()), array_keys(self::getCustomFieldTokens()))
-             ) as $token) {
+    );
+    foreach ($tokensInUse as $token) {
       if (isset(self::$fieldMapping[$token])) {
         $fields = array_merge($fields, self::$fieldMapping[$token]);
       }
@@ -75,7 +80,7 @@ trait CRM_Core_TokenTrait {
    * Get the tokens for custom fields
    * @return array token name => token label
    */
-  protected function getCustomFieldTokens() {
+  protected function getCustomFieldTokens(): array {
     if (!isset($this->customFieldTokens)) {
       $this->customFieldTokens = \CRM_Utils_Token::getCustomFieldTokens(ucfirst($this->getEntityName()));
     }