Completed
Pull Request — master (#3)
by
unknown
02:23
created
src/APIAccess/Connection.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * @access public
113 113
      * @sice GIT 0.1.0
114 114
      */
115
-    protected $certificate_file  = null;
115
+    protected $certificate_file = null;
116 116
 
117 117
     /**
118 118
      * @var array curl_http_header HTTP header that will be used with cURL
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      * @access protected
148 148
      * @sice GIT 0.1.0
149 149
      */
150
-    protected $user_logged  = false;
150
+    protected $user_logged = false;
151 151
     
152 152
     /**
153 153
      * @var string|null $json_request String that contains the last json request what will be (or was) sent to the server
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
      * @throws \Exception caso o método setCertificateFile() retorne false
197 197
      */
198 198
     private function __construct($server = null, $certificate = null) {
199
-        if (! function_exists('curl_init')) {
199
+        if ( ! function_exists('curl_init')) {
200 200
             throw new \Exception('Unable to find cURL');
201 201
         }
202 202
         
203
-        if ( ! empty($server) && ! $this->setIPAServer($server) ) {
203
+        if ( ! empty($server) && ! $this->setIPAServer($server)) {
204 204
             throw new \Exception("Error while validating the server");
205 205
         }
206
-        else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate) ) {
206
+        else if ( ! empty($certificate) && ! $this->setCertificateFile($certificate)) {
207 207
             throw new \Exception("Error while validating the certificate");
208 208
         }
209 209
         
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     {
258 258
         switch ($force_new) {
259 259
             case false:
260
-                if (! isset(self::$_instance)) {
260
+                if ( ! isset(self::$_instance)) {
261 261
                     self::$_instance = new self($server, $certificate);
262 262
                 }
263 263
                 $r = self::$_instance;
@@ -310,12 +310,12 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public function setIPAServer($host = null)
312 312
     {
313
-        if (empty($host) || is_null($host) || !is_string($host)) {
313
+        if (empty($host) || is_null($host) || ! is_string($host)) {
314 314
             return false;
315 315
         }
316 316
         $this->ipa_server = $host;
317
-        $this->jsonrpc_url = 'https://' . $host . '/ipa/session/json';
318
-        $this->jsonrpc_login_url = 'https://' . $host . '/ipa/session/login_password';
317
+        $this->jsonrpc_url = 'https://'.$host.'/ipa/session/json';
318
+        $this->jsonrpc_login_url = 'https://'.$host.'/ipa/session/login_password';
319 319
         return true;
320 320
     }
321 321
 
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
      */
347 347
     public function setCertificateFile($file)
348 348
     {
349
-        if (empty($file) || is_null($file) || !is_string($file)) {
349
+        if (empty($file) || is_null($file) || ! is_string($file)) {
350 350
             return false;
351
-        } else if (!file_exists($file)) {
351
+        } else if ( ! file_exists($file)) {
352 352
             throw new \Exception("Certificate file doesn't exists");
353
-        } else if (!is_readable($file)) {
353
+        } else if ( ! is_readable($file)) {
354 354
             throw new \Exception("Certificate file can't be read");
355 355
         }
356 356
         $this->certificate_file = $file;
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      */
532 532
     public function curlHaveError()
533 533
     {
534
-        return ( curl_errno($this->curl_handler) ) ? true : false;
534
+        return (curl_errno($this->curl_handler)) ? true : false;
535 535
     }
536 536
 
537 537
     /**
@@ -615,14 +615,14 @@  discard block
 block discarded – undo
615 615
             return true;
616 616
         }
617 617
         
618
-        if (!$user || !$password) {
618
+        if ( ! $user || ! $password) {
619 619
             return false;
620 620
         }
621 621
         
622
-        if (! $this->getIPAServer()) {
622
+        if ( ! $this->getIPAServer()) {
623 623
             throw new \Exception("Error while validating the server");
624 624
         }
625
-        if (! $this->getCertificateFile()) {
625
+        if ( ! $this->getCertificateFile()) {
626 626
             throw new \Exception("Error while validating the certificate");
627 627
         }
628 628
 
@@ -648,11 +648,11 @@  discard block
 block discarded – undo
648 648
         //$password = urlencode($password);
649 649
 
650 650
         curl_setopt($this->curl_handler, CURLOPT_HTTPHEADER, $this->curl_http_header);
651
-        curl_setopt($this->curl_handler, CURLOPT_URL,        $this->jsonrpc_login_url);
651
+        curl_setopt($this->curl_handler, CURLOPT_URL, $this->jsonrpc_login_url);
652 652
         curl_setopt($this->curl_handler, CURLOPT_POSTFIELDS, "user=$user&password=$password");
653 653
         // I need header for get the value for X-IPA-Rejection-Reason field
654 654
         // and as workaround_for_auth
655
-        if (! $this->curl_debug) {
655
+        if ( ! $this->curl_debug) {
656 656
             curl_setopt($this->curl_handler, CURLOPT_HEADER, true);
657 657
         }
658 658
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
         // I need header for get the value for X-IPA-Rejection-Reason field
672 672
         // and as workaround_for_auth
673
-        if (!$this->curl_debug) {
673
+        if ( ! $this->curl_debug) {
674 674
             curl_setopt($this->curl_handler, CURLOPT_HEADER, false);
675 675
         }
676 676
 
@@ -695,15 +695,15 @@  discard block
 block discarded – undo
695 695
                 $auth_info['message'] .= 'Unable to find user in the server. ';
696 696
             } else {
697 697
                 $auth_info['message'] .= 'Generic error in authentication. ';
698
-                if (! empty($ipa_error_description)) {
699
-                    $auth_info['message'] .= "The server returned \"" . $ipa_error_description . "\". ";
698
+                if ( ! empty($ipa_error_description)) {
699
+                    $auth_info['message'] .= "The server returned \"".$ipa_error_description."\". ";
700 700
                 }
701 701
             }
702 702
         } else if ('200' != $auth_info['http_code']) {
703 703
             $auth_info['authenticate'] = false;
704
-            $auth_info['message'] = "The response returned the HTTP code \"" . $auth_info['http_code'] . "\" that is not acceptable. ";
705
-            if (!empty($ipa_error_description)) {
706
-                $auth_info['message'] .= "The server returned \"" . $ipa_error_description . "\". ";
704
+            $auth_info['message'] = "The response returned the HTTP code \"".$auth_info['http_code']."\" that is not acceptable. ";
705
+            if ( ! empty($ipa_error_description)) {
706
+                $auth_info['message'] .= "The server returned \"".$ipa_error_description."\". ";
707 707
             }
708 708
         } else {
709 709
             $auth_info['authenticate'] = true;
@@ -768,11 +768,11 @@  discard block
 block discarded – undo
768 768
      */
769 769
     public function isAssociativeArray($var, $force = true)
770 770
     {
771
-        if (!is_array($var)) {
771
+        if ( ! is_array($var)) {
772 772
             return false;
773 773
         }
774 774
 
775
-        if (!empty($var) || $force) {
775
+        if ( ! empty($var) || $force) {
776 776
             return array_diff_key($var, array_keys(array_keys($var)));
777 777
         }
778 778
 
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
      */
793 793
     public function buildJsonRequest($method = null, $args = array(), $options = array())
794 794
     {
795
-        if (!$method || !is_array($args) || !$this->isAssociativeArray($options, false)) {
795
+        if ( ! $method || ! is_array($args) || ! $this->isAssociativeArray($options, false)) {
796 796
             return false;
797 797
         }
798 798
 
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
         );
822 822
 
823 823
         // JSON_PRETTY_PRINT constant unavaiable in PHP < 5.4.0
824
-        if (!defined('JSON_PRETTY_PRINT')) {define('JSON_PRETTY_PRINT', 128);}
824
+        if ( ! defined('JSON_PRETTY_PRINT')) {define('JSON_PRETTY_PRINT', 128); }
825 825
 
826 826
         $this->json_request = json_encode($return, JSON_PRETTY_PRINT);
827 827
         return $this->json_request;
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
      */
854 854
     public function buildRequest($method = null, $params = array(), $options = array(), $exceptionInError = true)
855 855
     {
856
-        if (!$this->userLogged()) {
856
+        if ( ! $this->userLogged()) {
857 857
             throw new \Exception('User is not logged in');
858 858
         }
859 859
 
@@ -866,10 +866,10 @@  discard block
 block discarded – undo
866 866
             CURLOPT_URL => $this->jsonrpc_url,
867 867
             CURLOPT_POSTFIELDS => $json,
868 868
             CURLOPT_HTTPHEADER => array(
869
-                'referer:https://' . $this->ipa_server . '/ipa/ui/index.html',
869
+                'referer:https://'.$this->ipa_server.'/ipa/ui/index.html',
870 870
                 'Content-Type:application/json',
871 871
                 'Accept:applicaton/json',
872
-                'Content-Length: ' . strlen($json),
872
+                'Content-Length: '.strlen($json),
873 873
             ),
874 874
         );
875 875
 
@@ -884,15 +884,15 @@  discard block
 block discarded – undo
884 884
         if ($this->curlHaveError()) {
885 885
             throw new \Exception('Error in cURL request');
886 886
         }
887
-        if (!$response_http_code || '200' != $response_http_code) {
887
+        if ( ! $response_http_code || '200' != $response_http_code) {
888 888
             throw new \Exception("The value \"$response_http_code\" is not a valid response code");
889 889
         }
890 890
         if (empty($json_retorno) || empty($object_json_returned)) {
891 891
             #TODO criar exceção para passar os dados do erro ao inves do json puro. Vide arquivo exemplos_retornos.txt
892 892
             throw new \Exception("Erro in json return. Value is ${json_retorno}");
893 893
         }
894
-        if ($exceptionInError && !empty($object_json_returned->error)) {
895
-            throw new \Exception("Error in request. Details: " . $object_json_returned->error->message, $object_json_returned->error->code);
894
+        if ($exceptionInError && ! empty($object_json_returned->error)) {
895
+            throw new \Exception("Error in request. Details: ".$object_json_returned->error->message, $object_json_returned->error->code);
896 896
         }
897 897
 
898 898
         return array($object_json_returned, $response_http_code);
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
     {
912 912
         $ret = $this->buildRequest('ping'); // receives json and http response code
913 913
         $json = $ret[0];
914
-        if (!empty($json->error) || empty($json->result) || empty($json->result->summary) || !is_string($json->result->summary)) {
914
+        if ( ! empty($json->error) || empty($json->result) || empty($json->result->summary) || ! is_string($json->result->summary)) {
915 915
             return false;
916 916
         }
917 917
         if ($return_string) {
Please login to merge, or discard this patch.