@@ -54,27 +54,51 @@ public function __construct(
5454 /**
5555 * Configura la autenticación específica para la aplicación.
5656 *
57- * @param array $credenciales Parámetros de autenticación. Puede ser 'pass' o 'cert'.
57+ * @param array $credenciales Parámetros de autenticación. Puede ser
58+ * 'pass' o 'cert'.
5859 * @throws \apigatewaycl\api_client\ApiException
5960 * @return void
6061 */
61- private function setupAuth (array $ credenciales )
62+ private function setupAuth (array $ credenciales ): void
6263 {
6364 $ tipo = key ($ credenciales ); // Detecta si es 'pass' o 'cert'
6465 $ datos = $ credenciales [$ tipo ] ?? [];
6566
66- $ identificador = $ datos ['rut ' ] ?? $ datos ['cert-data ' ] ?? $ datos ['file-data ' ] ?? null ;
67- $ clave = $ datos ['clave ' ] ?? $ datos ['pkey-data ' ] ?? $ datos ['file-pass ' ] ?? null ;
67+ $ identificador = $ datos ['rut ' ] ??
68+ $ datos ['cert-data ' ] ??
69+ $ datos ['file-data ' ] ??
70+ null ;
71+ $ clave = $ datos ['clave ' ] ??
72+ $ datos ['pkey-data ' ] ??
73+ $ datos ['file-pass ' ] ??
74+ null ;
6875
6976 if ($ identificador && $ clave ) {
7077 if ($ this ->isAuthPass ($ identificador )) {
71- $ this ->auth = ['pass ' => ['rut ' => $ identificador , 'clave ' => $ clave ]];
78+ $ this ->auth = [
79+ 'pass ' => [
80+ 'rut ' => $ identificador ,
81+ 'clave ' => $ clave ,
82+ ],
83+ ];
7284 } elseif ($ this ->isAuthCertData ($ identificador )) {
73- $ this ->auth = ['cert ' => ['cert-data ' => $ identificador , 'pkey-data ' => $ clave ]];
85+ $ this ->auth = [
86+ 'cert ' => [
87+ 'cert-data ' => $ identificador ,
88+ 'pkey-data ' => $ clave ,
89+ ],
90+ ];
7491 } elseif ($ this ->isAuthFileData ($ identificador )) {
75- $ this ->auth = ['cert ' => ['file-data ' => $ identificador , 'file-pass ' => $ clave ]];
92+ $ this ->auth = [
93+ 'cert ' => [
94+ 'file-data ' => $ identificador ,
95+ 'file-pass ' => $ clave ,
96+ ],
97+ ];
7698 } else {
77- throw new ApiException ('No se han proporcionado las credenciales de autentificación. ' );
99+ throw new ApiException (
100+ message: 'No se han proporcionado las credenciales de autentificación. '
101+ );
78102 }
79103 }
80104 }
@@ -102,9 +126,10 @@ private function setupAuth(array $credenciales)
102126 * - abcdefgh-i (caracteres no permitidos)
103127 *
104128 * @param string $rut El RUT a validar.
105- * @return bool true si el RUT tiene un formato válido,false en caso contrario.
129+ * @return bool true si el RUT tiene un formato válido,false en caso
130+ * contrario.
106131 */
107- private function isAuthPass (string $ rut )
132+ private function isAuthPass (string $ rut ): bool
108133 {
109134 if (is_null ($ rut )) {
110135 return false ;
@@ -118,9 +143,10 @@ private function isAuthPass(string $rut)
118143 * Verifica si una cadena es una cadena codificada en Base64 válida.
119144 *
120145 * @param string $firmaElectronicaBase64 La cadena a verificar.
121- * @return bool true si la cadena es válida en Base64, false en caso contrario.
146+ * @return bool true si la cadena es válida en Base64, false en caso
147+ * contrario.
122148 */
123- private function isAuthFileData (string $ firmaElectronicaBase64 )
149+ private function isAuthFileData (string $ firmaElectronicaBase64 ): bool
124150 {
125151 if (is_null ($ firmaElectronicaBase64 )) {
126152 return false ;
@@ -130,7 +156,10 @@ private function isAuthFileData(string $firmaElectronicaBase64)
130156 return false ;
131157 }
132158 // Validar Base64
133- return base64_decode ($ firmaElectronicaBase64 , true ) !== false ;
159+ return base64_decode (
160+ string: $ firmaElectronicaBase64 ,
161+ strict: true
162+ ) !== false ;
134163 }
135164
136165 /**
@@ -160,51 +189,73 @@ private function isAuthFileData(string $firmaElectronicaBase64)
160189 * @param string $pemStr La cadena a validar.
161190 * @return bool true si la cadena tiene formato PEM válido, false en caso contrario.
162191 */
163- private function isAuthCertData (string $ pemStr )
192+ private function isAuthCertData (string $ pemStr ): bool
164193 {
165194 if (is_null ($ pemStr )) {
166195 return false ;
167196 }
168197 // Expresión regular para validar el formato PEM
169198 $ pattern = '/-----BEGIN ([A-Z ]+)-----\s+([A-Za-z0-9+\/=\s]+)-----END \1-----$/m ' ;
170- if (!preg_match ($ pattern , trim ($ pemStr ), $ matches )) {
199+ if (!preg_match (
200+ $ pattern ,
201+ trim ($ pemStr ),
202+ $ matches
203+ )
204+ ) {
171205 return false ;
172206 }
173207 // Validar contenido Base64
174- $ base64Content = preg_replace ('/\s+/ ' , '' , $ matches [2 ]);
208+ $ base64Content = preg_replace (
209+ '/\s+/ ' ,
210+ '' ,
211+ $ matches [2 ]
212+ );
175213 return base64_decode ($ base64Content , true ) !== false ;
176214 }
177215
178216 /**
179217 * Obtiene la autenticación de tipo 'pass'.
180218 *
181- * @throws \apigatewaycl\api_client\ApiException Si falta información de autenticación.
219+ * @throws \apigatewaycl\api_client\ApiException Si falta información
220+ * de autenticación.
182221 * @return array Información de autenticación.
183222 */
184- protected function getAuthPass ()
223+ protected function getAuthPass (): array
185224 {
186225 if (isset ($ this ->auth ['pass ' ])) {
187226 if (empty ($ this ->auth ['pass ' ]['rut ' ])) {
188- throw new ApiException ('auth.pass.rut empty. ' );
227+ throw new ApiException (message: 'auth.pass.rut empty. ' );
189228 }
190229 if (empty ($ this ->auth ['pass ' ]['clave ' ])) {
191- throw new ApiException ('auth.pass.clave empty. ' );
230+ throw new ApiException (message: 'auth.pass.clave empty. ' );
192231 }
193232 } elseif (isset ($ this ->auth ['cert ' ])) {
194- if (isset ($ this ->auth ['cert ' ]['cert-data ' ]) && empty ($ this ->auth ['cert ' ]['cert-data ' ])) {
195- throw new ApiException ('auth.cert.cert-data empty. ' );
233+ if (
234+ isset ($ this ->auth ['cert ' ]['cert-data ' ]) &&
235+ empty ($ this ->auth ['cert ' ]['cert-data ' ])
236+ ) {
237+ throw new ApiException (message: 'auth.cert.cert-data empty. ' );
196238 }
197- if (isset ($ this ->auth ['cert ' ]['pkey-data ' ]) && empty ($ this ->auth ['cert ' ]['pkey-data ' ])) {
198- throw new ApiException ('auth.cert.pkey-data empty. ' );
239+ if (
240+ isset ($ this ->auth ['cert ' ]['pkey-data ' ]) &&
241+ empty ($ this ->auth ['cert ' ]['pkey-data ' ])
242+ ) {
243+ throw new ApiException (message: 'auth.cert.pkey-data empty. ' );
199244 }
200- if (isset ($ this ->auth ['cert ' ]['file-data ' ]) && empty ($ this ->auth ['cert ' ]['file-data ' ])) {
201- throw new ApiException ('auth.cert.file-data empty. ' );
245+ if (
246+ isset ($ this ->auth ['cert ' ]['file-data ' ]) &&
247+ empty ($ this ->auth ['cert ' ]['file-data ' ])
248+ ) {
249+ throw new ApiException (message: 'auth.cert.file-data empty. ' );
202250 }
203- if (isset ($ this ->auth ['cert ' ]['file-pass ' ]) && empty ($ this ->auth ['cert ' ]['file-pass ' ])) {
204- throw new ApiException ('auth.cert.file-pass empty. ' );
251+ if (
252+ isset ($ this ->auth ['cert ' ]['file-pass ' ]) &&
253+ empty ($ this ->auth ['cert ' ]['file-pass ' ])
254+ ) {
255+ throw new ApiException (message: 'auth.cert.file-pass empty. ' );
205256 }
206257 } else {
207- throw new ApiException ('auth.pass or auth.cert missing. ' );
258+ throw new ApiException (message: 'auth.pass or auth.cert missing. ' );
208259 }
209260
210261 return $ this ->auth ;
0 commit comments