@@ -257,26 +257,26 @@ abstract class AbstractReportingCloud
257257 private $ password ;
258258
259259 /**
260- * When true, API call does not count against quota
261- * "TEST MODE" watermark is added to document
260+ * Backend base URI
262261 *
263- * @var bool |null
262+ * @var string |null
264263 */
265- private $ test ;
264+ private $ baseUri ;
266265
267266 /**
268- * Backend base URI
267+ * Debug flag of REST client
269268 *
270- * @var string |null
269+ * @var bool |null
271270 */
272- private $ baseUri ;
271+ private $ debug ;
273272
274273 /**
275- * Backend version string
274+ * When true, API call does not count against quota
275+ * "TEST MODE" watermark is added to document
276276 *
277- * @var string |null
277+ * @var bool |null
278278 */
279- private $ version ;
279+ private $ test ;
280280
281281 /**
282282 * Backend timeout in seconds
@@ -286,11 +286,11 @@ abstract class AbstractReportingCloud
286286 private $ timeout ;
287287
288288 /**
289- * Debug flag of REST client
289+ * Backend version string
290290 *
291- * @var bool |null
291+ * @var string |null
292292 */
293- private $ debug ;
293+ private $ version ;
294294
295295 /**
296296 * REST client to backend
@@ -400,73 +400,73 @@ public function setBaseUri(string $baseUri): self
400400 }
401401
402402 /**
403- * Get the timeout (in seconds) of the backend web service
403+ * Return the debug flag
404404 *
405- * @return int |null
405+ * @return bool |null
406406 */
407- public function getTimeout (): ?int
407+ public function getDebug (): ?bool
408408 {
409- return $ this ->timeout ;
409+ return $ this ->debug ;
410410 }
411411
412412 /**
413- * Set the timeout (in seconds) of the backend web service
413+ * Set the debug flag
414414 *
415- * @param int $timeout
415+ * @param bool $debug Debug flag
416416 *
417417 * @return AbstractReportingCloud
418418 */
419- public function setTimeout ( int $ timeout ): self
419+ public function setDebug ( bool $ debug ): self
420420 {
421- $ this ->timeout = $ timeout ;
421+ $ this ->debug = $ debug ;
422422
423423 return $ this ;
424424 }
425425
426426 /**
427- * Return the debug flag
427+ * Return the test flag
428428 *
429429 * @return bool|null
430430 */
431- public function getDebug (): ?bool
431+ public function getTest (): ?bool
432432 {
433- return $ this ->debug ;
433+ return $ this ->test ;
434434 }
435435
436436 /**
437- * Set the debug flag
437+ * Set the test flag
438438 *
439- * @param bool $debug Debug flag
439+ * @param bool $test
440440 *
441441 * @return AbstractReportingCloud
442442 */
443- public function setDebug (bool $ debug ): self
443+ public function setTest (bool $ test ): self
444444 {
445- $ this ->debug = $ debug ;
445+ $ this ->test = $ test ;
446446
447447 return $ this ;
448448 }
449449
450450 /**
451- * Return the test flag
451+ * Get the timeout (in seconds) of the backend web service
452452 *
453- * @return bool |null
453+ * @return int |null
454454 */
455- public function getTest (): ?bool
455+ public function getTimeout (): ?int
456456 {
457- return $ this ->test ;
457+ return $ this ->timeout ;
458458 }
459459
460460 /**
461- * Set the test flag
461+ * Set the timeout (in seconds) of the backend web service
462462 *
463- * @param bool $test
463+ * @param int $timeout
464464 *
465465 * @return AbstractReportingCloud
466466 */
467- public function setTest ( bool $ test ): self
467+ public function setTimeout ( int $ timeout ): self
468468 {
469- $ this ->test = $ test ;
469+ $ this ->timeout = $ timeout ;
470470
471471 return $ this ;
472472 }
@@ -537,6 +537,69 @@ public function setClient(Client $client): self
537537 return $ this ;
538538 }
539539
540+ /**
541+ * Assign default values to option properties
542+ *
543+ * @return ReportingCloud
544+ */
545+ protected function setDefaultOptions (): self
546+ {
547+ if (null === $ this ->getBaseUri ()) {
548+ $ baseUri = $ this ->getBaseUriFromEnv () ?? self ::DEFAULT_BASE_URI ;
549+ $ this ->setBaseUri ($ baseUri );
550+ }
551+
552+ if (null === $ this ->getDebug ()) {
553+ $ this ->setDebug (self ::DEFAULT_DEBUG );
554+ }
555+
556+ if (null === $ this ->getTest ()) {
557+ $ this ->setTest (self ::DEFAULT_TEST );
558+ }
559+
560+ if (null === $ this ->getTimeout ()) {
561+ $ this ->setTimeout (self ::DEFAULT_TIMEOUT );
562+ }
563+
564+ if (null === $ this ->getVersion ()) {
565+ $ this ->setVersion (self ::DEFAULT_VERSION );
566+ }
567+
568+ return $ this ;
569+ }
570+
571+ /**
572+ * Return the base URI from the environment variable "REPORTING_CLOUD_BASE_URI",
573+ * checking that the hostname and sub-domain match the known hostname and sub-domain.
574+ *
575+ * Return null, if the environment variable has not been set or is empty.
576+ *
577+ * @throws InvalidArgumentException
578+ * @return string|null
579+ */
580+ protected function getBaseUriFromEnv (): ?string
581+ {
582+ $ envVarName = 'REPORTING_CLOUD_BASE_URI ' ;
583+
584+ $ baseUri = (string ) getenv ($ envVarName );
585+ $ baseUri = trim ($ baseUri );
586+
587+ if (empty ($ baseUri )) {
588+ return null ;
589+ }
590+
591+ $ sdkHost = (string ) parse_url (self ::DEFAULT_BASE_URI , PHP_URL_HOST );
592+ $ envHost = (string ) parse_url ($ baseUri , PHP_URL_HOST );
593+
594+ if (!StringUtils::endsWith ($ envHost , $ sdkHost )) {
595+ $ format = 'Base URI from environment variable "%s" with value "%s" does not end in "%s" ' ;
596+ $ message = sprintf ($ format , $ envVarName , $ baseUri , $ sdkHost );
597+ throw new InvalidArgumentException ($ message );
598+ }
599+
600+ return $ baseUri ;
601+ }
602+
540603 /**
541604 * Request the URI with options
542605 *
@@ -611,37 +674,5 @@ private function getAuthorizationHeader(): string
611674 throw new InvalidArgumentException ($ message );
612675 }
613676
614- /**
615- * Return the base URI from the environment variable "REPORTING_CLOUD_BASE_URI",
616- * checking that the hostname and sub-domain match the known hostname and sub-domain.
617- *
618- * Return null, if the environment variable has not been set or is empty.
619- *
620- * @throws InvalidArgumentException
621- * @return string|null
622- */
623- protected function getBaseUriFromEnv (): ?string
624- {
625- $ envVarName = 'REPORTING_CLOUD_BASE_URI ' ;
626-
627- $ baseUri = (string ) getenv ($ envVarName );
628- $ baseUri = trim ($ baseUri );
629-
630- if (empty ($ baseUri )) {
631- return null ;
632- }
633-
634- $ sdkHost = (string ) parse_url (self ::DEFAULT_BASE_URI , PHP_URL_HOST );
635- $ envHost = (string ) parse_url ($ baseUri , PHP_URL_HOST );
636-
637- if (!StringUtils::endsWith ($ envHost , $ sdkHost )) {
638- $ format = 'Base URI from environment variable "%s" with value "%s" does not end in "%s" ' ;
639- $ message = sprintf ($ format , $ envVarName , $ baseUri , $ sdkHost );
640- throw new InvalidArgumentException ($ message );
641- }
642-
643- return $ baseUri ;
644- }
645-
646677 // </editor-fold>
647678}
0 commit comments