Completed
Push — master ( 5d1c26...d793ff )
by Tobias
02:19
created
src/APIAccess/Core.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * Obtém o endereço (IP ou hostname) do servidor
263 263
      *
264 264
      * @param void
265
-     * @return string|bool
265
+     * @return string|null
266 266
      * @since 0.1
267 267
      * @see setIPAServer()
268 268
      */
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     /**
298 298
      * Retorna caminho completo (path) do certificado
299 299
      *
300
-     * @return string|bool
300
+     * @return string|null
301 301
      * @since 0.1
302 302
      * @see setCertificateFile()
303 303
      */
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      * Obtem a string de retorno do cURL definida anteriormente com setCurlResponse()
324 324
      *
325 325
      * @param void
326
-     * @return string|bool
326
+     * @return string|null
327 327
      * @since 0.1
328 328
      * @see setCurlResponse()
329 329
      */
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * Obtem uma manipulador (handler) cURL já com algumas opções definidas
362 362
      *
363 363
      * @param bool $forcar inicia o cURL mesmo que ele já esteja
364
-     * @return mixed Manipulador do cURL
364
+     * @return boolean Manipulador do cURL
365 365
      * @since 0.1
366 366
      * @see endCurl()
367 367
      */
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
      * Auxilia no debug do cURL. Deve ser utilizada no lugar de startCurl()
427 427
      *
428 428
      * @param void
429
-     * @return Manipulador (handler) para o cURL
429
+     * @return boolean (handler) para o cURL
430 430
      * @since 0.1
431 431
      * @see startCurl()
432 432
      * @todo need improvements
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
      * @param string $metodo parâmetro obrigatório que define o método a ser executado pelo servidor
680 680
      * @param array $argumentos argumentos para o método
681 681
      * @param array $opcoes parâmetros para o método
682
-     * @return string|bool retorna false caso hava erro nos parâmetros passados
682
+     * @return false|string retorna false caso hava erro nos parâmetros passados
683 683
      * @since 0.1
684 684
      * @link http://php.net/manual/pt_BR/function.json-encode.php
685 685
      */
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @access public
108 108
      * @since 0.1
109 109
      */
110
-    public $certificate_file  = null;
110
+    public $certificate_file = null;
111 111
 
112 112
     /**
113 113
      * @var array curl_http_header HTTP header that will be used with cURL
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      * @access protected
143 143
      * @since 0.1
144 144
      */
145
-    private $user_logged  = false;
145
+    private $user_logged = false;
146 146
 
147 147
     /**
148 148
      * @var string|null $json_request String that contains the last json request what will be (or was) sent to the server
@@ -181,16 +181,16 @@  discard block
 block discarded – undo
181 181
      * @throws \Exception caso o método setIPAServer() retorne false
182 182
      * @throws \Exception caso o método setCertificateFile() retorne false
183 183
      */
184
-    public function __construct( $server = null, $certificate = null )
184
+    public function __construct($server = null, $certificate = null)
185 185
     {
186
-        if (! function_exists('curl_init')) {
186
+        if ( ! function_exists('curl_init')) {
187 187
             throw new \Exception('Unable to find cURL');
188 188
         }
189 189
 
190
-        if ( ! empty($server) && ! $this->setIPAServer($server) ) {
190
+        if ( ! empty($server) && ! $this->setIPAServer($server)) {
191 191
             throw new \Exception("Error while validating the server");
192 192
         }
193
-        else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate) ) {
193
+        else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate)) {
194 194
             throw new \Exception("Error while validating the certificate");
195 195
         }
196 196
 
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
      */
250 250
     public function setIPAServer($host = null)
251 251
     {
252
-        if (empty($host) || is_null($host) || !is_string($host)) {
252
+        if (empty($host) || is_null($host) || ! is_string($host)) {
253 253
             return false;
254 254
         }
255 255
         $this->ipa_server = $host;
256
-        $this->jsonrpc_url = 'https://' . $host . '/ipa/session/json';
257
-        $this->jsonrpc_login_url = 'https://' . $host . '/ipa/session/login_password';
256
+        $this->jsonrpc_url = 'https://'.$host.'/ipa/session/json';
257
+        $this->jsonrpc_login_url = 'https://'.$host.'/ipa/session/login_password';
258 258
         return true;
259 259
     }
260 260
 
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
      */
284 284
     public function setCertificateFile($arquivo)
285 285
     {
286
-        if (empty($arquivo) || is_null($arquivo) || !is_string($arquivo)) {
286
+        if (empty($arquivo) || is_null($arquivo) || ! is_string($arquivo)) {
287 287
             return false;
288
-        } else if (!file_exists($arquivo)) {
288
+        } else if ( ! file_exists($arquivo)) {
289 289
             throw new \Exception('Arquivo do certificado não existe');
290
-        } else if (!is_readable($arquivo)) {
290
+        } else if ( ! is_readable($arquivo)) {
291 291
             throw new \Exception('Arquivo do certificado não pôde ser lido');
292 292
         }
293 293
         $this->certificate_file = $arquivo;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      */
459 459
     public function curlHaveError()
460 460
     {
461
-        return ( curl_errno($this->curl_handler) ) ? true : false;
461
+        return (curl_errno($this->curl_handler)) ? true : false;
462 462
     }
463 463
 
464 464
     /**
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         // }
518 518
         //  removido no lugar de usar o metodo curlHaveError()
519 519
         // $retorno = $this->getCurlResponse() === false ? false : true;
520
-        return ( $this->curlHaveError() ) ? false : $codigo_http;
520
+        return ($this->curlHaveError()) ? false : $codigo_http;
521 521
     }
522 522
 
523 523
     /**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
      */
541 541
     public function authenticate($usuario = null, $senha = null)
542 542
     {
543
-        if (!$usuario || !$senha) {
543
+        if ( ! $usuario || ! $senha) {
544 544
             return false;
545 545
         }
546 546
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         curl_setopt($this->curl_handler, CURLOPT_POSTFIELDS, "user=$usuario&password=$senha");
571 571
         // Preciso do header para pegar o valor do campo X-IPA-Rejection-Reason
572 572
         // e como workaround_for_auth
573
-        if (!$this->curl_debug) {
573
+        if ( ! $this->curl_debug) {
574 574
             curl_setopt($this->curl_handler, CURLOPT_HEADER, true);
575 575
         }
576 576
 
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 
588 588
         // Preciso do header para pegar o valor do campo X-IPA-Rejection-Reason
589 589
         // e como workaround_for_auth
590
-        if (!$this->curl_debug) {
590
+        if ( ! $this->curl_debug) {
591 591
             curl_setopt($this->curl_handler, CURLOPT_HEADER, false);
592 592
         }
593 593
 
@@ -612,15 +612,15 @@  discard block
 block discarded – undo
612 612
                 $retorno['mensagem'] .= 'Usuário não encontrado no servidor. ';
613 613
             } else {
614 614
                 $retorno['mensagem'] .= 'Erro na autenticação. ';
615
-                if (!empty($descricao_erro_ipa)) {
616
-                    $retorno['mensagem'] .= "O servidor retornou \"" . $descricao_erro_ipa . "\". ";
615
+                if ( ! empty($descricao_erro_ipa)) {
616
+                    $retorno['mensagem'] .= "O servidor retornou \"".$descricao_erro_ipa."\". ";
617 617
                 }
618 618
             }
619 619
         } else if ('200' != $retorno['codigo_http']) {
620 620
             $retorno['autenticado'] = false;
621
-            $retorno['mensagem'] = "A resposta retornou o código HTTP \"" . $retorno['codigo_http'] . "\" que não é aceitável. ";
622
-            if (!empty($descricao_erro_ipa)) {
623
-                $retorno['mensagem'] .= "O servidor retornou \"" . $descricao_erro_ipa . "\". ";
621
+            $retorno['mensagem'] = "A resposta retornou o código HTTP \"".$retorno['codigo_http']."\" que não é aceitável. ";
622
+            if ( ! empty($descricao_erro_ipa)) {
623
+                $retorno['mensagem'] .= "O servidor retornou \"".$descricao_erro_ipa."\". ";
624 624
             }
625 625
         } else {
626 626
             $retorno['autenticado'] = true;
@@ -662,11 +662,11 @@  discard block
 block discarded – undo
662 662
      */
663 663
     public function isAssociativeArray($var, $force = true)
664 664
     {
665
-        if (!is_array($var)) {
665
+        if ( ! is_array($var)) {
666 666
             return false;
667 667
         }
668 668
 
669
-        if (!empty($var) || $force) {
669
+        if ( ! empty($var) || $force) {
670 670
             return array_diff_key($var, array_keys(array_keys($var)));
671 671
         }
672 672
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      */
686 686
     public function buildJsonRequest($metodo = null, $argumentos = array(), $opcoes = array())
687 687
     {
688
-        if (!$metodo || !is_array($argumentos) || !$this->isAssociativeArray($opcoes, false)) {
688
+        if ( ! $metodo || ! is_array($argumentos) || ! $this->isAssociativeArray($opcoes, false)) {
689 689
             return false;
690 690
         }
691 691
 
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
      */
743 743
     public function buildRequest($metodo = null, $parametros = array(), $opcoes = array(), $exceptionInError = true)
744 744
     {
745
-        if (!$this->userLogged()) {
745
+        if ( ! $this->userLogged()) {
746 746
             throw new \Exception('Usuario não está logado');
747 747
         }
748 748
 
@@ -755,10 +755,10 @@  discard block
 block discarded – undo
755 755
             CURLOPT_URL => $this->jsonrpc_url,
756 756
             CURLOPT_POSTFIELDS => $json,
757 757
             CURLOPT_HTTPHEADER => array(
758
-                'referer:https://' . $this->ipa_server . '/ipa/ui/index.html',
758
+                'referer:https://'.$this->ipa_server.'/ipa/ui/index.html',
759 759
                 'Content-Type:application/json',
760 760
                 'Accept:applicaton/json',
761
-                'Content-Length: ' . strlen($json),
761
+                'Content-Length: '.strlen($json),
762 762
             ),
763 763
         );
764 764
 
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
         if ($this->curlHaveError()) {
774 774
             throw new \Exception('Erro na requisição curl');
775 775
         }
776
-        if (!$codigo_http_resposta || '200' != $codigo_http_resposta) {
776
+        if ( ! $codigo_http_resposta || '200' != $codigo_http_resposta) {
777 777
             throw new \Exception("O valor \"$codigo_http_resposta\" não é um código de resposta válido");
778 778
         }
779 779
         if (empty($json_retorno) || empty($objeto_json_retorno)) {
780 780
             #TODO criar exceção para passar os dados do erro ao inves do json puro. Vide arquivo exemplos_retornos.txt
781 781
             throw new \Exception("Erro no retorno json. Valor é ${json_retorno}");
782 782
         }
783
-        if ($exceptionInError && !empty($objeto_json_retorno->error)) {
784
-            throw new \Exception("Erro na requisição. Detalhes: " . $objeto_json_retorno->error->message, $objeto_json_retorno->error->code);
783
+        if ($exceptionInError && ! empty($objeto_json_retorno->error)) {
784
+            throw new \Exception("Erro na requisição. Detalhes: ".$objeto_json_retorno->error->message, $objeto_json_retorno->error->code);
785 785
         }
786 786
 
787 787
         return array($objeto_json_retorno, $codigo_http_resposta);
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
     {
800 800
         $ret = $this->buildRequest('ping'); // retorna json e codigo http da resposta
801 801
         $json = $ret[0];
802
-        if (!empty($json->error) || empty($json->result) || empty($json->result->summary) || !is_string($json->result->summary)) {
802
+        if ( ! empty($json->error) || empty($json->result) || empty($json->result->summary) || ! is_string($json->result->summary)) {
803 803
             return false;
804 804
         }
805 805
         if ($retornar_string) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -189,8 +189,7 @@
 block discarded – undo
189 189
 
190 190
         if ( ! empty($server) && ! $this->setIPAServer($server) ) {
191 191
             throw new \Exception("Error while validating the server");
192
-        }
193
-        else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate) ) {
192
+        } else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate) ) {
194 193
             throw new \Exception("Error while validating the certificate");
195 194
         }
196 195
 
Please login to merge, or discard this patch.
bootstrap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,4 +18,4 @@
 block discarded – undo
18 18
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 19
 */
20 20
 
21
-include __DIR__ . '/src/autoload.php';
22 21
\ No newline at end of file
22
+include __DIR__.'/src/autoload.php';
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
examples/all.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 // Veja documentação do método procurarUsuarioBy() !
139 139
 _print( "Procurando usuarios cujo login seja \"$procurar\"" );
140 140
 try {
141
-	$procura_usuario_por = $ipa->findUserBy( 'uid', $procurar ); // login
142
-	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'mail', '[email protected]' ); // email
143
-	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'givenname', $procurar ); // primeiro nome
144
-	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'cn', 'Administrator' ); // nome completo
141
+  $procura_usuario_por = $ipa->findUserBy( 'uid', $procurar ); // login
142
+  //$procura_usuario_por = $ipa->procurarUsuarioBy( 'mail', '[email protected]' ); // email
143
+  //$procura_usuario_por = $ipa->procurarUsuarioBy( 'givenname', $procurar ); // primeiro nome
144
+  //$procura_usuario_por = $ipa->procurarUsuarioBy( 'cn', 'Administrator' ); // nome completo
145 145
     //$procura_usuario_por = $ipa->procurarUsuarioBy( 'in_group', 'admins' ); // usuário está no grupo
146 146
     if ( $procura_usuario_por ) {
147 147
       _print( 'Usuários encontrados' );
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
       _print( 'Nenhum usuário encontrado' );
151 151
     }
152 152
 } catch ( \Exception $e ) {
153
-	_print( "[procura usuario por] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
154
-	_print( "Requisicao json eh {$ipa->getJsonRequest()}" );
155
-	_print( "Resposta json eh {$ipa->getJsonResponse()}" );
156
-	die();
153
+  _print( "[procura usuario por] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
154
+  _print( "Requisicao json eh {$ipa->getJsonRequest()}" );
155
+  _print( "Resposta json eh {$ipa->getJsonResponse()}" );
156
+  die();
157 157
 }
158 158
 
159 159
 
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
 
25 25
 
26 26
 // Pedações de código úteis apenas para este arquivo
27
-require_once( 'snippet_debug.php' );
28
-require_once( 'functions.utils.php' );
27
+require_once('snippet_debug.php');
28
+require_once('functions.utils.php');
29 29
 
30 30
 // Variáveis mais utilizadas ao longo do código
31 31
 $host          = 'ipa.demo1.freeipa.org';
32 32
 // O certificado pode ser obtido em https://$host/ipa/config/ca.crt
33
-$certificado   = getcwd() ."/../certs/ipa.demo1.freeipa.org_ca.crt";
33
+$certificado   = getcwd()."/../certs/ipa.demo1.freeipa.org_ca.crt";
34 34
 $usuario       = 'admin';
35 35
 $senha         = 'Secret123';
36 36
 $procurar      = 'teste';
37
-$random        = rand( 1, 9999 );
37
+$random        = rand(1, 9999);
38 38
 
39 39
 // Instancia a classe
40
-require_once( '../bootstrap.php' );
40
+require_once('../bootstrap.php');
41 41
 try {
42
-  $ipa = new \FreeIPA\APIAccess\Group( $host, $certificado );
43
-} catch ( Exception $e ) {
44
-  _print( "[instancia] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
42
+  $ipa = new \FreeIPA\APIAccess\Group($host, $certificado);
43
+} catch (Exception $e) {
44
+  _print("[instancia] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
45 45
   die();
46 46
 }
47 47
 
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 
63 63
 // Faz autenticação
64 64
 try {
65
-  $ret_aut = $ipa->authenticate( $usuario, $senha );
66
-  if ( TRUE === $ret_aut['autenticado'] ) { // usuário está autenticado
67
-    _print( $ret_aut['mensagem'] );
65
+  $ret_aut = $ipa->authenticate($usuario, $senha);
66
+  if (TRUE === $ret_aut['autenticado']) { // usuário está autenticado
67
+    _print($ret_aut['mensagem']);
68 68
   }
69 69
   else {
70
-    _print( $ret_aut['mensagem'] );
70
+    _print($ret_aut['mensagem']);
71 71
     // Para debug:
72 72
     var_dump($ret_aut);
73 73
     // Para debug mais detalhado:
@@ -77,104 +77,104 @@  discard block
 block discarded – undo
77 77
     //print "String de retorno do curl: " . $ipa->getRetornoCurl() . "<br/>\n";
78 78
     die();
79 79
   }
80
-} catch ( Exception $e ) {
81
-  _print( "[login] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
80
+} catch (Exception $e) {
81
+  _print("[login] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
82 82
   die();
83 83
 }
84 84
 
85 85
 
86 86
 // Faz um teste de conexão com o servidor
87
-_print( 'Fazendo um ping' );
87
+_print('Fazendo um ping');
88 88
 try {
89 89
   $ret_ping = $ipa->pingToServer();
90
-  if ( $ret_ping ) {
91
-    _print( 'Pingado!' );
90
+  if ($ret_ping) {
91
+    _print('Pingado!');
92 92
   } else {
93
-    _print( 'Erro no ping!' );
93
+    _print('Erro no ping!');
94 94
   }
95
-} catch ( Exception $e ) {
96
-  _print( "[ping] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
95
+} catch (Exception $e) {
96
+  _print("[ping] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
97 97
   die();
98 98
 }
99 99
 
100 100
 
101 101
 // Obtem informações do usuário
102
-_print( "Mostrando o usuario \"$usuario\"" );
102
+_print("Mostrando o usuario \"$usuario\"");
103 103
 try {
104
-  $ret_usuario = $ipa->getUser( $usuario );
105
-  if ( TRUE == $ret_usuario ) {
106
-    _print( 'Usuario encontrado' );
107
-    var_dump( $ret_usuario );
104
+  $ret_usuario = $ipa->getUser($usuario);
105
+  if (TRUE == $ret_usuario) {
106
+    _print('Usuario encontrado');
107
+    var_dump($ret_usuario);
108 108
   } else {
109
-    _print( "Usuario $usuario nao foi encontrado");
109
+    _print("Usuario $usuario nao foi encontrado");
110 110
   }
111
-} catch ( Exception $e ) {
112
-  _print( "Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
111
+} catch (Exception $e) {
112
+  _print("Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
113 113
   die();
114 114
 }
115 115
 
116 116
 
117 117
 // Procurando um usuário através de um método genérico
118
-_print( "Procurando usuários cujo login/nome contenham \"$procurar\"" );
118
+_print("Procurando usuários cujo login/nome contenham \"$procurar\"");
119 119
 try {
120
-  $ret_procura_usuarios = $ipa->findUser( array( $procurar ) );
121
-  if ( $ret_procura_usuarios ) {
122
-    $t = count( $ret_procura_usuarios );
120
+  $ret_procura_usuarios = $ipa->findUser(array($procurar));
121
+  if ($ret_procura_usuarios) {
122
+    $t = count($ret_procura_usuarios);
123 123
     print "Encontrado $t usuários. Nomes: ";
124
-    for ($i=0; $i<$t; $i++) {
125
-      print $ret_procura_usuarios[$i]->uid[0] . " | " ;
124
+    for ($i = 0; $i<$t; $i++) {
125
+      print $ret_procura_usuarios[$i]->uid[0]." | ";
126 126
     }
127 127
     _print();
128 128
   } else {
129
-    _print( 'Nenhum usuário encontrado' );
129
+    _print('Nenhum usuário encontrado');
130 130
   }
131
-} catch ( Exception $e ) {
132
-  _print( "[consulta usuario] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
131
+} catch (Exception $e) {
132
+  _print("[consulta usuario] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
133 133
   die();
134 134
 }
135 135
 
136 136
 
137 137
 // Procura um usuario atraves de um campo identificador
138 138
 // Veja documentação do método procurarUsuarioBy() !
139
-_print( "Procurando usuarios cujo login seja \"$procurar\"" );
139
+_print("Procurando usuarios cujo login seja \"$procurar\"");
140 140
 try {
141
-	$procura_usuario_por = $ipa->findUserBy( 'uid', $procurar ); // login
141
+	$procura_usuario_por = $ipa->findUserBy('uid', $procurar); // login
142 142
 	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'mail', '[email protected]' ); // email
143 143
 	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'givenname', $procurar ); // primeiro nome
144 144
 	//$procura_usuario_por = $ipa->procurarUsuarioBy( 'cn', 'Administrator' ); // nome completo
145 145
     //$procura_usuario_por = $ipa->procurarUsuarioBy( 'in_group', 'admins' ); // usuário está no grupo
146
-    if ( $procura_usuario_por ) {
147
-      _print( 'Usuários encontrados' );
146
+    if ($procura_usuario_por) {
147
+      _print('Usuários encontrados');
148 148
       var_dump($procura_usuario_por);
149 149
     } else {
150
-      _print( 'Nenhum usuário encontrado' );
150
+      _print('Nenhum usuário encontrado');
151 151
     }
152
-} catch ( \Exception $e ) {
153
-	_print( "[procura usuario por] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
154
-	_print( "Requisicao json eh {$ipa->getJsonRequest()}" );
155
-	_print( "Resposta json eh {$ipa->getJsonResponse()}" );
152
+} catch (\Exception $e) {
153
+	_print("[procura usuario por] Excessao. Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
154
+	_print("Requisicao json eh {$ipa->getJsonRequest()}");
155
+	_print("Resposta json eh {$ipa->getJsonResponse()}");
156 156
 	die();
157 157
 }
158 158
 
159 159
 
160 160
 // Insere um novo usuario
161
-$dados_novo_usuario =  array (
161
+$dados_novo_usuario = array(
162 162
   'givenname'    => 'Richardi',
163 163
   'sn'           => 'Stallman',
164 164
   'uid'          => "stallman$random",
165 165
   'mail'         => "[email protected]",
166 166
   'userpassword' => $senha,
167 167
 );
168
-_print( "Adicionando o usuário {$dados_novo_usuario['uid']} com a senha \"$senha\"" );
168
+_print("Adicionando o usuário {$dados_novo_usuario['uid']} com a senha \"$senha\"");
169 169
 try {
170
-  $adicionar_usuario = $ipa->adicionarUsuario( $dados_novo_usuario );
171
-  if ( $adicionar_usuario ) {
172
-    _print( 'Usuario adicionado' );
170
+  $adicionar_usuario = $ipa->adicionarUsuario($dados_novo_usuario);
171
+  if ($adicionar_usuario) {
172
+    _print('Usuario adicionado');
173 173
   } else {
174
-    _print( 'Erro ao adicionar o usuario' );
174
+    _print('Erro ao adicionar o usuario');
175 175
   }
176
-} catch ( \Exception $e ) {
177
-  _print( "[criando usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
176
+} catch (\Exception $e) {
177
+  _print("[criando usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
178 178
   die();
179 179
 }
180 180
 
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 $dados_alterar_usuario = array(
184 184
   'givenname' => 'Richard',
185 185
 );
186
-_print( "Alterando o usuario {$dados_novo_usuario['uid']}" );
186
+_print("Alterando o usuario {$dados_novo_usuario['uid']}");
187 187
 try {
188
-  $alterar_usuario = $ipa->modificarUsuario( $dados_novo_usuario['uid'], $dados_alterar_usuario );
189
-  if ( $alterar_usuario ) {
190
-    _print( 'Usuario alterado' );
188
+  $alterar_usuario = $ipa->modificarUsuario($dados_novo_usuario['uid'], $dados_alterar_usuario);
189
+  if ($alterar_usuario) {
190
+    _print('Usuario alterado');
191 191
   } else {
192
-    _print( 'Erro ao alterar o usuario' );
192
+    _print('Erro ao alterar o usuario');
193 193
   }
194
-} catch ( \Exception $e ) {
195
-  _print( "[alterando usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
194
+} catch (\Exception $e) {
195
+  _print("[alterando usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
196 196
   die();
197 197
 }
198 198
 
@@ -201,49 +201,49 @@  discard block
 block discarded – undo
201 201
 $dados_alterar_usenha_suario = array(
202 202
   'userpassword' => 'batatinha123',
203 203
 );
204
-_print( "Alterando senha do usuario {$dados_novo_usuario['uid']} para {$dados_alterar_usenha_suario['userpassword']}" );
204
+_print("Alterando senha do usuario {$dados_novo_usuario['uid']} para {$dados_alterar_usenha_suario['userpassword']}");
205 205
 try {
206
-  $alterar_senha_usuario = $ipa->modificarUsuario( $dados_novo_usuario['uid'], $dados_alterar_usenha_suario );
207
-  if ( $alterar_senha_usuario ) {
208
-    _print( 'Senha alterada' );
206
+  $alterar_senha_usuario = $ipa->modificarUsuario($dados_novo_usuario['uid'], $dados_alterar_usenha_suario);
207
+  if ($alterar_senha_usuario) {
208
+    _print('Senha alterada');
209 209
   } else {
210
-    _print( 'Erro ao alterar a senha do usuario' );
210
+    _print('Erro ao alterar a senha do usuario');
211 211
   }
212
-} catch ( \Exception $e ) {
213
-  _print( "[alterando senha usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
212
+} catch (\Exception $e) {
213
+  _print("[alterando senha usuario] Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
214 214
   die();
215 215
 }
216 216
 
217 217
 
218 218
 // Adiciona um grupo
219
-_print( "Adicionando grupo \"grupo$random\"" );
219
+_print("Adicionando grupo \"grupo$random\"");
220 220
 try {
221
-  $adicionar_grupo = $ipa->adicionarGrupo( "grupo$random", "Descrição do grupo$random" );
222
-  if ( $adicionar_grupo ) {
223
-    _print( 'Grupo adicionado' );
221
+  $adicionar_grupo = $ipa->adicionarGrupo("grupo$random", "Descrição do grupo$random");
222
+  if ($adicionar_grupo) {
223
+    _print('Grupo adicionado');
224 224
   } else {
225
-    _print( 'Erro ao adicionar o grupo' );
225
+    _print('Erro ao adicionar o grupo');
226 226
   }
227
-} catch ( \Exception $e ) {
228
-  _print( "[adicionando grupo] Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
227
+} catch (\Exception $e) {
228
+  _print("[adicionando grupo] Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
229 229
   die();
230 230
 }
231 231
 
232 232
 
233 233
 // Adicionando um usuario a um grupo
234
-_print( "Adicionando o usuário \"$usuario\" ao grupo \"grupo$random\"" );
234
+_print("Adicionando o usuário \"$usuario\" ao grupo \"grupo$random\"");
235 235
 try {
236
-  $adicionar_usuario_grupo = $ipa->adicionarMembroGrupo( "grupo$random", $usuario );
237
-  if ( $adicionar_grupo ) {
238
-    _print( 'Usuarios adicionados ao grupo' );
239
-    var_dump( $adicionar_usuario_grupo );
236
+  $adicionar_usuario_grupo = $ipa->adicionarMembroGrupo("grupo$random", $usuario);
237
+  if ($adicionar_grupo) {
238
+    _print('Usuarios adicionados ao grupo');
239
+    var_dump($adicionar_usuario_grupo);
240 240
   } else {
241
-    _print( 'Erro ao adicionar usuarios ao grupo' );
241
+    _print('Erro ao adicionar usuarios ao grupo');
242 242
   }
243
-} catch ( \Exception $e ) {
244
-  _print( "[adicionando usuarios ao grupo] Mensagem: {$e->getMessage()} Código: {$e->getCode()}" );
243
+} catch (\Exception $e) {
244
+  _print("[adicionando usuarios ao grupo] Mensagem: {$e->getMessage()} Código: {$e->getCode()}");
245 245
   die();
246 246
 }
247 247
 
248 248
 
249
-_print( 'FIM' );
249
+_print('FIM');
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@
 block discarded – undo
65 65
   $ret_aut = $ipa->authenticate( $usuario, $senha );
66 66
   if ( TRUE === $ret_aut['autenticado'] ) { // usuário está autenticado
67 67
     _print( $ret_aut['mensagem'] );
68
-  }
69
-  else {
68
+  } else {
70 69
     _print( $ret_aut['mensagem'] );
71 70
     // Para debug:
72 71
     var_dump($ret_aut);
Please login to merge, or discard this patch.
examples/functions.utils.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@
 block discarded – undo
4 4
  * Print a message
5 5
  */
6 6
 function _print( $string = NULL ) {
7
-	if ( 'cli' == php_sapi_name() ) { // PHP is running in terminal
8
-		$line_end = PHP_EOL;
9
-	} else {
10
-		$line_end = '<br/>';
11
-	}
7
+  if ( 'cli' == php_sapi_name() ) { // PHP is running in terminal
8
+    $line_end = PHP_EOL;
9
+  } else {
10
+    $line_end = '<br/>';
11
+  }
12 12
 
13
-	if ( ! empty( $string ) ) {
14
-		$file   = basename( $_SERVER["PHP_SELF"] );
15
-		$output = date( 'd-m-Y_H:i:s ' ) . "[$file] $string $line_end";
16
-	} else {
17
-		$output = $line_end;
18
-	}
13
+  if ( ! empty( $string ) ) {
14
+    $file   = basename( $_SERVER["PHP_SELF"] );
15
+    $output = date( 'd-m-Y_H:i:s ' ) . "[$file] $string $line_end";
16
+  } else {
17
+    $output = $line_end;
18
+  }
19 19
 
20
-	print ( $output );
20
+  print ( $output );
21 21
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,19 +3,19 @@
 block discarded – undo
3 3
 /**
4 4
  * Print a message
5 5
  */
6
-function _print( $string = NULL ) {
7
-	if ( 'cli' == php_sapi_name() ) { // PHP is running in terminal
6
+function _print($string = NULL) {
7
+	if ('cli' == php_sapi_name()) { // PHP is running in terminal
8 8
 		$line_end = PHP_EOL;
9 9
 	} else {
10 10
 		$line_end = '<br/>';
11 11
 	}
12 12
 
13
-	if ( ! empty( $string ) ) {
14
-		$file   = basename( $_SERVER["PHP_SELF"] );
15
-		$output = date( 'd-m-Y_H:i:s ' ) . "[$file] $string $line_end";
13
+	if ( ! empty($string)) {
14
+		$file   = basename($_SERVER["PHP_SELF"]);
15
+		$output = date('d-m-Y_H:i:s ')."[$file] $string $line_end";
16 16
 	} else {
17 17
 		$output = $line_end;
18 18
 	}
19 19
 
20
-	print ( $output );
20
+	print ($output);
21 21
 }
Please login to merge, or discard this patch.
examples/snippet_debug.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2
-ini_set( 'display_errors', 1); // display errors, quando definido em tempo de execucao, não funciona para fatal erros
3
-ini_set( 'track_errors',   1);
4
-ini_set( 'html_errors',    1);
5
-error_reporting( E_ALL );
2
+ini_set('display_errors', 1); // display errors, quando definido em tempo de execucao, não funciona para fatal erros
3
+ini_set('track_errors', 1);
4
+ini_set('html_errors', 1);
5
+error_reporting(E_ALL);
6 6
 //set_error_handler( 'var_dump' );
Please login to merge, or discard this patch.
src/APIAccess/Group.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function adicionarGrupo($nome = null, $dados = array())
52 52
     {
53
-        if (!$nome || !$dados) {
53
+        if ( ! $nome || ! $dados) {
54 54
             return false;
55 55
         }
56 56
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
         // O método buildRequest() já verifica o campo 'error', que é o único relevante para este método da API
75 75
         $retorno_requisicao = $this->buildRequest('group_add', $argumentos, $opcoes_final); // retorna json e codigo http da resposta
76
-        if (!$retorno_requisicao) {
76
+        if ( ! $retorno_requisicao) {
77 77
             return false;
78 78
         }
79 79
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function adicionarMembroGrupo($nome_grupo = null, $dados = array())
99 99
     {
100
-        if (!$nome_grupo || !$dados) {
100
+        if ( ! $nome_grupo || ! $dados) {
101 101
             return false;
102 102
         }
103 103
 
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
         }
118 118
 
119 119
         $retorno_requisicao = $this->buildRequest('group_add_member', $argumentos, $opcoes_final); // retorna json e codigo http da resposta
120
-        if (!$retorno_requisicao) {
120
+        if ( ! $retorno_requisicao) {
121 121
             return false;
122 122
         }
123 123
         $json_retorno = $retorno_requisicao[0];
124
-        if (!$json_retorno->result->completed) {
124
+        if ( ! $json_retorno->result->completed) {
125 125
             $mensagem = "Erro ao inserir membros no grupo \"$nome_grupo\".";
126
-            if (!empty($json_retorno->result->failed->member->group) || !empty($json_retorno->result->failed->member->user)) {
126
+            if ( ! empty($json_retorno->result->failed->member->group) || ! empty($json_retorno->result->failed->member->user)) {
127 127
                 $mensagem .= 'Detalhes: ';
128 128
             }
129 129
 
130
-            if (!empty($json_retorno->result->failed->member->group)) {
130
+            if ( ! empty($json_retorno->result->failed->member->group)) {
131 131
                 $mensagem .= implode(' ', $json_retorno->result->failed->member->group[0]);
132 132
             }
133 133
 
134
-            if (!empty($json_retorno->result->failed->member->user)) {
134
+            if ( ! empty($json_retorno->result->failed->member->user)) {
135 135
                 $mensagem .= implode(' ', $json_retorno->result->failed->member->user[0]);
136 136
             }
137 137
 
Please login to merge, or discard this patch.
src/APIAccess/User.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function findUser($argumentos = array(), $opcoes = array())
53 53
     {
54
-        if (!is_array($argumentos) || !is_array($opcoes)) {
54
+        if ( ! is_array($argumentos) || ! is_array($opcoes)) {
55 55
             return false;
56 56
         }
57 57
 
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
         $json = $retorno_requisicao[0];
70 70
         $json_string = json_encode($json);
71 71
 
72
-        if (empty($json->result) || !isset($json->result->count)) {
72
+        if (empty($json->result) || ! isset($json->result->count)) {
73 73
             throw new \Exception("Um ou mais elementos necessários não foram encontrados na resposta json. Resposta foi \"$json_string\".");
74 74
         }
75 75
 
76
-        if ($json->result->count < 1) {
76
+        if ($json->result->count<1) {
77 77
             return false;
78 78
         }
79 79
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function findUserBy($campo = null, $valor = null)
102 102
     {
103
-        if (!$campo || !$valor) {
103
+        if ( ! $campo || ! $valor) {
104 104
             return false;
105 105
         }
106 106
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function getUser($parametros = null, $opcoes = array())
126 126
     {
127
-        if (!is_array($opcoes)) {
127
+        if ( ! is_array($opcoes)) {
128 128
             return false;
129 129
         }
130 130
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         $json = $retorno_requisicao[0];
150 150
         $json_string = json_encode($json);
151 151
 
152
-        if (!empty($json->error) && strtolower($json->error->name) == 'notfound') {
152
+        if ( ! empty($json->error) && strtolower($json->error->name) == 'notfound') {
153 153
             // usuário não encontrado
154 154
             return false;
155 155
         }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         }
160 160
 
161 161
         // #TODO remover este trecho?
162
-        if (!isset($json->result->result)) {
162
+        if ( ! isset($json->result->result)) {
163 163
             return false;
164 164
         }
165 165
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function adicionarUsuario($dados)
185 185
     {
186
-        if (!$dados || !isset($dados['uid']) || empty($dados['uid'])) {
186
+        if ( ! $dados || ! isset($dados['uid']) || empty($dados['uid'])) {
187 187
             return false;
188 188
         }
189 189
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
         // O método buildRequest() já verifica o campo 'error', que é o único relevante para este método da API
203 203
         $retorno_requisicao = $this->buildRequest('user_add', $argumentos, $opcoes_final); // retorna json e codigo http da resposta
204
-        if (!$retorno_requisicao) {
204
+        if ( ! $retorno_requisicao) {
205 205
             return false;
206 206
         }
207 207
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function modificarUsuario($login = null, $dados = array())
237 237
     {
238
-        if (!$login || !$dados) {
238
+        if ( ! $login || ! $dados) {
239 239
             return false;
240 240
         }
241 241
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
         // O método buildRequest() já verifica o campo 'error', que é o único relevante para este método da API
254 254
         $retorno_requisicao = $this->buildRequest('user_mod', $argumentos, $opcoes_final); // retorna json e codigo http da resposta
255
-        if (!$retorno_requisicao) {
255
+        if ( ! $retorno_requisicao) {
256 256
             return false;
257 257
         }
258 258
 
Please login to merge, or discard this patch.
src/autoload.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
  * @return void
32 32
  * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
33 33
  */
34
-spl_autoload_register(function ($class) {
34
+spl_autoload_register(function($class) {
35 35
 
36 36
     // project-specific namespace prefix
37 37
     $prefix = 'FreeIPA\\';
38 38
 
39 39
     // base directory for the namespace prefix
40 40
     // $base_dir = __DIR__ . '/src/';
41
-    $base_dir = __DIR__ . '/';
41
+    $base_dir = __DIR__.'/';
42 42
 
43 43
     // does the class use the namespace prefix?
44 44
     $len = strlen($prefix);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     // replace the namespace prefix with the base directory, replace namespace
54 54
     // separators with directory separators in the relative class name, append
55 55
     // with .php
56
-    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
56
+    $file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
57 57
 
58 58
     // if the file exists, require it
59 59
     if (file_exists($file)) {
Please login to merge, or discard this patch.