3131 ]);
3232} catch (AuthenticationException $ e ) {
3333 // Invalid credentials or login failed
34- echo " Authentication failed: " . $ e ->getMessage () . PHP_EOL ;
34+ echo ' Authentication failed: ' . $ e ->getMessage (). PHP_EOL ;
3535 // Suggestion: Check SAP_B1_USERNAME and SAP_B1_PASSWORD in .env
3636
3737} catch (SessionExpiredException $ e ) {
3838 // Session timed out (usually auto-refreshed, but can occur)
39- echo " Session expired: " . $ e ->getMessage () . PHP_EOL ;
39+ echo ' Session expired: ' . $ e ->getMessage (). PHP_EOL ;
4040 // SDK will automatically retry with a new session if auto_refresh is enabled
4141
4242} catch (RateLimitException $ e ) {
4343 // Too many requests (429)
44- echo " Rate limited! Retry after: " . $ e ->getRetryAfter () . " seconds" . PHP_EOL ;
44+ echo ' Rate limited! Retry after: ' . $ e ->getRetryAfter (). ' seconds' . PHP_EOL ;
4545 sleep ($ e ->getRetryAfter ());
4646 // Retry the request...
4747
4848} catch (CircuitBreakerOpenException $ e ) {
4949 // Circuit breaker is open due to repeated failures
50- echo " Service temporarily unavailable (circuit open) " . PHP_EOL ;
51- echo " Will recover after: " . $ e ->getRecoveryTime ()->diffForHumans () . PHP_EOL ;
50+ echo ' Service temporarily unavailable (circuit open) ' . PHP_EOL ;
51+ echo ' Will recover after: ' . $ e ->getRecoveryTime ()->diffForHumans (). PHP_EOL ;
5252 // Don't retry immediately - the circuit breaker protects the server
5353
5454} catch (PoolExhaustedException $ e ) {
5555 // No sessions available in pool (high concurrency scenario)
56- echo " No sessions available, try again later " . PHP_EOL ;
56+ echo ' No sessions available, try again later ' . PHP_EOL ;
5757 // Consider increasing pool size or wait_timeout in config
5858
5959} catch (ProxyException $ e ) {
6060 // Proxy/gateway error (502)
61- echo " Proxy error: " . $ e ->getMessage () . PHP_EOL ;
61+ echo ' Proxy error: ' . $ e ->getMessage (). PHP_EOL ;
6262 // Usually temporary - SDK will retry automatically
6363
6464} catch (ConnectionException $ e ) {
6565 // Network connectivity issues
66- echo " Cannot connect to SAP server: " . $ e ->getMessage () . PHP_EOL ;
66+ echo ' Cannot connect to SAP server: ' . $ e ->getMessage (). PHP_EOL ;
6767 // Check network, firewall, VPN, or SAP server status
6868
6969} catch (ServiceLayerException $ e ) {
7070 // SAP Business logic error
71- echo " SAP Error Code: " . $ e ->getCode () . PHP_EOL ;
72- echo " SAP Message: " . $ e ->getMessage () . PHP_EOL ;
73- echo " Human Message: " . $ e ->getHumanMessage () . PHP_EOL ;
74- echo " Suggestion: " . $ e ->getSuggestion () . PHP_EOL ;
75- echo " Category: " . $ e ->getCategory () . PHP_EOL ;
76- echo " Is Retryable: " . ($ e ->isRetryable () ? 'Yes ' : 'No ' ) . PHP_EOL ;
71+ echo ' SAP Error Code: ' . $ e ->getCode (). PHP_EOL ;
72+ echo ' SAP Message: ' . $ e ->getMessage (). PHP_EOL ;
73+ echo ' Human Message: ' . $ e ->getHumanMessage (). PHP_EOL ;
74+ echo ' Suggestion: ' . $ e ->getSuggestion (). PHP_EOL ;
75+ echo ' Category: ' . $ e ->getCategory (). PHP_EOL ;
76+ echo ' Is Retryable: ' . ($ e ->isRetryable () ? 'Yes ' : 'No ' ). PHP_EOL ;
7777
7878} catch (JsonDecodeException $ e ) {
7979 // Malformed JSON response
80- echo " Invalid JSON response: " . $ e ->getMessage () . PHP_EOL ;
81- echo " Body preview: " . $ e ->getBodyPreview () . PHP_EOL ;
80+ echo ' Invalid JSON response: ' . $ e ->getMessage (). PHP_EOL ;
81+ echo ' Body preview: ' . $ e ->getBodyPreview (). PHP_EOL ;
8282
8383} catch (\Throwable $ e ) {
8484 // Catch-all for unexpected errors
85- echo " Unexpected error: " . $ e ->getMessage () . PHP_EOL ;
85+ echo ' Unexpected error: ' . $ e ->getMessage (). PHP_EOL ;
8686}
8787
8888// =============================================================================
9797 ]);
9898} catch (ServiceLayerException $ e ) {
9999 if ($ e ->getCode () === -2035 ) {
100- echo " Business partner already exists, updating instead... " . PHP_EOL ;
100+ echo ' Business partner already exists, updating instead... ' . PHP_EOL ;
101101 SapB1::update ('BusinessPartners ' , 'EXISTING_CODE ' , [
102102 'CardName ' => 'Test ' ,
103103 ]);
111111 SapB1::update ('BusinessPartners ' , 'NONEXISTENT ' , ['CardName ' => 'New Name ' ]);
112112} catch (ServiceLayerException $ e ) {
113113 if ($ e ->getCode () === -2028 ) {
114- echo " Business partner not found: NONEXISTENT " . PHP_EOL ;
114+ echo ' Business partner not found: NONEXISTENT ' . PHP_EOL ;
115115 } else {
116116 throw $ e ;
117117 }
122122 SapB1::delete ('BusinessPartners ' , 'C001 ' );
123123} catch (ServiceLayerException $ e ) {
124124 if ($ e ->getCategory () === 'constraint_violation ' ) {
125- echo " Cannot delete: " . $ e ->getHumanMessage () . PHP_EOL ;
126- echo " Tip: " . $ e ->getSuggestion () . PHP_EOL ;
125+ echo ' Cannot delete: ' . $ e ->getHumanMessage (). PHP_EOL ;
126+ echo ' Tip: ' . $ e ->getSuggestion (). PHP_EOL ;
127127 } else {
128128 throw $ e ;
129129 }
@@ -139,17 +139,17 @@ function createBusinessPartner(array $data): array
139139 $ required = ['CardCode ' , 'CardName ' , 'CardType ' ];
140140 $ missing = array_diff ($ required , array_keys ($ data ));
141141
142- if (!empty ($ missing )) {
142+ if (! empty ($ missing )) {
143143 throw new \InvalidArgumentException (
144- 'Missing required fields: ' . implode (', ' , $ missing )
144+ 'Missing required fields: ' . implode (', ' , $ missing )
145145 );
146146 }
147147
148148 // Validate CardType
149149 $ validTypes = ['cCustomer ' , 'cSupplier ' , 'cLead ' ];
150- if (!in_array ($ data ['CardType ' ], $ validTypes , true )) {
150+ if (! in_array ($ data ['CardType ' ], $ validTypes , true )) {
151151 throw new \InvalidArgumentException (
152- 'Invalid CardType. Must be one of: ' . implode (', ' , $ validTypes )
152+ 'Invalid CardType. Must be one of: ' . implode (', ' , $ validTypes )
153153 );
154154 }
155155
@@ -171,14 +171,14 @@ function withRetry(callable $operation, int $maxAttempts = 3): mixed
171171 } catch (ServiceLayerException $ e ) {
172172 $ lastException = $ e ;
173173
174- if (!$ e ->isRetryable ()) {
174+ if (! $ e ->isRetryable ()) {
175175 throw $ e ; // Don't retry non-retryable errors
176176 }
177177
178178 $ attempt ++;
179179 if ($ attempt < $ maxAttempts ) {
180180 $ delay = pow (2 , $ attempt ); // Exponential backoff
181- echo "Attempt {$ attempt } failed, retrying in {$ delay }s... " . PHP_EOL ;
181+ echo "Attempt {$ attempt } failed, retrying in {$ delay }s... " . PHP_EOL ;
182182 sleep ($ delay );
183183 }
184184 }
@@ -226,11 +226,13 @@ function getBusinessPartnersWithFallback(): array
226226 try {
227227 $ partners = SapB1::get ('BusinessPartners ' )->value ();
228228 cache ()->put ('business_partners ' , $ partners , 3600 );
229+
229230 return $ partners ;
230231 } catch (ConnectionException |CircuitBreakerOpenException $ e ) {
231232 $ cached = cache ()->get ('business_partners ' );
232233 if ($ cached !== null ) {
233- Log::warning ('Using cached business partners due to: ' . $ e ->getMessage ());
234+ Log::warning ('Using cached business partners due to: ' .$ e ->getMessage ());
235+
234236 return $ cached ;
235237 }
236238 throw $ e ;
0 commit comments