88use Laminas \Http \Exception \RuntimeException ;
99use Laminas \Http \Request ;
1010use Magento \Framework \Exception \LocalizedException ;
11- use Magento \Framework \HTTP \LaminasClient ;
1211use Magento \Framework \HTTP \LaminasClientFactory ;
1312use Magento \Framework \Serialize \SerializerInterface ;
1413use Magento \NewRelicReporting \Model \Config ;
15- use Magento \NewRelicReporting \Model \NerdGraph \ Client as NerdGraphClient ;
14+ use Magento \NewRelicReporting \Model \Config \ Source \ ApiMode ;
1615use Magento \NewRelicReporting \Model \NerdGraph \DeploymentTracker ;
1716use Psr \Log \LoggerInterface ;
1817
2120 */
2221class Deployments
2322{
24- /**
25- * API mode constant for NerdGraph (GraphQL) API
26- */
27- private const NERDGRAPH = 'nerdgraph ' ;
23+
2824 /**
2925 * API URL for New Relic deployments
3026 */
@@ -43,22 +39,17 @@ class Deployments
4339 /**
4440 * @var LaminasClientFactory $clientFactory
4541 */
46- protected $ clientFactory ;
42+ protected LaminasClientFactory $ clientFactory ;
4743
4844 /**
4945 * @var SerializerInterface
5046 */
51- private $ serializer ;
52-
53- /**
54- * @var NerdGraphClient
55- */
56- private $ nerdGraphClient ;
47+ private SerializerInterface $ serializer ;
5748
5849 /**
5950 * @var DeploymentTracker
6051 */
61- private $ deploymentTracker ;
52+ private DeploymentTracker $ deploymentTracker ;
6253
6354 /**
6455 * Constructor
@@ -67,22 +58,19 @@ class Deployments
6758 * @param LoggerInterface $logger
6859 * @param LaminasClientFactory $clientFactory
6960 * @param SerializerInterface $serializer
70- * @param NerdGraphClient $nerdGraphClient
7161 * @param DeploymentTracker $deploymentTracker
7262 */
7363 public function __construct (
7464 Config $ config ,
7565 LoggerInterface $ logger ,
7666 LaminasClientFactory $ clientFactory ,
7767 SerializerInterface $ serializer ,
78- NerdGraphClient $ nerdGraphClient ,
7968 DeploymentTracker $ deploymentTracker
8069 ) {
8170 $ this ->config = $ config ;
8271 $ this ->logger = $ logger ;
8372 $ this ->clientFactory = $ clientFactory ;
8473 $ this ->serializer = $ serializer ;
85- $ this ->nerdGraphClient = $ nerdGraphClient ;
8674 $ this ->deploymentTracker = $ deploymentTracker ;
8775 }
8876
@@ -100,6 +88,7 @@ public function __construct(
10088 * @param string|null $groupId Group ID (NerdGraph only)
10189 *
10290 * @return bool|string|array
91+ * @throws LocalizedException
10392 */
10493 public function setDeployment (
10594 string $ description ,
@@ -113,7 +102,7 @@ public function setDeployment(
113102 // Check API mode configuration
114103 $ apiMode = $ this ->config ->getApiMode ();
115104
116- if ($ apiMode === self :: NERDGRAPH ) {
105+ if ($ apiMode === ApiMode:: MODE_NERDGRAPH ) {
117106 return $ this ->createNerdGraphDeployment (
118107 $ description ,
119108 $ change ,
@@ -137,7 +126,7 @@ public function setDeployment(
137126 * @param string|null $revision
138127 * @return bool|string
139128 */
140- private function createV2RestDeployment ($ description , $ change , $ user , $ revision )
129+ private function createV2RestDeployment (string $ description , bool | string $ change , bool | string $ user , ? string $ revision ): bool | string
141130 {
142131 $ apiUrl = $ this ->config ->getNewRelicApiUrl ();
143132 if (empty ($ apiUrl )) {
@@ -147,7 +136,6 @@ private function createV2RestDeployment($description, $change, $user, $revision)
147136
148137 $ apiUrl = sprintf ($ apiUrl , $ this ->config ->getNewRelicAppId ());
149138
150- /** @var LaminasClient $client */
151139 $ client = $ this ->clientFactory ->create ();
152140 $ client ->setUri ($ apiUrl );
153141 $ client ->setMethod (Request::METHOD_POST );
@@ -200,7 +188,7 @@ private function createV2RestDeployment($description, $change, $user, $revision)
200188 * @return array|false
201189 * @throws LocalizedException
202190 */
203- private function createNerdGraphDeployment ($ description , $ change , $ user , $ revision , $ commit , $ deepLink , $ groupId )
191+ private function createNerdGraphDeployment (string $ description , bool | string $ change , bool | string $ user , ? string $ revision , ? string $ commit , ? string $ deepLink , ? string $ groupId ): false | array
204192 {
205193 return $ this ->deploymentTracker ->createDeployment (
206194 $ description ,
0 commit comments