(NFC) Civi::pipe - Swap various quotes
authorTim Otten <totten@civicrm.org>
Fri, 14 Jan 2022 03:00:11 +0000 (19:00 -0800)
committerTim Otten <totten@civicrm.org>
Fri, 14 Jan 2022 03:00:11 +0000 (19:00 -0800)
These are just some double-quoted PHP strings that need double-quotes.

Civi/Pipe/BasicPipeClient.php
Civi/Pipe/JsonRpc.php
Civi/Pipe/JsonRpcMethodException.php
Civi/Pipe/LineSessionTrait.php
Civi/Pipe/PipeSession.php
Civi/Pipe/PublicMethods.php

index 8adbc99c12bb1223226ca2436dd9ce281320e793..0544db39852205bd8c2662560a19ed77cac0f22b 100644 (file)
@@ -81,7 +81,7 @@ class BasicPipeClient {
    */
   public function connect(string $command): array {
     if ($this->process) {
-      throw new \RuntimeException("Client error: Already connected");
+      throw new \RuntimeException('Client error: Already connected');
     }
 
     $desc = [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'a']];
@@ -92,7 +92,7 @@ class BasicPipeClient {
     $line = stream_get_line($this->pipes[1], $this->bufferSize, "\n");
     $this->welcome = json_decode($line, TRUE);
     if ($this->welcome === NULL || !isset($this->welcome['Civi::pipe'])) {
-      throw new \RuntimeException("Protocol error: Received malformed welcome");
+      throw new \RuntimeException('Protocol error: Received malformed welcome');
     }
     return $this->welcome['Civi::pipe'];
   }
@@ -114,7 +114,7 @@ class BasicPipeClient {
    */
   public function call(string $method, array $params, $id = NULL): array {
     if (!$this->process) {
-      throw new \RuntimeException("Client error: Connection was not been opened yet.");
+      throw new \RuntimeException('Client error: Connection was not been opened yet.');
     }
 
     $requestLine = json_encode(['jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $id]);
@@ -122,10 +122,10 @@ class BasicPipeClient {
     $responseLine = stream_get_line($this->pipes[1], $this->bufferSize, "\n");
     $decode = json_decode($responseLine, TRUE);
     if (!isset($decode['jsonrpc']) || $decode['jsonrpc'] !== '2.0') {
-      throw new \RuntimeException("Protocol error: Response lacks JSON-RPC header.");
+      throw new \RuntimeException('Protocol error: Response lacks JSON-RPC header.');
     }
     if (!array_key_exists('id', $decode) || $decode['id'] !== $id) {
-      throw new \RuntimeException("Protocol error: Received response for wrong request.");
+      throw new \RuntimeException('Protocol error: Received response for wrong request.');
     }
 
     if (array_key_exists('error', $decode) && !array_key_exists('result', $decode)) {
index 7fb2b74ac11f1e7b4f5851e14808d0af0e0ce162..3e458cd00c4a94de19d8cc86939da05cbc9e84f8 100644 (file)
@@ -52,7 +52,7 @@ class JsonRpc {
       $response = static::handleMethodCall($parsed, $dispatcher);
     }
     else {
-      // [sic] "Invalid Request" title-case is anomalous but dictated by standard.
+      // [sic] 'Invalid Request' title-case is anomalous but dictated by standard.
       throw new \InvalidArgumentException('Invalid Request', -32600);
     }
 
@@ -65,7 +65,7 @@ class JsonRpc {
         throw new \InvalidArgumentException('Parse error', -32700);
       }
       if (($request['jsonrpc'] ?? '') !== '2.0' || !is_string($request['method'])) {
-        // [sic] "Invalid Request" title-case is anomalous but dictated by standard.
+        // [sic] 'Invalid Request' title-case is anomalous but dictated by standard.
         throw new \InvalidArgumentException('Invalid Request', -32600);
       }
       if (isset($request['params']) && !is_array($request['params'])) {
index f2985a3ec2addb58e7929df20ab26862fe7236fd..a8148a321462dc8c9d158997d3ae65af8ddbf11b 100644 (file)
@@ -17,7 +17,7 @@ class JsonRpcMethodException extends \CRM_Core_Exception {
   public $raw;
 
   public function __construct(array $jsonRpcError) {
-    parent::__construct($jsonRpcError['error']['message'] ?? "Unknown JSON-RPC error",
+    parent::__construct($jsonRpcError['error']['message'] ?? 'Unknown JSON-RPC error',
       $jsonRpcError['error']['code'] ?? 0,
       $jsonRpcError['error']['data'] ?? []
     );
index 5de7025bdd87590edcd8943398e001b88f1eeb4c..d068b90d88a135477c22f398aeb1701166b48a51 100644 (file)
@@ -18,10 +18,10 @@ namespace Civi\Pipe;
  * $session = new class {
  *   use LineSessionTrait;
  *   protected function onRequest(string $requestLine): ?string {
- *     return "Thanks";
+ *     return 'Thanks';
  *   }
  *   protected function onException(string $requestLine, \Throwable $t): ?string {
- *     return "Oops";
+ *     return 'Oops';
  *   }
  * }
  * $session->setIO(STDIN, STDOUT)->run();
index cd900067adaa8cf193ac35377f79dc3fbc576cf5..2960bdbf4387a146598560ea8368508097dea1f2 100644 (file)
@@ -69,7 +69,7 @@ class PipeSession {
       }
     }
 
-    return json_encode(["Civi::pipe" => $flags]);
+    return json_encode(['Civi::pipe' => $flags]);
   }
 
   /**
index 3cb7e8d592338474b9295fd574e6c2ec4fde072d..06b17406b6942180497c02de08a7fcf49fec5353 100644 (file)
@@ -104,7 +104,7 @@ class PublicMethods {
    */
   public function login(PipeSession $session, array $request) {
     if (!function_exists('authx_login')) {
-      throw new \CRM_Core_Exception("Cannot authenticate. Authx is not configured.");
+      throw new \CRM_Core_Exception('Cannot authenticate. Authx is not configured.');
     }
 
     $redact = function(?array $authx) {
@@ -116,17 +116,17 @@ class PublicMethods {
       return $redact(authx_login(['flow' => 'script', 'principal' => $principal]));
     }
     elseif ($principal && !$session->isTrusted()) {
-      throw new AuthxException("Session is not trusted.");
+      throw new AuthxException('Session is not trusted.');
     }
     elseif (isset($request['cred'])) {
       $authn = new \Civi\Authx\Authenticator();
       $authn->setRejectMode('exception');
       if ($authn->auth(NULL, ['flow' => 'pipe', 'cred' => $request['cred']])) {
-        return $redact(\CRM_Core_Session::singleton()->get("authx"));
+        return $redact(\CRM_Core_Session::singleton()->get('authx'));
       }
     }
 
-    throw new AuthxException("Cannot authenticate. Must specify principal/credentials.");
+    throw new AuthxException('Cannot authenticate. Must specify principal/credentials.');
   }
 
   /**