@@ -61,6 +61,10 @@ |
||
| 61 | 61 | * @throws Exception|PagSeguroServiceException |
| 62 | 62 | * @throws Exception |
| 63 | 63 | */ |
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param boolean $onlyCheckoutCode |
|
| 67 | + */ |
|
| 64 | 68 | public static function createCheckoutRequest( |
| 65 | 69 | PagSeguroCredentials $credentials, |
| 66 | 70 | PagSeguroPaymentRequest $paymentRequest, |
@@ -27,107 +27,107 @@ |
||
| 27 | 27 | class PagSeguroPaymentService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /*** |
|
| 30 | + /*** |
|
| 31 | 31 | * |
| 32 | 32 | */ |
| 33 | - const SERVICE_NAME = 'paymentService'; |
|
| 33 | + const SERVICE_NAME = 'paymentService'; |
|
| 34 | 34 | |
| 35 | - /*** |
|
| 35 | + /*** |
|
| 36 | 36 | * @param PagSeguroConnectionData $connectionData |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
| 40 | - { |
|
| 41 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 42 | - } |
|
| 39 | + private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
|
| 40 | + { |
|
| 41 | + return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /*** |
|
| 44 | + /*** |
|
| 45 | 45 | * @param PagSeguroConnectionData $connectionData |
| 46 | 46 | * @param $code |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | - private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
|
| 50 | - { |
|
| 51 | - return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // createCheckoutRequest is the actual implementation of the Register method |
|
| 55 | - // This separation serves as test hook to validate the Uri |
|
| 56 | - // against the code returned by the service |
|
| 57 | - /*** |
|
| 49 | + private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
|
| 50 | + { |
|
| 51 | + return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // createCheckoutRequest is the actual implementation of the Register method |
|
| 55 | + // This separation serves as test hook to validate the Uri |
|
| 56 | + // against the code returned by the service |
|
| 57 | + /*** |
|
| 58 | 58 | * @param PagSeguroCredentials $credentials |
| 59 | 59 | * @param PagSeguroPaymentRequest $paymentRequest |
| 60 | 60 | * @return bool|string |
| 61 | 61 | * @throws Exception|PagSeguroServiceException |
| 62 | 62 | * @throws Exception |
| 63 | 63 | */ |
| 64 | - public static function createCheckoutRequest( |
|
| 65 | - PagSeguroCredentials $credentials, |
|
| 66 | - PagSeguroPaymentRequest $paymentRequest, |
|
| 67 | - $onlyCheckoutCode |
|
| 68 | - ) { |
|
| 69 | - |
|
| 70 | - LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 71 | - |
|
| 72 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 73 | - |
|
| 74 | - try { |
|
| 75 | - |
|
| 76 | - $connection = new PagSeguroHttpConnection(); |
|
| 77 | - $connection->post( |
|
| 78 | - self::buildCheckoutRequestUrl($connectionData), |
|
| 79 | - PagSeguroPaymentParser::getData($paymentRequest), |
|
| 80 | - $connectionData->getServiceTimeout(), |
|
| 81 | - $connectionData->getCharset() |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 85 | - |
|
| 86 | - switch ($httpStatus->getType()) { |
|
| 87 | - |
|
| 88 | - case 'OK': |
|
| 89 | - $PaymentParserData = PagSeguroPaymentParser::readSuccessXml($connection->getResponse()); |
|
| 90 | - |
|
| 91 | - if ($onlyCheckoutCode) { |
|
| 92 | - $paymentReturn = $PaymentParserData->getCode(); |
|
| 93 | - } else { |
|
| 94 | - $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
|
| 95 | - } |
|
| 96 | - LogPagSeguro::info( |
|
| 97 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 98 | - $PaymentParserData->getCode() |
|
| 99 | - ); |
|
| 100 | - break; |
|
| 101 | - |
|
| 102 | - case 'BAD_REQUEST': |
|
| 103 | - $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
|
| 104 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 105 | - LogPagSeguro::error( |
|
| 106 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 107 | - $e->getOneLineMessage() |
|
| 108 | - ); |
|
| 109 | - throw $e; |
|
| 110 | - break; |
|
| 111 | - |
|
| 112 | - default: |
|
| 113 | - $e = new PagSeguroServiceException($httpStatus); |
|
| 114 | - LogPagSeguro::error( |
|
| 115 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 116 | - $e->getOneLineMessage() |
|
| 117 | - ); |
|
| 118 | - throw $e; |
|
| 119 | - break; |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - return (isset($paymentReturn) ? $paymentReturn : false); |
|
| 123 | - |
|
| 124 | - } catch (PagSeguroServiceException $e) { |
|
| 125 | - throw $e; |
|
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 129 | - throw $e; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - } |
|
| 64 | + public static function createCheckoutRequest( |
|
| 65 | + PagSeguroCredentials $credentials, |
|
| 66 | + PagSeguroPaymentRequest $paymentRequest, |
|
| 67 | + $onlyCheckoutCode |
|
| 68 | + ) { |
|
| 69 | + |
|
| 70 | + LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 71 | + |
|
| 72 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 73 | + |
|
| 74 | + try { |
|
| 75 | + |
|
| 76 | + $connection = new PagSeguroHttpConnection(); |
|
| 77 | + $connection->post( |
|
| 78 | + self::buildCheckoutRequestUrl($connectionData), |
|
| 79 | + PagSeguroPaymentParser::getData($paymentRequest), |
|
| 80 | + $connectionData->getServiceTimeout(), |
|
| 81 | + $connectionData->getCharset() |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 85 | + |
|
| 86 | + switch ($httpStatus->getType()) { |
|
| 87 | + |
|
| 88 | + case 'OK': |
|
| 89 | + $PaymentParserData = PagSeguroPaymentParser::readSuccessXml($connection->getResponse()); |
|
| 90 | + |
|
| 91 | + if ($onlyCheckoutCode) { |
|
| 92 | + $paymentReturn = $PaymentParserData->getCode(); |
|
| 93 | + } else { |
|
| 94 | + $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
|
| 95 | + } |
|
| 96 | + LogPagSeguro::info( |
|
| 97 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 98 | + $PaymentParserData->getCode() |
|
| 99 | + ); |
|
| 100 | + break; |
|
| 101 | + |
|
| 102 | + case 'BAD_REQUEST': |
|
| 103 | + $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
|
| 104 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 105 | + LogPagSeguro::error( |
|
| 106 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 107 | + $e->getOneLineMessage() |
|
| 108 | + ); |
|
| 109 | + throw $e; |
|
| 110 | + break; |
|
| 111 | + |
|
| 112 | + default: |
|
| 113 | + $e = new PagSeguroServiceException($httpStatus); |
|
| 114 | + LogPagSeguro::error( |
|
| 115 | + "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 116 | + $e->getOneLineMessage() |
|
| 117 | + ); |
|
| 118 | + throw $e; |
|
| 119 | + break; |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + return (isset($paymentReturn) ? $paymentReturn : false); |
|
| 123 | + |
|
| 124 | + } catch (PagSeguroServiceException $e) { |
|
| 125 | + throw $e; |
|
| 126 | + } |
|
| 127 | + catch (Exception $e) { |
|
| 128 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 129 | + throw $e; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | private static function buildCheckoutRequestUrl(PagSeguroConnectionData $connectionData) |
| 40 | 40 | { |
| 41 | - return $connectionData->getServiceUrl() . '/?' . $connectionData->getCredentialsUrlQuery(); |
|
| 41 | + return $connectionData->getServiceUrl().'/?'.$connectionData->getCredentialsUrlQuery(); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /*** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private static function buildCheckoutUrl(PagSeguroConnectionData $connectionData, $code) |
| 50 | 50 | { |
| 51 | - return $connectionData->getPaymentUrl() . $connectionData->getResource('checkoutUrl') . "?code=$code"; |
|
| 51 | + return $connectionData->getPaymentUrl().$connectionData->getResource('checkoutUrl')."?code=$code"; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // createCheckoutRequest is the actual implementation of the Register method |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $onlyCheckoutCode |
| 68 | 68 | ) { |
| 69 | 69 | |
| 70 | - LogPagSeguro::info("PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - begin"); |
|
| 70 | + LogPagSeguro::info("PagSeguroPaymentService.Register(".$paymentRequest->toString().") - begin"); |
|
| 71 | 71 | |
| 72 | 72 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
| 73 | 73 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $paymentReturn = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); |
| 95 | 95 | } |
| 96 | 96 | LogPagSeguro::info( |
| 97 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . |
|
| 97 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - end {1}". |
|
| 98 | 98 | $PaymentParserData->getCode() |
| 99 | 99 | ); |
| 100 | 100 | break; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $errors = PagSeguroPaymentParser::readErrors($connection->getResponse()); |
| 104 | 104 | $e = new PagSeguroServiceException($httpStatus, $errors); |
| 105 | 105 | LogPagSeguro::error( |
| 106 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 106 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - error ". |
|
| 107 | 107 | $e->getOneLineMessage() |
| 108 | 108 | ); |
| 109 | 109 | throw $e; |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | default: |
| 113 | 113 | $e = new PagSeguroServiceException($httpStatus); |
| 114 | 114 | LogPagSeguro::error( |
| 115 | - "PagSeguroPaymentService.Register(" . $paymentRequest->toString() . ") - error " . |
|
| 115 | + "PagSeguroPaymentService.Register(".$paymentRequest->toString().") - error ". |
|
| 116 | 116 | $e->getOneLineMessage() |
| 117 | 117 | ); |
| 118 | 118 | throw $e; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | throw $e; |
| 126 | 126 | } |
| 127 | 127 | catch (Exception $e) { |
| 128 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 128 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
| 129 | 129 | throw $e; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -123,8 +123,7 @@ |
||
| 123 | 123 | |
| 124 | 124 | } catch (PagSeguroServiceException $e) { |
| 125 | 125 | throw $e; |
| 126 | - } |
|
| 127 | - catch (Exception $e) { |
|
| 126 | + } catch (Exception $e) { |
|
| 128 | 127 | LogPagSeguro::error("Exception: " . $e->getMessage()); |
| 129 | 128 | throw $e; |
| 130 | 129 | } |
@@ -29,6 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | const SERVICE_NAME = 'refundService'; |
| 31 | 31 | |
| 32 | + /** |
|
| 33 | + * @param PagSeguroConnectionData $connectionData |
|
| 34 | + */ |
|
| 32 | 35 | private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
| 33 | 36 | { |
| 34 | 37 | if (is_null($refundValue)) { |
@@ -40,6 +43,10 @@ discard block |
||
| 40 | 43 | } |
| 41 | 44 | } |
| 42 | 45 | |
| 46 | + /** |
|
| 47 | + * @param string $transactionCode |
|
| 48 | + * @param string $refundValue |
|
| 49 | + */ |
|
| 43 | 50 | public static function createRefundRequest( |
| 44 | 51 | PagSeguroCredentials $credentials, |
| 45 | 52 | $transactionCode, |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
| 33 | 33 | { |
| 34 | 34 | if (is_null($refundValue)) { |
| 35 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | - . "&transactionCode=" . $transactionCode; |
|
| 35 | + return $connectionData->getServiceUrl().'?'.$connectionData->getCredentialsUrlQuery() |
|
| 36 | + . "&transactionCode=".$transactionCode; |
|
| 37 | 37 | } else { |
| 38 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | - . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 38 | + return $connectionData->getServiceUrl().'?'.$connectionData->getCredentialsUrlQuery() |
|
| 39 | + . "&transactionCode=".$transactionCode."&refundValue=".$refundValue; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | PagSeguroCredentials $credentials, |
| 45 | 45 | $transactionCode, |
| 46 | 46 | $refundValue = null |
| 47 | - ){ |
|
| 47 | + ) { |
|
| 48 | 48 | |
| 49 | 49 | LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
| 50 | 50 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
| 80 | 80 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 81 | 81 | LogPagSeguro::error( |
| 82 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 82 | + "PagSeguroRefundService.createRefundRequest() - error ". |
|
| 83 | 83 | $err->getOneLineMessage() |
| 84 | 84 | ); |
| 85 | 85 | throw $err; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | default: |
| 88 | 88 | $err = new PagSeguroServiceException($httpStatus); |
| 89 | 89 | LogPagSeguro::error( |
| 90 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 90 | + "PagSeguroRefundService.createRefundRequest() - error ". |
|
| 91 | 91 | $err->getOneLineMessage() |
| 92 | 92 | ); |
| 93 | 93 | throw $err; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } catch (PagSeguroServiceException $err) { |
| 99 | 99 | throw $err; |
| 100 | 100 | } catch (Exception $err) { |
| 101 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 101 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 102 | 102 | throw $err; |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -27,79 +27,79 @@ |
||
| 27 | 27 | class PagSeguroRefundService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - const SERVICE_NAME = 'refundService'; |
|
| 30 | + const SERVICE_NAME = 'refundService'; |
|
| 31 | 31 | |
| 32 | - private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
|
| 33 | - { |
|
| 34 | - if (is_null($refundValue)) { |
|
| 35 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | - . "&transactionCode=" . $transactionCode; |
|
| 37 | - } else { |
|
| 38 | - return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | - . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 40 | - } |
|
| 41 | - } |
|
| 32 | + private static function buildRefundURL($connectionData, $transactionCode, $refundValue = null) |
|
| 33 | + { |
|
| 34 | + if (is_null($refundValue)) { |
|
| 35 | + return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 36 | + . "&transactionCode=" . $transactionCode; |
|
| 37 | + } else { |
|
| 38 | + return $connectionData->getServiceUrl() . '?' . $connectionData->getCredentialsUrlQuery() |
|
| 39 | + . "&transactionCode=" . $transactionCode . "&refundValue=" . $refundValue; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public static function createRefundRequest( |
|
| 44 | - PagSeguroCredentials $credentials, |
|
| 45 | - $transactionCode, |
|
| 46 | - $refundValue = null |
|
| 47 | - ){ |
|
| 43 | + public static function createRefundRequest( |
|
| 44 | + PagSeguroCredentials $credentials, |
|
| 45 | + $transactionCode, |
|
| 46 | + $refundValue = null |
|
| 47 | + ){ |
|
| 48 | 48 | |
| 49 | - LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
|
| 50 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 49 | + LogPagSeguro::info("PagSeguroRefundService.Register(".$transactionCode.") - begin"); |
|
| 50 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 51 | 51 | |
| 52 | - if (is_null($refundValue)) { |
|
| 53 | - $url = self::buildRefundURL($connectionData, $transactionCode); |
|
| 54 | - } else { |
|
| 55 | - $url = self::buildRefundURL($connectionData, $transactionCode, $refundValue); |
|
| 56 | - } |
|
| 52 | + if (is_null($refundValue)) { |
|
| 53 | + $url = self::buildRefundURL($connectionData, $transactionCode); |
|
| 54 | + } else { |
|
| 55 | + $url = self::buildRefundURL($connectionData, $transactionCode, $refundValue); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - try { |
|
| 58 | + try { |
|
| 59 | 59 | |
| 60 | - $connection = new PagSeguroHttpConnection(); |
|
| 61 | - $connection->post( |
|
| 62 | - $url, |
|
| 63 | - array(), |
|
| 64 | - $connectionData->getServiceTimeout(), |
|
| 65 | - $connectionData->getCharset() |
|
| 66 | - ); |
|
| 60 | + $connection = new PagSeguroHttpConnection(); |
|
| 61 | + $connection->post( |
|
| 62 | + $url, |
|
| 63 | + array(), |
|
| 64 | + $connectionData->getServiceTimeout(), |
|
| 65 | + $connectionData->getCharset() |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 68 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 69 | 69 | |
| 70 | - switch ($httpStatus->getType()) { |
|
| 71 | - case 'OK': |
|
| 70 | + switch ($httpStatus->getType()) { |
|
| 71 | + case 'OK': |
|
| 72 | 72 | |
| 73 | - $result = PagSeguroRefundParser::readSuccessXml($connection->getResponse()); |
|
| 74 | - LogPagSeguro::info( |
|
| 75 | - "PagSeguroRefundService.createRefundRequest(".$result.") - end " |
|
| 76 | - ); |
|
| 77 | - break; |
|
| 78 | - case 'BAD_REQUEST': |
|
| 79 | - $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
|
| 80 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | - LogPagSeguro::error( |
|
| 82 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 83 | - $err->getOneLineMessage() |
|
| 84 | - ); |
|
| 85 | - throw $err; |
|
| 86 | - break; |
|
| 87 | - default: |
|
| 88 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 89 | - LogPagSeguro::error( |
|
| 90 | - "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 91 | - $err->getOneLineMessage() |
|
| 92 | - ); |
|
| 93 | - throw $err; |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - return isset($result) ? $result : false; |
|
| 73 | + $result = PagSeguroRefundParser::readSuccessXml($connection->getResponse()); |
|
| 74 | + LogPagSeguro::info( |
|
| 75 | + "PagSeguroRefundService.createRefundRequest(".$result.") - end " |
|
| 76 | + ); |
|
| 77 | + break; |
|
| 78 | + case 'BAD_REQUEST': |
|
| 79 | + $errors = PagSeguroRefundParser::readErrors($connection->getResponse()); |
|
| 80 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | + LogPagSeguro::error( |
|
| 82 | + "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 83 | + $err->getOneLineMessage() |
|
| 84 | + ); |
|
| 85 | + throw $err; |
|
| 86 | + break; |
|
| 87 | + default: |
|
| 88 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 89 | + LogPagSeguro::error( |
|
| 90 | + "PagSeguroRefundService.createRefundRequest() - error " . |
|
| 91 | + $err->getOneLineMessage() |
|
| 92 | + ); |
|
| 93 | + throw $err; |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + return isset($result) ? $result : false; |
|
| 97 | 97 | |
| 98 | - } catch (PagSeguroServiceException $err) { |
|
| 99 | - throw $err; |
|
| 100 | - } catch (Exception $err) { |
|
| 101 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 102 | - throw $err; |
|
| 103 | - } |
|
| 104 | - } |
|
| 98 | + } catch (PagSeguroServiceException $err) { |
|
| 99 | + throw $err; |
|
| 100 | + } catch (Exception $err) { |
|
| 101 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 102 | + throw $err; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | \ No newline at end of file |
@@ -44,6 +44,10 @@ |
||
| 44 | 44 | * @throws Exception|PagSeguroServiceException |
| 45 | 45 | * @throws Exception |
| 46 | 46 | */ |
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param PagSeguroAccountCredentials $credentials |
|
| 50 | + */ |
|
| 47 | 51 | public static function getSession($credentials) |
| 48 | 52 | { |
| 49 | 53 | $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private static function buildSessionURL($connectionData) |
| 36 | 36 | { |
| 37 | - return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 37 | + return $connectionData->getWebserviceUrl().$connectionData->getSessionUrl(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /*** |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
| 50 | 50 | |
| 51 | - $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 51 | + $url = self::buildSessionURL($connectionData)."?".$connectionData->getCredentialsUrlQuery(); |
|
| 52 | 52 | |
| 53 | 53 | try { |
| 54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | return $session->getId(); |
| 72 | 72 | |
| 73 | 73 | LogPagSeguro::info( |
| 74 | - "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 74 | + "PagSeguroSessionService.getSession()(".$session->toString().") - end {1}" |
|
| 75 | 75 | ); |
| 76 | 76 | break; |
| 77 | 77 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
| 80 | 80 | $e = new PagSeguroServiceException($httpStatus, $errors); |
| 81 | 81 | LogPagSeguro::error( |
| 82 | - "PagSeguroSessionService.getSession() - error " . |
|
| 82 | + "PagSeguroSessionService.getSession() - error ". |
|
| 83 | 83 | $e->getOneLineMessage() |
| 84 | 84 | ); |
| 85 | 85 | throw $e; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $e = new PagSeguroServiceException($httpStatus); |
| 91 | 91 | LogPagSeguro::error( |
| 92 | - "PagSeguroSessionService.getSession() - error " . |
|
| 92 | + "PagSeguroSessionService.getSession() - error ". |
|
| 93 | 93 | $e->getOneLineMessage() |
| 94 | 94 | ); |
| 95 | 95 | throw $e; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | } catch (PagSeguroServiceException $e) { |
| 99 | 99 | throw $e; |
| 100 | 100 | } catch (Exception $e) { |
| 101 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 101 | + LogPagSeguro::error("Exception: ".$e->getMessage()); |
|
| 102 | 102 | throw $e; |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -27,80 +27,80 @@ |
||
| 27 | 27 | class PagSeguroSessionService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /*** |
|
| 30 | + /*** |
|
| 31 | 31 | * Build URL for get session. |
| 32 | 32 | * @param PagSeguroConnectionData $connectionData |
| 33 | 33 | * @return string session URL |
| 34 | 34 | */ |
| 35 | - private static function buildSessionURL($connectionData) |
|
| 36 | - { |
|
| 37 | - return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 38 | - } |
|
| 35 | + private static function buildSessionURL($connectionData) |
|
| 36 | + { |
|
| 37 | + return $connectionData->getWebserviceUrl() . $connectionData->getSessionUrl(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /*** |
|
| 40 | + /*** |
|
| 41 | 41 | * Get session for direct payment from webservice |
| 42 | 42 | * @param $credentials PagSeguroAccountCredentials |
| 43 | 43 | * @return bool|string |
| 44 | 44 | * @throws Exception|PagSeguroServiceException |
| 45 | 45 | * @throws Exception |
| 46 | 46 | */ |
| 47 | - public static function getSession($credentials) |
|
| 48 | - { |
|
| 49 | - $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
|
| 47 | + public static function getSession($credentials) |
|
| 48 | + { |
|
| 49 | + $connectionData = new PagSeguroConnectionData($credentials, 'sessionService'); |
|
| 50 | 50 | |
| 51 | - $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 51 | + $url = self::buildSessionURL($connectionData) . "?" . $connectionData->getCredentialsUrlQuery(); |
|
| 52 | 52 | |
| 53 | - try { |
|
| 53 | + try { |
|
| 54 | 54 | |
| 55 | - $connection = new PagSeguroHttpConnection(); |
|
| 56 | - $connection->post( |
|
| 57 | - $url, |
|
| 58 | - array(), |
|
| 59 | - $connectionData->getServiceTimeout(), |
|
| 60 | - $connectionData->getCharset() |
|
| 61 | - ); |
|
| 55 | + $connection = new PagSeguroHttpConnection(); |
|
| 56 | + $connection->post( |
|
| 57 | + $url, |
|
| 58 | + array(), |
|
| 59 | + $connectionData->getServiceTimeout(), |
|
| 60 | + $connectionData->getCharset() |
|
| 61 | + ); |
|
| 62 | 62 | |
| 63 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 63 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 64 | 64 | |
| 65 | - switch ($httpStatus->getType()) { |
|
| 65 | + switch ($httpStatus->getType()) { |
|
| 66 | 66 | |
| 67 | - case 'OK': |
|
| 67 | + case 'OK': |
|
| 68 | 68 | |
| 69 | - $session = PagSeguroSessionParser::readResult($connection->getResponse()); |
|
| 69 | + $session = PagSeguroSessionParser::readResult($connection->getResponse()); |
|
| 70 | 70 | |
| 71 | - return $session->getId(); |
|
| 71 | + return $session->getId(); |
|
| 72 | 72 | |
| 73 | - LogPagSeguro::info( |
|
| 74 | - "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 75 | - ); |
|
| 76 | - break; |
|
| 73 | + LogPagSeguro::info( |
|
| 74 | + "PagSeguroSessionService.getSession()(" . $session->toString() . ") - end {1}" |
|
| 75 | + ); |
|
| 76 | + break; |
|
| 77 | 77 | |
| 78 | - case 'BAD_REQUEST': |
|
| 79 | - $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
|
| 80 | - $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | - LogPagSeguro::error( |
|
| 82 | - "PagSeguroSessionService.getSession() - error " . |
|
| 83 | - $e->getOneLineMessage() |
|
| 84 | - ); |
|
| 85 | - throw $e; |
|
| 86 | - break; |
|
| 78 | + case 'BAD_REQUEST': |
|
| 79 | + $errors = PagSeguroSessionParser::readErrors($connection->getStatus()); |
|
| 80 | + $e = new PagSeguroServiceException($httpStatus, $errors); |
|
| 81 | + LogPagSeguro::error( |
|
| 82 | + "PagSeguroSessionService.getSession() - error " . |
|
| 83 | + $e->getOneLineMessage() |
|
| 84 | + ); |
|
| 85 | + throw $e; |
|
| 86 | + break; |
|
| 87 | 87 | |
| 88 | - default: |
|
| 88 | + default: |
|
| 89 | 89 | |
| 90 | - $e = new PagSeguroServiceException($httpStatus); |
|
| 91 | - LogPagSeguro::error( |
|
| 92 | - "PagSeguroSessionService.getSession() - error " . |
|
| 93 | - $e->getOneLineMessage() |
|
| 94 | - ); |
|
| 95 | - throw $e; |
|
| 96 | - break; |
|
| 97 | - } |
|
| 98 | - } catch (PagSeguroServiceException $e) { |
|
| 99 | - throw $e; |
|
| 100 | - } catch (Exception $e) { |
|
| 101 | - LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 102 | - throw $e; |
|
| 103 | - } |
|
| 104 | - } |
|
| 90 | + $e = new PagSeguroServiceException($httpStatus); |
|
| 91 | + LogPagSeguro::error( |
|
| 92 | + "PagSeguroSessionService.getSession() - error " . |
|
| 93 | + $e->getOneLineMessage() |
|
| 94 | + ); |
|
| 95 | + throw $e; |
|
| 96 | + break; |
|
| 97 | + } |
|
| 98 | + } catch (PagSeguroServiceException $e) { |
|
| 99 | + throw $e; |
|
| 100 | + } catch (Exception $e) { |
|
| 101 | + LogPagSeguro::error("Exception: " . $e->getMessage()); |
|
| 102 | + throw $e; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @param PagSeguroConnectionData $connectionData |
| 39 | - * @param $transactionCode |
|
| 39 | + * @param string $transactionCode |
|
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | 42 | private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | * @param PagSeguroCredentials $credentials |
| 263 | - * @param $reference |
|
| 264 | - * @param null $initialDate |
|
| 265 | - * @param null $finalDate |
|
| 266 | - * @param null $pageNumber |
|
| 267 | - * @param null $maxPageResults |
|
| 263 | + * @param string $reference |
|
| 264 | + * @param string $initialDate |
|
| 265 | + * @param string $finalDate |
|
| 266 | + * @param integer $pageNumber |
|
| 267 | + * @param integer $maxPageResults |
|
| 268 | 268 | * @throws Exception |
| 269 | 269 | * @throws PagSeguroServiceException |
| 270 | 270 | */ |
@@ -314,10 +314,10 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | - * @param $pageNumber |
|
| 318 | - * @param $maxPageResults |
|
| 319 | - * @param $initialDate |
|
| 320 | - * @param null $finalDate |
|
| 317 | + * @param integer|null $pageNumber |
|
| 318 | + * @param integer|null $maxPageResults |
|
| 319 | + * @param string $initialDate |
|
| 320 | + * @param string|null $finalDate |
|
| 321 | 321 | * @return array |
| 322 | 322 | */ |
| 323 | 323 | private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | - * @param $connection |
|
| 338 | - * @param $code |
|
| 337 | + * @param PagSeguroHttpConnection $connection |
|
| 338 | + * @param string $code |
|
| 339 | 339 | * @return bool|PagSeguroTransaction |
| 340 | 340 | * @throws PagSeguroServiceException |
| 341 | 341 | */ |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
| 379 | - * @param $connection |
|
| 380 | - * @param null $initialDate |
|
| 381 | - * @param null $finalDate |
|
| 379 | + * @param PagSeguroHttpConnection $connection |
|
| 380 | + * @param string $initialDate |
|
| 381 | + * @param string|null $finalDate |
|
| 382 | 382 | * @return bool|PagSeguroTransactionSearchResult |
| 383 | 383 | * @throws PagSeguroServiceException |
| 384 | 384 | */ |
@@ -27,96 +27,96 @@ discard block |
||
| 27 | 27 | class PagSeguroTransactionSearchService |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - const SERVICE_NAME = 'transactionSearchService'; |
|
| 34 | - |
|
| 35 | - private static $logService; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param PagSeguroConnectionData $connectionData |
|
| 39 | - * @param $transactionCode |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
|
| 43 | - { |
|
| 44 | - $url = $connectionData->getServiceUrl('v3'); |
|
| 45 | - return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param PagSeguroConnectionData $connectionData |
|
| 50 | - * @param array $searchParams |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - private static function buildSearchUrlByDate(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 54 | - { |
|
| 55 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 56 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 57 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 58 | - if ($searchParams['pageNumber'] != null) { |
|
| 59 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 60 | - } |
|
| 61 | - if ($searchParams['maxPageResults'] != null) { |
|
| 62 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 63 | - } |
|
| 64 | - return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 65 | - "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param PagSeguroConnectionData $connectionData |
|
| 70 | - * @param array $searchParams |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - private static function buildSearchUrlAbandoned(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 74 | - { |
|
| 75 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 76 | - |
|
| 77 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 78 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 79 | - if ($searchParams['pageNumber'] != null) { |
|
| 80 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 81 | - } |
|
| 82 | - if ($searchParams['maxPageResults'] != null) { |
|
| 83 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 84 | - } |
|
| 85 | - return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 86 | - "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param PagSeguroConnectionData $connectionData |
|
| 91 | - * @param $reference |
|
| 92 | - * @param null $searchParams |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - private static function buildSearchUrlByReference( |
|
| 96 | - PagSeguroConnectionData $connectionData, |
|
| 97 | - $reference, |
|
| 98 | - $searchParams = null |
|
| 99 | - ){ |
|
| 100 | - $url = $connectionData->getServiceUrl('v2'); |
|
| 101 | - if ($searchParams == null) { |
|
| 102 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 103 | - } else { |
|
| 104 | - |
|
| 105 | - $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 106 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 107 | - if ($searchParams['pageNumber'] != null) { |
|
| 108 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 109 | - } |
|
| 110 | - if ($searchParams['maxPageResults'] != null) { |
|
| 111 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 115 | - . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /*** |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + const SERVICE_NAME = 'transactionSearchService'; |
|
| 34 | + |
|
| 35 | + private static $logService; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param PagSeguroConnectionData $connectionData |
|
| 39 | + * @param $transactionCode |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
|
| 43 | + { |
|
| 44 | + $url = $connectionData->getServiceUrl('v3'); |
|
| 45 | + return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param PagSeguroConnectionData $connectionData |
|
| 50 | + * @param array $searchParams |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + private static function buildSearchUrlByDate(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 54 | + { |
|
| 55 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 56 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 57 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 58 | + if ($searchParams['pageNumber'] != null) { |
|
| 59 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 60 | + } |
|
| 61 | + if ($searchParams['maxPageResults'] != null) { |
|
| 62 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 63 | + } |
|
| 64 | + return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 65 | + "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param PagSeguroConnectionData $connectionData |
|
| 70 | + * @param array $searchParams |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + private static function buildSearchUrlAbandoned(PagSeguroConnectionData $connectionData, array $searchParams) |
|
| 74 | + { |
|
| 75 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 76 | + |
|
| 77 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 78 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 79 | + if ($searchParams['pageNumber'] != null) { |
|
| 80 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 81 | + } |
|
| 82 | + if ($searchParams['maxPageResults'] != null) { |
|
| 83 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 84 | + } |
|
| 85 | + return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 86 | + "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param PagSeguroConnectionData $connectionData |
|
| 91 | + * @param $reference |
|
| 92 | + * @param null $searchParams |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + private static function buildSearchUrlByReference( |
|
| 96 | + PagSeguroConnectionData $connectionData, |
|
| 97 | + $reference, |
|
| 98 | + $searchParams = null |
|
| 99 | + ){ |
|
| 100 | + $url = $connectionData->getServiceUrl('v2'); |
|
| 101 | + if ($searchParams == null) { |
|
| 102 | + return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 103 | + } else { |
|
| 104 | + |
|
| 105 | + $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
|
| 106 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 107 | + if ($searchParams['pageNumber'] != null) { |
|
| 108 | + $page = "&page=" . $searchParams['pageNumber']; |
|
| 109 | + } |
|
| 110 | + if ($searchParams['maxPageResults'] != null) { |
|
| 111 | + $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 115 | + . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /*** |
|
| 120 | 120 | * Finds a transaction with a matching transaction code |
| 121 | 121 | * |
| 122 | 122 | * @param PagSeguroCredentials $credentials |
@@ -126,35 +126,35 @@ discard block |
||
| 126 | 126 | * @throws PagSeguroServiceException |
| 127 | 127 | * @throws Exception |
| 128 | 128 | */ |
| 129 | - public static function searchByCode(PagSeguroCredentials $credentials, $transactionCode) |
|
| 130 | - { |
|
| 129 | + public static function searchByCode(PagSeguroCredentials $credentials, $transactionCode) |
|
| 130 | + { |
|
| 131 | 131 | |
| 132 | - LogPagSeguro::info("PagSeguroTransactionSearchService.SearchByCode($transactionCode) - begin"); |
|
| 132 | + LogPagSeguro::info("PagSeguroTransactionSearchService.SearchByCode($transactionCode) - begin"); |
|
| 133 | 133 | |
| 134 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 134 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 135 | 135 | |
| 136 | - try { |
|
| 136 | + try { |
|
| 137 | 137 | |
| 138 | - $connection = new PagSeguroHttpConnection(); |
|
| 139 | - $connection->get( |
|
| 140 | - self::buildSearchUrlByCode($connectionData, $transactionCode), |
|
| 141 | - $connectionData->getServiceTimeout(), |
|
| 142 | - $connectionData->getCharset() |
|
| 143 | - ); |
|
| 138 | + $connection = new PagSeguroHttpConnection(); |
|
| 139 | + $connection->get( |
|
| 140 | + self::buildSearchUrlByCode($connectionData, $transactionCode), |
|
| 141 | + $connectionData->getServiceTimeout(), |
|
| 142 | + $connectionData->getCharset() |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - return self::searchByCodeResult($connection, $transactionCode); |
|
| 145 | + return self::searchByCodeResult($connection, $transactionCode); |
|
| 146 | 146 | |
| 147 | - } catch (PagSeguroServiceException $err) { |
|
| 148 | - throw $err; |
|
| 149 | - } |
|
| 150 | - catch (Exception $err) { |
|
| 151 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 152 | - throw $err; |
|
| 153 | - } |
|
| 147 | + } catch (PagSeguroServiceException $err) { |
|
| 148 | + throw $err; |
|
| 149 | + } |
|
| 150 | + catch (Exception $err) { |
|
| 151 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 152 | + throw $err; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /*** |
|
| 157 | + /*** |
|
| 158 | 158 | * Search transactions associated with this set of credentials within a date range |
| 159 | 159 | * |
| 160 | 160 | * @param PagSeguroCredentials $credentials |
@@ -167,45 +167,45 @@ discard block |
||
| 167 | 167 | * @throws PagSeguroServiceException |
| 168 | 168 | * @throws Exception |
| 169 | 169 | */ |
| 170 | - public static function searchByDate( |
|
| 171 | - PagSeguroCredentials $credentials, |
|
| 172 | - $pageNumber, |
|
| 173 | - $maxPageResults, |
|
| 174 | - $initialDate, |
|
| 175 | - $finalDate = null |
|
| 176 | - ) { |
|
| 170 | + public static function searchByDate( |
|
| 171 | + PagSeguroCredentials $credentials, |
|
| 172 | + $pageNumber, |
|
| 173 | + $maxPageResults, |
|
| 174 | + $initialDate, |
|
| 175 | + $finalDate = null |
|
| 176 | + ) { |
|
| 177 | 177 | |
| 178 | - LogPagSeguro::info( |
|
| 179 | - "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | - ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 181 | - ); |
|
| 178 | + LogPagSeguro::info( |
|
| 179 | + "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | + ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 183 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 184 | 184 | |
| 185 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 185 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 186 | 186 | |
| 187 | - try { |
|
| 187 | + try { |
|
| 188 | 188 | |
| 189 | - $connection = new PagSeguroHttpConnection(); |
|
| 190 | - $connection->get( |
|
| 191 | - self::buildSearchUrlByDate($connectionData, $searchParams), |
|
| 192 | - $connectionData->getServiceTimeout(), |
|
| 193 | - $connectionData->getCharset() |
|
| 194 | - ); |
|
| 189 | + $connection = new PagSeguroHttpConnection(); |
|
| 190 | + $connection->get( |
|
| 191 | + self::buildSearchUrlByDate($connectionData, $searchParams), |
|
| 192 | + $connectionData->getServiceTimeout(), |
|
| 193 | + $connectionData->getCharset() |
|
| 194 | + ); |
|
| 195 | 195 | |
| 196 | - self::$logService = "SearchByDate"; |
|
| 197 | - return self::searchResult($connection, $initialDate, $finalDate); |
|
| 196 | + self::$logService = "SearchByDate"; |
|
| 197 | + return self::searchResult($connection, $initialDate, $finalDate); |
|
| 198 | 198 | |
| 199 | - } catch (PagSeguroServiceException $err) { |
|
| 200 | - throw $err; |
|
| 201 | - } catch (Exception $err) { |
|
| 202 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 203 | - throw $err; |
|
| 204 | - } |
|
| 199 | + } catch (PagSeguroServiceException $err) { |
|
| 200 | + throw $err; |
|
| 201 | + } catch (Exception $err) { |
|
| 202 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 203 | + throw $err; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /*** |
|
| 208 | + /*** |
|
| 209 | 209 | * Search transactions abandoned associated with this set of credentials within a date range |
| 210 | 210 | * |
| 211 | 211 | * @param PagSeguroCredentials $credentials |
@@ -218,211 +218,211 @@ discard block |
||
| 218 | 218 | * @throws PagSeguroServiceException |
| 219 | 219 | * @throws Exception |
| 220 | 220 | */ |
| 221 | - public static function searchAbandoned( |
|
| 222 | - PagSeguroCredentials $credentials, |
|
| 223 | - $pageNumber, |
|
| 224 | - $maxPageResults, |
|
| 225 | - $initialDate, |
|
| 226 | - $finalDate = null |
|
| 227 | - ) { |
|
| 228 | - |
|
| 229 | - LogPagSeguro::info( |
|
| 230 | - "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | - PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 236 | - |
|
| 237 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 238 | - |
|
| 239 | - try { |
|
| 240 | - |
|
| 241 | - $connection = new PagSeguroHttpConnection(); |
|
| 242 | - $connection->get( |
|
| 243 | - self::buildSearchUrlAbandoned($connectionData, $searchParams), |
|
| 244 | - $connectionData->getServiceTimeout(), |
|
| 245 | - $connectionData->getCharset() |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - self::$logService = "searchAbandoned"; |
|
| 249 | - return self::searchResult($connection, $initialDate, $finalDate); |
|
| 250 | - |
|
| 251 | - } catch (PagSeguroServiceException $err) { |
|
| 252 | - throw $err; |
|
| 253 | - } |
|
| 254 | - catch (Exception $err) { |
|
| 255 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 256 | - throw $err; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @param PagSeguroCredentials $credentials |
|
| 263 | - * @param $reference |
|
| 264 | - * @param null $initialDate |
|
| 265 | - * @param null $finalDate |
|
| 266 | - * @param null $pageNumber |
|
| 267 | - * @param null $maxPageResults |
|
| 268 | - * @throws Exception |
|
| 269 | - * @throws PagSeguroServiceException |
|
| 270 | - */ |
|
| 271 | - public static function searchByReference( |
|
| 272 | - PagSeguroCredentials $credentials, |
|
| 273 | - $reference, |
|
| 274 | - $initialDate = null, |
|
| 275 | - $finalDate = null, |
|
| 276 | - $pageNumber = null, |
|
| 277 | - $maxPageResults = null |
|
| 278 | - ) { |
|
| 279 | - |
|
| 280 | - LogPagSeguro::info( |
|
| 281 | - "PagSeguroTransactionSearchService.SearchByReference(reference=".$reference.") - begin" |
|
| 282 | - ); |
|
| 283 | - |
|
| 284 | - $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 285 | - |
|
| 286 | - if ($initialDate) |
|
| 287 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | - else |
|
| 289 | - $searchParams = null; |
|
| 290 | - |
|
| 291 | - try { |
|
| 292 | - |
|
| 293 | - $connection = new PagSeguroHttpConnection(); |
|
| 294 | - $connection->get( |
|
| 295 | - self::buildSearchUrlByReference( |
|
| 296 | - $connectionData, |
|
| 297 | - $reference, |
|
| 298 | - $searchParams |
|
| 299 | - ), |
|
| 300 | - $connectionData->getServiceTimeout(), |
|
| 301 | - $connectionData->getCharset() |
|
| 302 | - ); |
|
| 303 | - |
|
| 304 | - self::$logService = "SearchByReference"; |
|
| 305 | - return self::searchResult($connection); |
|
| 306 | - |
|
| 307 | - } catch (PagSeguroServiceException $err) { |
|
| 308 | - throw $err; |
|
| 309 | - } catch (Exception $err) { |
|
| 310 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 311 | - throw $err; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @param $pageNumber |
|
| 318 | - * @param $maxPageResults |
|
| 319 | - * @param $initialDate |
|
| 320 | - * @param null $finalDate |
|
| 321 | - * @return array |
|
| 322 | - */ |
|
| 323 | - private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
|
| 324 | - { |
|
| 325 | - $searchParams = array( |
|
| 326 | - 'initialDate' => PagSeguroHelper::formatDate($initialDate), |
|
| 327 | - 'pageNumber' => $pageNumber, |
|
| 328 | - 'maxPageResults' => $maxPageResults |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; |
|
| 332 | - |
|
| 333 | - return $searchParams; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param $connection |
|
| 338 | - * @param $code |
|
| 339 | - * @return bool|PagSeguroTransaction |
|
| 340 | - * @throws PagSeguroServiceException |
|
| 341 | - */ |
|
| 342 | - private function searchByCodeResult($connection, $code) |
|
| 343 | - { |
|
| 344 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 345 | - |
|
| 346 | - switch ($httpStatus->getType()) { |
|
| 347 | - |
|
| 348 | - case 'OK': |
|
| 349 | - $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
| 350 | - LogPagSeguro::info( |
|
| 351 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 352 | - $transaction->toString() |
|
| 353 | - ); |
|
| 354 | - break; |
|
| 355 | - |
|
| 356 | - case 'BAD_REQUEST': |
|
| 357 | - $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 358 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 359 | - LogPagSeguro::error( |
|
| 360 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 361 | - $err->getOneLineMessage() |
|
| 362 | - ); |
|
| 363 | - throw $err; |
|
| 364 | - break; |
|
| 365 | - |
|
| 366 | - default: |
|
| 367 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 368 | - LogPagSeguro::error( |
|
| 369 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 370 | - $err->getOneLineMessage() |
|
| 371 | - ); |
|
| 372 | - throw $err; |
|
| 373 | - break; |
|
| 374 | - } |
|
| 375 | - return isset($transaction) ? $transaction : false; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @param $connection |
|
| 380 | - * @param null $initialDate |
|
| 381 | - * @param null $finalDate |
|
| 382 | - * @return bool|PagSeguroTransactionSearchResult |
|
| 383 | - * @throws PagSeguroServiceException |
|
| 384 | - */ |
|
| 385 | - private function searchResult($connection, $initialDate = null, $finalDate = null) |
|
| 386 | - { |
|
| 387 | - |
|
| 388 | - $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 389 | - |
|
| 390 | - switch ($httpStatus->getType()) { |
|
| 391 | - |
|
| 392 | - case 'OK': |
|
| 393 | - |
|
| 394 | - $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
|
| 395 | - |
|
| 396 | - LogPagSeguro::info( |
|
| 397 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 400 | - ); |
|
| 401 | - break; |
|
| 402 | - |
|
| 403 | - case 'BAD_REQUEST': |
|
| 404 | - $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 405 | - $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 406 | - LogPagSeguro::error( |
|
| 407 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 410 | - ); |
|
| 411 | - throw $err; |
|
| 412 | - break; |
|
| 413 | - |
|
| 414 | - default: |
|
| 415 | - $err = new PagSeguroServiceException($httpStatus); |
|
| 416 | - LogPagSeguro::error( |
|
| 417 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 420 | - ); |
|
| 421 | - throw $err; |
|
| 422 | - break; |
|
| 423 | - |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return isset($searchResult) ? $searchResult : false; |
|
| 427 | - } |
|
| 221 | + public static function searchAbandoned( |
|
| 222 | + PagSeguroCredentials $credentials, |
|
| 223 | + $pageNumber, |
|
| 224 | + $maxPageResults, |
|
| 225 | + $initialDate, |
|
| 226 | + $finalDate = null |
|
| 227 | + ) { |
|
| 228 | + |
|
| 229 | + LogPagSeguro::info( |
|
| 230 | + "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | + PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 236 | + |
|
| 237 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 238 | + |
|
| 239 | + try { |
|
| 240 | + |
|
| 241 | + $connection = new PagSeguroHttpConnection(); |
|
| 242 | + $connection->get( |
|
| 243 | + self::buildSearchUrlAbandoned($connectionData, $searchParams), |
|
| 244 | + $connectionData->getServiceTimeout(), |
|
| 245 | + $connectionData->getCharset() |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + self::$logService = "searchAbandoned"; |
|
| 249 | + return self::searchResult($connection, $initialDate, $finalDate); |
|
| 250 | + |
|
| 251 | + } catch (PagSeguroServiceException $err) { |
|
| 252 | + throw $err; |
|
| 253 | + } |
|
| 254 | + catch (Exception $err) { |
|
| 255 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 256 | + throw $err; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @param PagSeguroCredentials $credentials |
|
| 263 | + * @param $reference |
|
| 264 | + * @param null $initialDate |
|
| 265 | + * @param null $finalDate |
|
| 266 | + * @param null $pageNumber |
|
| 267 | + * @param null $maxPageResults |
|
| 268 | + * @throws Exception |
|
| 269 | + * @throws PagSeguroServiceException |
|
| 270 | + */ |
|
| 271 | + public static function searchByReference( |
|
| 272 | + PagSeguroCredentials $credentials, |
|
| 273 | + $reference, |
|
| 274 | + $initialDate = null, |
|
| 275 | + $finalDate = null, |
|
| 276 | + $pageNumber = null, |
|
| 277 | + $maxPageResults = null |
|
| 278 | + ) { |
|
| 279 | + |
|
| 280 | + LogPagSeguro::info( |
|
| 281 | + "PagSeguroTransactionSearchService.SearchByReference(reference=".$reference.") - begin" |
|
| 282 | + ); |
|
| 283 | + |
|
| 284 | + $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
|
| 285 | + |
|
| 286 | + if ($initialDate) |
|
| 287 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | + else |
|
| 289 | + $searchParams = null; |
|
| 290 | + |
|
| 291 | + try { |
|
| 292 | + |
|
| 293 | + $connection = new PagSeguroHttpConnection(); |
|
| 294 | + $connection->get( |
|
| 295 | + self::buildSearchUrlByReference( |
|
| 296 | + $connectionData, |
|
| 297 | + $reference, |
|
| 298 | + $searchParams |
|
| 299 | + ), |
|
| 300 | + $connectionData->getServiceTimeout(), |
|
| 301 | + $connectionData->getCharset() |
|
| 302 | + ); |
|
| 303 | + |
|
| 304 | + self::$logService = "SearchByReference"; |
|
| 305 | + return self::searchResult($connection); |
|
| 306 | + |
|
| 307 | + } catch (PagSeguroServiceException $err) { |
|
| 308 | + throw $err; |
|
| 309 | + } catch (Exception $err) { |
|
| 310 | + LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 311 | + throw $err; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param $pageNumber |
|
| 318 | + * @param $maxPageResults |
|
| 319 | + * @param $initialDate |
|
| 320 | + * @param null $finalDate |
|
| 321 | + * @return array |
|
| 322 | + */ |
|
| 323 | + private function buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate = null) |
|
| 324 | + { |
|
| 325 | + $searchParams = array( |
|
| 326 | + 'initialDate' => PagSeguroHelper::formatDate($initialDate), |
|
| 327 | + 'pageNumber' => $pageNumber, |
|
| 328 | + 'maxPageResults' => $maxPageResults |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; |
|
| 332 | + |
|
| 333 | + return $searchParams; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param $connection |
|
| 338 | + * @param $code |
|
| 339 | + * @return bool|PagSeguroTransaction |
|
| 340 | + * @throws PagSeguroServiceException |
|
| 341 | + */ |
|
| 342 | + private function searchByCodeResult($connection, $code) |
|
| 343 | + { |
|
| 344 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 345 | + |
|
| 346 | + switch ($httpStatus->getType()) { |
|
| 347 | + |
|
| 348 | + case 'OK': |
|
| 349 | + $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
|
| 350 | + LogPagSeguro::info( |
|
| 351 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 352 | + $transaction->toString() |
|
| 353 | + ); |
|
| 354 | + break; |
|
| 355 | + |
|
| 356 | + case 'BAD_REQUEST': |
|
| 357 | + $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 358 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 359 | + LogPagSeguro::error( |
|
| 360 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 361 | + $err->getOneLineMessage() |
|
| 362 | + ); |
|
| 363 | + throw $err; |
|
| 364 | + break; |
|
| 365 | + |
|
| 366 | + default: |
|
| 367 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 368 | + LogPagSeguro::error( |
|
| 369 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 370 | + $err->getOneLineMessage() |
|
| 371 | + ); |
|
| 372 | + throw $err; |
|
| 373 | + break; |
|
| 374 | + } |
|
| 375 | + return isset($transaction) ? $transaction : false; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @param $connection |
|
| 380 | + * @param null $initialDate |
|
| 381 | + * @param null $finalDate |
|
| 382 | + * @return bool|PagSeguroTransactionSearchResult |
|
| 383 | + * @throws PagSeguroServiceException |
|
| 384 | + */ |
|
| 385 | + private function searchResult($connection, $initialDate = null, $finalDate = null) |
|
| 386 | + { |
|
| 387 | + |
|
| 388 | + $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); |
|
| 389 | + |
|
| 390 | + switch ($httpStatus->getType()) { |
|
| 391 | + |
|
| 392 | + case 'OK': |
|
| 393 | + |
|
| 394 | + $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
|
| 395 | + |
|
| 396 | + LogPagSeguro::info( |
|
| 397 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 400 | + ); |
|
| 401 | + break; |
|
| 402 | + |
|
| 403 | + case 'BAD_REQUEST': |
|
| 404 | + $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
|
| 405 | + $err = new PagSeguroServiceException($httpStatus, $errors); |
|
| 406 | + LogPagSeguro::error( |
|
| 407 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 410 | + ); |
|
| 411 | + throw $err; |
|
| 412 | + break; |
|
| 413 | + |
|
| 414 | + default: |
|
| 415 | + $err = new PagSeguroServiceException($httpStatus); |
|
| 416 | + LogPagSeguro::error( |
|
| 417 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | + PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | + PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 420 | + ); |
|
| 421 | + throw $err; |
|
| 422 | + break; |
|
| 423 | + |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return isset($searchResult) ? $searchResult : false; |
|
| 427 | + } |
|
| 428 | 428 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | private static function buildSearchUrlByCode(PagSeguroConnectionData $connectionData, $transactionCode) |
| 43 | 43 | { |
| 44 | 44 | $url = $connectionData->getServiceUrl('v3'); |
| 45 | - return "{$url}/{$transactionCode}/?" . $connectionData->getCredentialsUrlQuery(); |
|
| 45 | + return "{$url}/{$transactionCode}/?".$connectionData->getCredentialsUrlQuery(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $url = $connectionData->getServiceUrl('v2'); |
| 56 | 56 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 57 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 57 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 58 | 58 | if ($searchParams['pageNumber'] != null) { |
| 59 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 59 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 60 | 60 | } |
| 61 | 61 | if ($searchParams['maxPageResults'] != null) { |
| 62 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 62 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 63 | 63 | } |
| 64 | - return "{$url}/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 64 | + return "{$url}/?".$connectionData->getCredentialsUrlQuery(). |
|
| 65 | 65 | "&initialDate={$initialDate}{$finalDate}{$page}{$maxPageResults}"; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | $url = $connectionData->getServiceUrl('v2'); |
| 76 | 76 | |
| 77 | 77 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 78 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 78 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 79 | 79 | if ($searchParams['pageNumber'] != null) { |
| 80 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 80 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 81 | 81 | } |
| 82 | 82 | if ($searchParams['maxPageResults'] != null) { |
| 83 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 83 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 84 | 84 | } |
| 85 | - return "{$url}/abandoned/?" . $connectionData->getCredentialsUrlQuery() . |
|
| 85 | + return "{$url}/abandoned/?".$connectionData->getCredentialsUrlQuery(). |
|
| 86 | 86 | "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -96,22 +96,22 @@ discard block |
||
| 96 | 96 | PagSeguroConnectionData $connectionData, |
| 97 | 97 | $reference, |
| 98 | 98 | $searchParams = null |
| 99 | - ){ |
|
| 99 | + ) { |
|
| 100 | 100 | $url = $connectionData->getServiceUrl('v2'); |
| 101 | 101 | if ($searchParams == null) { |
| 102 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference; |
|
| 102 | + return "{$url}?".$connectionData->getCredentialsUrlQuery()."&reference=".$reference; |
|
| 103 | 103 | } else { |
| 104 | 104 | |
| 105 | 105 | $initialDate = $searchParams['initialDate'] != null ? $searchParams['initialDate'] : ""; |
| 106 | - $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=" . $searchParams['finalDate']) : ""; |
|
| 106 | + $finalDate = $searchParams['finalDate'] != null ? ("&finalDate=".$searchParams['finalDate']) : ""; |
|
| 107 | 107 | if ($searchParams['pageNumber'] != null) { |
| 108 | - $page = "&page=" . $searchParams['pageNumber']; |
|
| 108 | + $page = "&page=".$searchParams['pageNumber']; |
|
| 109 | 109 | } |
| 110 | 110 | if ($searchParams['maxPageResults'] != null) { |
| 111 | - $maxPageResults = "&maxPageResults=" . $searchParams['maxPageResults']; |
|
| 111 | + $maxPageResults = "&maxPageResults=".$searchParams['maxPageResults']; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - return "{$url}?" . $connectionData->getCredentialsUrlQuery() . "&reference=" . $reference |
|
| 114 | + return "{$url}?".$connectionData->getCredentialsUrlQuery()."&reference=".$reference |
|
| 115 | 115 | . "&initialDate={$initialDate}&finalDate={$finalDate}{$page}{$maxPageResults}"; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | throw $err; |
| 149 | 149 | } |
| 150 | 150 | catch (Exception $err) { |
| 151 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 151 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 152 | 152 | throw $err; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | ) { |
| 177 | 177 | |
| 178 | 178 | LogPagSeguro::info( |
| 179 | - "PagSeguroTransactionSearchService.SearchByDate(initialDate=" . PagSeguroHelper::formatDate($initialDate) . |
|
| 180 | - ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 179 | + "PagSeguroTransactionSearchService.SearchByDate(initialDate=".PagSeguroHelper::formatDate($initialDate). |
|
| 180 | + ", finalDate=".PagSeguroHelper::formatDate($finalDate).") - begin" |
|
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } catch (PagSeguroServiceException $err) { |
| 200 | 200 | throw $err; |
| 201 | 201 | } catch (Exception $err) { |
| 202 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 202 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 203 | 203 | throw $err; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | ) { |
| 228 | 228 | |
| 229 | 229 | LogPagSeguro::info( |
| 230 | - "PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . |
|
| 231 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 232 | - PagSeguroHelper::formatDate($finalDate) . ") - begin" |
|
| 230 | + "PagSeguroTransactionSearchService.searchAbandoned(initialDate=". |
|
| 231 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 232 | + PagSeguroHelper::formatDate($finalDate).") - begin" |
|
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | 235 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | throw $err; |
| 253 | 253 | } |
| 254 | 254 | catch (Exception $err) { |
| 255 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 255 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 256 | 256 | throw $err; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } catch (PagSeguroServiceException $err) { |
| 308 | 308 | throw $err; |
| 309 | 309 | } catch (Exception $err) { |
| 310 | - LogPagSeguro::error("Exception: " . $err->getMessage()); |
|
| 310 | + LogPagSeguro::error("Exception: ".$err->getMessage()); |
|
| 311 | 311 | throw $err; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | case 'OK': |
| 349 | 349 | $transaction = PagSeguroTransactionParser::readTransaction($connection->getResponse()); |
| 350 | 350 | LogPagSeguro::info( |
| 351 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end " . |
|
| 351 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - end ". |
|
| 352 | 352 | $transaction->toString() |
| 353 | 353 | ); |
| 354 | 354 | break; |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
| 358 | 358 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 359 | 359 | LogPagSeguro::error( |
| 360 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 360 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error ". |
|
| 361 | 361 | $err->getOneLineMessage() |
| 362 | 362 | ); |
| 363 | 363 | throw $err; |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | default: |
| 367 | 367 | $err = new PagSeguroServiceException($httpStatus); |
| 368 | 368 | LogPagSeguro::error( |
| 369 | - "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error " . |
|
| 369 | + "PagSeguroTransactionSearchService.SearchByCode(transactionCode=$code) - error ". |
|
| 370 | 370 | $err->getOneLineMessage() |
| 371 | 371 | ); |
| 372 | 372 | throw $err; |
@@ -394,9 +394,9 @@ discard block |
||
| 394 | 394 | $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); |
| 395 | 395 | |
| 396 | 396 | LogPagSeguro::info( |
| 397 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 398 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 399 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString() |
|
| 397 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 398 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 399 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$searchResult->toString() |
|
| 400 | 400 | ); |
| 401 | 401 | break; |
| 402 | 402 | |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); |
| 405 | 405 | $err = new PagSeguroServiceException($httpStatus, $errors); |
| 406 | 406 | LogPagSeguro::error( |
| 407 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 408 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 409 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 407 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 408 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 409 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$err->getOneLineMessage() |
|
| 410 | 410 | ); |
| 411 | 411 | throw $err; |
| 412 | 412 | break; |
@@ -414,9 +414,9 @@ discard block |
||
| 414 | 414 | default: |
| 415 | 415 | $err = new PagSeguroServiceException($httpStatus); |
| 416 | 416 | LogPagSeguro::error( |
| 417 | - sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . |
|
| 418 | - PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . |
|
| 419 | - PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage() |
|
| 417 | + sprintf("PagSeguroTransactionSearchService.%s(initialDate=". |
|
| 418 | + PagSeguroHelper::formatDate($initialDate).", finalDate=". |
|
| 419 | + PagSeguroHelper::formatDate($finalDate).") - end ", self::$logService).$err->getOneLineMessage() |
|
| 420 | 420 | ); |
| 421 | 421 | throw $err; |
| 422 | 422 | break; |
@@ -146,8 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | } catch (PagSeguroServiceException $err) { |
| 148 | 148 | throw $err; |
| 149 | - } |
|
| 150 | - catch (Exception $err) { |
|
| 149 | + } catch (Exception $err) { |
|
| 151 | 150 | LogPagSeguro::error("Exception: " . $err->getMessage()); |
| 152 | 151 | throw $err; |
| 153 | 152 | } |
@@ -250,8 +249,7 @@ discard block |
||
| 250 | 249 | |
| 251 | 250 | } catch (PagSeguroServiceException $err) { |
| 252 | 251 | throw $err; |
| 253 | - } |
|
| 254 | - catch (Exception $err) { |
|
| 252 | + } catch (Exception $err) { |
|
| 255 | 253 | LogPagSeguro::error("Exception: " . $err->getMessage()); |
| 256 | 254 | throw $err; |
| 257 | 255 | } |
@@ -283,10 +281,11 @@ discard block |
||
| 283 | 281 | |
| 284 | 282 | $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); |
| 285 | 283 | |
| 286 | - if ($initialDate) |
|
| 287 | - $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 288 | - else |
|
| 289 | - $searchParams = null; |
|
| 284 | + if ($initialDate) { |
|
| 285 | + $searchParams = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate); |
|
| 286 | + } else { |
|
| 287 | + $searchParams = null; |
|
| 288 | + } |
|
| 290 | 289 | |
| 291 | 290 | try { |
| 292 | 291 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * Get index for sheet |
| 305 | 305 | * |
| 306 | 306 | * @param PHPExcel_Worksheet $pSheet |
| 307 | - * @return Sheet index |
|
| 307 | + * @return integer|null index |
|
| 308 | 308 | * @throws Exception |
| 309 | 309 | */ |
| 310 | 310 | public function getIndex(PHPExcel_Worksheet $pSheet) |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @param string $sheetName Sheet name to modify index for |
| 323 | 323 | * @param int $newIndex New index for the sheet |
| 324 | - * @return New sheet index |
|
| 324 | + * @return integer sheet index |
|
| 325 | 325 | * @throws Exception |
| 326 | 326 | */ |
| 327 | 327 | public function setIndexByName($sheetName, $newIndex) |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * Add named range |
| 458 | 458 | * |
| 459 | 459 | * @param PHPExcel_NamedRange $namedRange |
| 460 | - * @return PHPExcel |
|
| 460 | + * @return boolean |
|
| 461 | 461 | */ |
| 462 | 462 | public function addNamedRange(PHPExcel_NamedRange $namedRange) { |
| 463 | 463 | if ($namedRange->getScope() == null) { |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** PHPExcel root directory */ |
| 30 | -if (!defined('PHPEXCEL_ROOT')) { |
|
| 31 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/'); |
|
| 32 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|
| 30 | +if ( ! defined('PHPEXCEL_ROOT')) { |
|
| 31 | + define('PHPEXCEL_ROOT', dirname(__FILE__).'/'); |
|
| 32 | + require(PHPEXCEL_ROOT.'PHPExcel/Autoloader.php'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | */ |
| 135 | 135 | public function disconnectWorksheets() { |
| 136 | - foreach($this->_workSheetCollection as $k => &$worksheet) { |
|
| 136 | + foreach ($this->_workSheetCollection as $k => &$worksheet) { |
|
| 137 | 137 | $worksheet->disconnectCells(); |
| 138 | 138 | $this->_workSheetCollection[$k] = null; |
| 139 | 139 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
| 217 | 217 | { |
| 218 | - if($iSheetIndex === NULL) { |
|
| 218 | + if ($iSheetIndex === NULL) { |
|
| 219 | 219 | $this->_workSheetCollection[] = $pSheet; |
| 220 | 220 | } else { |
| 221 | 221 | // Insert the sheet at the requested index |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | return $worksheet; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - throw new Exception('Workbook does not contain sheet:' . $pValue); |
|
| 395 | + throw new Exception('Workbook does not contain sheet:'.$pValue); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | // update the cellXfs |
| 439 | 439 | foreach ($pSheet->getCellCollection(false) as $cellID) { |
| 440 | 440 | $cell = $pSheet->getCell($cellID); |
| 441 | - $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs ); |
|
| 441 | + $cell->setXfIndex($cell->getXfIndex() + $countCellXfs); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | return $this->addSheet($pSheet, $iSheetIndex); |
@@ -487,8 +487,8 @@ discard block |
||
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // then look for local defined name (has priority over global defined name if both names exist) |
| 490 | - if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) { |
|
| 491 | - $returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]; |
|
| 490 | + if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange])) { |
|
| 491 | + $returnValue = $this->_namedRanges[$pSheet->getTitle().'!'.$namedRange]; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | unset($this->_namedRanges[$namedRange]); |
| 509 | 509 | } |
| 510 | 510 | } else { |
| 511 | - if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) { |
|
| 512 | - unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]); |
|
| 511 | + if (isset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange])) { |
|
| 512 | + unset($this->_namedRanges[$pSheet->getTitle().'!'.$namedRange]); |
|
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | return $this; |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * Implement PHP __clone to create a deep clone, not just a shallow copy. |
| 546 | 546 | */ |
| 547 | 547 | public function __clone() { |
| 548 | - foreach($this as $key => $val) { |
|
| 548 | + foreach ($this as $key => $val) { |
|
| 549 | 549 | if (is_object($val) || (is_array($val))) { |
| 550 | 550 | $this->{$key} = unserialize(serialize($val)); |
| 551 | 551 | } |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | foreach ($worksheet->getCellCollection(false) as $cellID) { |
| 634 | 634 | $cell = $worksheet->getCell($cellID); |
| 635 | 635 | $xfIndex = $cell->getXfIndex(); |
| 636 | - if ($xfIndex > $pIndex ) { |
|
| 636 | + if ($xfIndex > $pIndex) { |
|
| 637 | 637 | // decrease xf index by 1 |
| 638 | 638 | $cell->setXfIndex($xfIndex - 1); |
| 639 | 639 | } else if ($xfIndex == $pIndex) { |
@@ -780,19 +780,19 @@ discard block |
||
| 780 | 780 | // for all cells |
| 781 | 781 | foreach ($sheet->getCellCollection(false) as $cellID) { |
| 782 | 782 | $cell = $sheet->getCell($cellID); |
| 783 | - $cell->setXfIndex( $map[$cell->getXfIndex()] ); |
|
| 783 | + $cell->setXfIndex($map[$cell->getXfIndex()]); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | // for all row dimensions |
| 787 | 787 | foreach ($sheet->getRowDimensions() as $rowDimension) { |
| 788 | 788 | if ($rowDimension->getXfIndex() !== null) { |
| 789 | - $rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] ); |
|
| 789 | + $rowDimension->setXfIndex($map[$rowDimension->getXfIndex()]); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // for all column dimensions |
| 794 | 794 | foreach ($sheet->getColumnDimensions() as $columnDimension) { |
| 795 | - $columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] ); |
|
| 795 | + $columnDimension->setXfIndex($map[$columnDimension->getXfIndex()]); |
|
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | 798 | |
@@ -191,48 +191,48 @@ discard block |
||
| 191 | 191 | return $this->_workSheetCollection[$this->_activeSheetIndex]; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Create sheet and add it to this workbook |
|
| 196 | - * |
|
| 194 | + /** |
|
| 195 | + * Create sheet and add it to this workbook |
|
| 196 | + * |
|
| 197 | 197 | * @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last) |
| 198 | - * @return PHPExcel_Worksheet |
|
| 199 | - * @throws Exception |
|
| 200 | - */ |
|
| 201 | - public function createSheet($iSheetIndex = null) |
|
| 202 | - { |
|
| 203 | - $newSheet = new PHPExcel_Worksheet($this); |
|
| 204 | - $this->addSheet($newSheet, $iSheetIndex); |
|
| 205 | - return $newSheet; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Add sheet |
|
| 210 | - * |
|
| 211 | - * @param PHPExcel_Worksheet $pSheet |
|
| 198 | + * @return PHPExcel_Worksheet |
|
| 199 | + * @throws Exception |
|
| 200 | + */ |
|
| 201 | + public function createSheet($iSheetIndex = null) |
|
| 202 | + { |
|
| 203 | + $newSheet = new PHPExcel_Worksheet($this); |
|
| 204 | + $this->addSheet($newSheet, $iSheetIndex); |
|
| 205 | + return $newSheet; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Add sheet |
|
| 210 | + * |
|
| 211 | + * @param PHPExcel_Worksheet $pSheet |
|
| 212 | 212 | * @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last) |
| 213 | - * @return PHPExcel_Worksheet |
|
| 214 | - * @throws Exception |
|
| 215 | - */ |
|
| 216 | - public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
|
| 217 | - { |
|
| 218 | - if($iSheetIndex === NULL) { |
|
| 219 | - $this->_workSheetCollection[] = $pSheet; |
|
| 220 | - } else { |
|
| 221 | - // Insert the sheet at the requested index |
|
| 222 | - array_splice( |
|
| 223 | - $this->_workSheetCollection, |
|
| 224 | - $iSheetIndex, |
|
| 225 | - 0, |
|
| 226 | - array($pSheet) |
|
| 227 | - ); |
|
| 213 | + * @return PHPExcel_Worksheet |
|
| 214 | + * @throws Exception |
|
| 215 | + */ |
|
| 216 | + public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) |
|
| 217 | + { |
|
| 218 | + if($iSheetIndex === NULL) { |
|
| 219 | + $this->_workSheetCollection[] = $pSheet; |
|
| 220 | + } else { |
|
| 221 | + // Insert the sheet at the requested index |
|
| 222 | + array_splice( |
|
| 223 | + $this->_workSheetCollection, |
|
| 224 | + $iSheetIndex, |
|
| 225 | + 0, |
|
| 226 | + array($pSheet) |
|
| 227 | + ); |
|
| 228 | 228 | |
| 229 | 229 | // Adjust active sheet index if necessary |
| 230 | 230 | if ($this->_activeSheetIndex >= $iSheetIndex) { |
| 231 | 231 | ++$this->_activeSheetIndex; |
| 232 | 232 | } |
| 233 | - } |
|
| 233 | + } |
|
| 234 | 234 | return $pSheet; |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * Remove sheet by index |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - /** |
|
| 319 | + /** |
|
| 320 | 320 | * Set index for sheet by sheet name. |
| 321 | 321 | * |
| 322 | 322 | * @param string $sheetName Sheet name to modify index for |
@@ -324,22 +324,22 @@ discard block |
||
| 324 | 324 | * @return New sheet index |
| 325 | 325 | * @throws Exception |
| 326 | 326 | */ |
| 327 | - public function setIndexByName($sheetName, $newIndex) |
|
| 328 | - { |
|
| 329 | - $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); |
|
| 330 | - $pSheet = array_splice( |
|
| 331 | - $this->_workSheetCollection, |
|
| 332 | - $oldIndex, |
|
| 333 | - 1 |
|
| 334 | - ); |
|
| 335 | - array_splice( |
|
| 336 | - $this->_workSheetCollection, |
|
| 337 | - $newIndex, |
|
| 338 | - 0, |
|
| 339 | - $pSheet |
|
| 340 | - ); |
|
| 341 | - return $newIndex; |
|
| 342 | - } |
|
| 327 | + public function setIndexByName($sheetName, $newIndex) |
|
| 328 | + { |
|
| 329 | + $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); |
|
| 330 | + $pSheet = array_splice( |
|
| 331 | + $this->_workSheetCollection, |
|
| 332 | + $oldIndex, |
|
| 333 | + 1 |
|
| 334 | + ); |
|
| 335 | + array_splice( |
|
| 336 | + $this->_workSheetCollection, |
|
| 337 | + $newIndex, |
|
| 338 | + 0, |
|
| 339 | + $pSheet |
|
| 340 | + ); |
|
| 341 | + return $newIndex; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | 345 | * Get sheet count |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | */ |
| 725 | 725 | public function garbageCollect() |
| 726 | 726 | { |
| 727 | - // how many references are there to each cellXf ? |
|
| 727 | + // how many references are there to each cellXf ? |
|
| 728 | 728 | $countReferencesCellXf = array(); |
| 729 | 729 | foreach ($this->_cellXfCollection as $index => $cellXf) { |
| 730 | 730 | $countReferencesCellXf[$index] = 0; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @param string $pCoord Coordinate address of the cell to update |
| 88 | 88 | * @param PHPExcel_Cell $cell Cell to update |
| 89 | - * @return void |
|
| 89 | + * @return PHPExcel_Cell |
|
| 90 | 90 | * @throws Exception |
| 91 | 91 | */ |
| 92 | 92 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell? |
| 108 | 108 | * |
| 109 | 109 | * @param string $pCoord Coordinate address of the cell to check |
| 110 | - * @return void |
|
| 110 | + * @return boolean |
|
| 111 | 111 | * @return boolean |
| 112 | 112 | */ |
| 113 | 113 | public function isDataSet($pCoord) { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | private $_memcache = null; |
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 62 | - * and the 'nullify' the current cell object |
|
| 63 | - * |
|
| 60 | + /** |
|
| 61 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 62 | + * and the 'nullify' the current cell object |
|
| 63 | + * |
|
| 64 | 64 | * @return void |
| 65 | - * @throws Exception |
|
| 66 | - */ |
|
| 65 | + * @throws Exception |
|
| 66 | + */ |
|
| 67 | 67 | private function _storeData() { |
| 68 | 68 | if ($this->_currentCellIsDirty) { |
| 69 | 69 | $this->_currentObject->detach(); |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | } // function _storeData() |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Add or Update a cell in cache identified by coordinate address |
|
| 86 | - * |
|
| 87 | - * @param string $pCoord Coordinate address of the cell to update |
|
| 88 | - * @param PHPExcel_Cell $cell Cell to update |
|
| 84 | + /** |
|
| 85 | + * Add or Update a cell in cache identified by coordinate address |
|
| 86 | + * |
|
| 87 | + * @param string $pCoord Coordinate address of the cell to update |
|
| 88 | + * @param PHPExcel_Cell $cell Cell to update |
|
| 89 | 89 | * @return void |
| 90 | - * @throws Exception |
|
| 91 | - */ |
|
| 90 | + * @throws Exception |
|
| 91 | + */ |
|
| 92 | 92 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
| 93 | 93 | if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) { |
| 94 | 94 | $this->_storeData(); |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Get cell at a specific coordinate |
|
| 134 | - * |
|
| 135 | - * @param string $pCoord Coordinate of the cell |
|
| 136 | - * @throws Exception |
|
| 137 | - * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 138 | - */ |
|
| 133 | + * Get cell at a specific coordinate |
|
| 134 | + * |
|
| 135 | + * @param string $pCoord Coordinate of the cell |
|
| 136 | + * @throws Exception |
|
| 137 | + * @return PHPExcel_Cell Cell that was found, or null if not found |
|
| 138 | + */ |
|
| 139 | 139 | public function getCacheData($pCoord) { |
| 140 | 140 | if ($pCoord === $this->_currentObjectID) { |
| 141 | 141 | return $this->_currentObject; |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | } // function getCacheData() |
| 167 | 167 | |
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Delete a cell in cache identified by coordinate address |
|
| 171 | - * |
|
| 172 | - * @param string $pCoord Coordinate address of the cell to delete |
|
| 173 | - * @throws Exception |
|
| 174 | - */ |
|
| 169 | + /** |
|
| 170 | + * Delete a cell in cache identified by coordinate address |
|
| 171 | + * |
|
| 172 | + * @param string $pCoord Coordinate address of the cell to delete |
|
| 173 | + * @throws Exception |
|
| 174 | + */ |
|
| 175 | 175 | public function deleteCacheData($pCoord) { |
| 176 | 176 | // Delete the entry from Memcache |
| 177 | 177 | $this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache'); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @param string $host Memcache server |
| 266 | 266 | * @param integer $port Memcache port |
| 267 | - * @throws Exception |
|
| 267 | + * @throws Exception |
|
| 268 | 268 | */ |
| 269 | 269 | public function failureCallback($host, $port) { |
| 270 | 270 | throw new Exception('memcache '.$host.':'.$port.' failed'); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | $this->_currentObject->detach(); |
| 70 | 70 | |
| 71 | 71 | $obj = serialize($this->_currentObject); |
| 72 | - if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 73 | - if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 72 | + if ( ! $this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 73 | + if ( ! $this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 74 | 74 | $this->__destruct(); |
| 75 | 75 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache'); |
| 76 | 76 | } |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | parent::copyCellCollection($parent); |
| 192 | 192 | // Get a new id for the new file name |
| 193 | 193 | $baseUnique = $this->_getUniqueID(); |
| 194 | - $newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 194 | + $newCachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 195 | 195 | $cacheList = $this->getCellList(); |
| 196 | - foreach($cacheList as $cellID) { |
|
| 196 | + foreach ($cacheList as $cellID) { |
|
| 197 | 197 | if ($cellID != $this->_currentObjectID) { |
| 198 | 198 | $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache'); |
| 199 | 199 | if ($obj === false) { |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | parent::deleteCacheData($cellID); |
| 202 | 202 | throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache'); |
| 203 | 203 | } |
| 204 | - if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) { |
|
| 204 | + if ( ! $this->_memcache->add($newCachePrefix.$cellID.'.cache', $obj, NULL, $this->_cacheTime)) { |
|
| 205 | 205 | $this->__destruct(); |
| 206 | 206 | throw new Exception('Failed to store cell '.$cellID.' in MemCache'); |
| 207 | 207 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return void |
| 218 | 218 | */ |
| 219 | 219 | public function unsetWorksheetCells() { |
| 220 | - if(!is_null($this->_currentObject)) { |
|
| 220 | + if ( ! is_null($this->_currentObject)) { |
|
| 221 | 221 | $this->_currentObject->detach(); |
| 222 | 222 | $this->_currentObject = $this->_currentObjectID = null; |
| 223 | 223 | } |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @param array of mixed $arguments Additional initialisation arguments |
| 240 | 240 | */ |
| 241 | 241 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 242 | - $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; |
|
| 243 | - $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; |
|
| 244 | - $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 242 | + $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost'; |
|
| 243 | + $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211; |
|
| 244 | + $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 245 | 245 | |
| 246 | 246 | if (is_null($this->_cachePrefix)) { |
| 247 | 247 | $baseUnique = $this->_getUniqueID(); |
| 248 | - $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 248 | + $this->_cachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 249 | 249 | |
| 250 | 250 | // Set a new Memcache object and connect to the Memcache server |
| 251 | 251 | $this->_memcache = new Memcache(); |
| 252 | - if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { |
|
| 252 | + if ( ! $this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) { |
|
| 253 | 253 | throw new Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort); |
| 254 | 254 | } |
| 255 | 255 | $this->_cacheTime = $cacheTime; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function __destruct() { |
| 278 | 278 | $cacheList = $this->getCellList(); |
| 279 | - foreach($cacheList as $cellID) { |
|
| 279 | + foreach ($cacheList as $cellID) { |
|
| 280 | 280 | $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache'); |
| 281 | 281 | } |
| 282 | 282 | } // function __destruct() |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return boolean |
| 289 | 289 | */ |
| 290 | 290 | public static function cacheMethodIsAvailable() { |
| 291 | - if (!function_exists('memcache_add')) { |
|
| 291 | + if ( ! function_exists('memcache_add')) { |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | * |
| 86 | 86 | * @param string $pCoord Coordinate address of the cell to update |
| 87 | 87 | * @param PHPExcel_Cell $cell Cell to update |
| 88 | - * @return void |
|
| 88 | + * @return PHPExcel_Cell |
|
| 89 | 89 | * @throws Exception |
| 90 | 90 | */ |
| 91 | 91 | public function addCacheData($pCoord, PHPExcel_Cell $cell) { |
@@ -50,13 +50,13 @@ |
||
| 50 | 50 | private $_cacheTime = 600; |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Store cell data in cache for the current cell object if it's "dirty", |
|
| 55 | - * and the 'nullify' the current cell object |
|
| 56 | - * |
|
| 53 | + /** |
|
| 54 | + * Store cell data in cache for the current cell object if it's "dirty", |
|
| 55 | + * and the 'nullify' the current cell object |
|
| 56 | + * |
|
| 57 | 57 | * @return void |
| 58 | - * @throws Exception |
|
| 59 | - */ |
|
| 58 | + * @throws Exception |
|
| 59 | + */ |
|
| 60 | 60 | private function _storeData() { |
| 61 | 61 | if ($this->_currentCellIsDirty) { |
| 62 | 62 | $this->_currentObject->detach(); |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $obj = serialize($this->_currentObject); |
| 65 | 65 | if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) { |
| 66 | - if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 66 | + if ( ! wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 67 | 67 | $this->__destruct(); |
| 68 | 68 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
| 69 | 69 | } |
| 70 | 70 | } else { |
| 71 | - if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 71 | + if ( ! wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) { |
|
| 72 | 72 | $this->__destruct(); |
| 73 | 73 | throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache'); |
| 74 | 74 | } |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | parent::copyCellCollection($parent); |
| 192 | 192 | // Get a new id for the new file name |
| 193 | 193 | $baseUnique = $this->_getUniqueID(); |
| 194 | - $newCachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 194 | + $newCachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 195 | 195 | $cacheList = $this->getCellList(); |
| 196 | - foreach($cacheList as $cellID) { |
|
| 196 | + foreach ($cacheList as $cellID) { |
|
| 197 | 197 | if ($cellID != $this->_currentObjectID) { |
| 198 | 198 | $success = false; |
| 199 | 199 | $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | parent::deleteCacheData($cellID); |
| 203 | 203 | throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache'); |
| 204 | 204 | } |
| 205 | - if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
|
| 205 | + if ( ! wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) { |
|
| 206 | 206 | $this->__destruct(); |
| 207 | 207 | throw new Exception('Failed to store cell '.$cellID.' in Wincache'); |
| 208 | 208 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | 220 | public function unsetWorksheetCells() { |
| 221 | - if(!is_null($this->_currentObject)) { |
|
| 221 | + if ( ! is_null($this->_currentObject)) { |
|
| 222 | 222 | $this->_currentObject->detach(); |
| 223 | 223 | $this->_currentObject = $this->_currentObjectID = null; |
| 224 | 224 | } |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @param array of mixed $arguments Additional initialisation arguments |
| 241 | 241 | */ |
| 242 | 242 | public function __construct(PHPExcel_Worksheet $parent, $arguments) { |
| 243 | - $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 243 | + $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600; |
|
| 244 | 244 | |
| 245 | 245 | if (is_null($this->_cachePrefix)) { |
| 246 | 246 | $baseUnique = $this->_getUniqueID(); |
| 247 | - $this->_cachePrefix = substr(md5($baseUnique),0,8).'.'; |
|
| 247 | + $this->_cachePrefix = substr(md5($baseUnique), 0, 8).'.'; |
|
| 248 | 248 | $this->_cacheTime = $cacheTime; |
| 249 | 249 | |
| 250 | 250 | parent::__construct($parent); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function __destruct() { |
| 259 | 259 | $cacheList = $this->getCellList(); |
| 260 | - foreach($cacheList as $cellID) { |
|
| 260 | + foreach ($cacheList as $cellID) { |
|
| 261 | 261 | wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache'); |
| 262 | 262 | } |
| 263 | 263 | } // function __destruct() |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return boolean |
| 271 | 271 | */ |
| 272 | 272 | public static function cacheMethodIsAvailable() { |
| 273 | - if (!function_exists('wincache_ucache_add')) { |
|
| 273 | + if ( ! function_exists('wincache_ucache_add')) { |
|
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | /** |
| 143 | 143 | * Return the current cache storage class |
| 144 | 144 | * |
| 145 | - * @return PHPExcel_CachedObjectStorage_ICache|NULL |
|
| 145 | + * @return string|null |
|
| 146 | 146 | **/ |
| 147 | 147 | public static function getCacheStorageClass() |
| 148 | 148 | { |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | class PHPExcel_CachedObjectStorageFactory |
| 38 | 38 | { |
| 39 | - const cache_in_memory = 'Memory'; |
|
| 40 | - const cache_in_memory_gzip = 'MemoryGZip'; |
|
| 41 | - const cache_in_memory_serialized = 'MemorySerialized'; |
|
| 42 | - const cache_igbinary = 'Igbinary'; |
|
| 39 | + const cache_in_memory = 'Memory'; |
|
| 40 | + const cache_in_memory_gzip = 'MemoryGZip'; |
|
| 41 | + const cache_in_memory_serialized = 'MemorySerialized'; |
|
| 42 | + const cache_igbinary = 'Igbinary'; |
|
| 43 | 43 | const cache_to_discISAM = 'DiscISAM'; |
| 44 | - const cache_to_apc = 'APC'; |
|
| 44 | + const cache_to_apc = 'APC'; |
|
| 45 | 45 | const cache_to_memcache = 'Memcache'; |
| 46 | 46 | const cache_to_phpTemp = 'PHPTemp'; |
| 47 | 47 | const cache_to_wincache = 'Wincache'; |
| 48 | - const cache_to_sqlite = 'SQLite'; |
|
| 48 | + const cache_to_sqlite = 'SQLite'; |
|
| 49 | 49 | const cache_to_sqlite3 = 'SQLite3'; |
| 50 | 50 | |
| 51 | 51 | |
@@ -98,17 +98,17 @@ discard block |
||
| 98 | 98 | ), |
| 99 | 99 | self::cache_igbinary => array( |
| 100 | 100 | ), |
| 101 | - self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB' |
|
| 101 | + self::cache_to_phpTemp => array('memoryCacheSize' => '1MB' |
|
| 102 | 102 | ), |
| 103 | - self::cache_to_discISAM => array( 'dir' => NULL |
|
| 103 | + self::cache_to_discISAM => array('dir' => NULL |
|
| 104 | 104 | ), |
| 105 | - self::cache_to_apc => array( 'cacheTime' => 600 |
|
| 105 | + self::cache_to_apc => array('cacheTime' => 600 |
|
| 106 | 106 | ), |
| 107 | - self::cache_to_memcache => array( 'memcacheServer' => 'localhost', |
|
| 107 | + self::cache_to_memcache => array('memcacheServer' => 'localhost', |
|
| 108 | 108 | 'memcachePort' => 11211, |
| 109 | 109 | 'cacheTime' => 600 |
| 110 | 110 | ), |
| 111 | - self::cache_to_wincache => array( 'cacheTime' => 600 |
|
| 111 | + self::cache_to_wincache => array('cacheTime' => 600 |
|
| 112 | 112 | ), |
| 113 | 113 | self::cache_to_sqlite => array( |
| 114 | 114 | ), |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | public static function getCacheStorageMethods() |
| 173 | 173 | { |
| 174 | 174 | $activeMethods = array(); |
| 175 | - foreach(self::$_storageMethods as $storageMethod) { |
|
| 176 | - $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod; |
|
| 175 | + foreach (self::$_storageMethods as $storageMethod) { |
|
| 176 | + $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$storageMethod; |
|
| 177 | 177 | if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) { |
| 178 | 178 | $activeMethods[] = $storageMethod; |
| 179 | 179 | } |
@@ -192,25 +192,25 @@ discard block |
||
| 192 | 192 | **/ |
| 193 | 193 | public static function initialize($method = self::cache_in_memory, $arguments = array()) |
| 194 | 194 | { |
| 195 | - if (!in_array($method,self::$_storageMethods)) { |
|
| 195 | + if ( ! in_array($method, self::$_storageMethods)) { |
|
| 196 | 196 | return FALSE; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method; |
| 200 | - if (!call_user_func(array( $cacheStorageClass, |
|
| 200 | + if ( ! call_user_func(array($cacheStorageClass, |
|
| 201 | 201 | 'cacheMethodIsAvailable'))) { |
| 202 | 202 | return FALSE; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method]; |
| 206 | - foreach($arguments as $k => $v) { |
|
| 206 | + foreach ($arguments as $k => $v) { |
|
| 207 | 207 | if (isset(self::$_storageMethodParameters[$method][$k])) { |
| 208 | 208 | self::$_storageMethodParameters[$method][$k] = $v; |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | if (self::$_cacheStorageMethod === NULL) { |
| 213 | - self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method; |
|
| 213 | + self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method; |
|
| 214 | 214 | self::$_cacheStorageMethod = $method; |
| 215 | 215 | } |
| 216 | 216 | return TRUE; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | if ($cacheMethodIsAvailable) { |
| 234 | - $instance = new self::$_cacheStorageClass( $parent, |
|
| 234 | + $instance = new self::$_cacheStorageClass($parent, |
|
| 235 | 235 | self::$_storageMethodParameters[self::$_cacheStorageMethod] |
| 236 | 236 | ); |
| 237 | 237 | if ($instance !== NULL) { |
@@ -1852,7 +1852,7 @@ discard block |
||
| 1852 | 1852 | /** |
| 1853 | 1853 | * Set calculation cache expiration time |
| 1854 | 1854 | * |
| 1855 | - * @param float $pValue |
|
| 1855 | + * @param integer $pValue |
|
| 1856 | 1856 | */ |
| 1857 | 1857 | public function setCalculationCacheExpirationTime($pValue = 15) { |
| 1858 | 1858 | self::$_calculationCacheExpirationTime = $pValue; |
@@ -1966,6 +1966,10 @@ discard block |
||
| 1966 | 1966 | return $formula; |
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | + /** |
|
| 1970 | + * @param string $fromSeparator |
|
| 1971 | + * @param string $toSeparator |
|
| 1972 | + */ |
|
| 1969 | 1973 | private static function _translateFormula($from,$to,$formula,$fromSeparator,$toSeparator) { |
| 1970 | 1974 | // Convert any Excel function names to the required language |
| 1971 | 1975 | if (self::$_localeLanguage !== 'en_us') { |
@@ -2386,7 +2390,7 @@ discard block |
||
| 2386 | 2390 | * Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0 |
| 2387 | 2391 | * |
| 2388 | 2392 | * @param mixed &$matrix matrix operand |
| 2389 | - * @return array An array comprising the number of rows, and number of columns |
|
| 2393 | + * @return integer[] An array comprising the number of rows, and number of columns |
|
| 2390 | 2394 | */ |
| 2391 | 2395 | public static function _getMatrixDimensions(&$matrix) { |
| 2392 | 2396 | $matrixRows = count($matrix); |
@@ -2409,6 +2413,10 @@ discard block |
||
| 2409 | 2413 | * |
| 2410 | 2414 | * @param mixed &$matrix1 First matrix operand |
| 2411 | 2415 | * @param mixed &$matrix2 Second matrix operand |
| 2416 | + * @param integer $matrix1Rows |
|
| 2417 | + * @param integer $matrix1Columns |
|
| 2418 | + * @param integer $matrix2Rows |
|
| 2419 | + * @param integer $matrix2Columns |
|
| 2412 | 2420 | */ |
| 2413 | 2421 | private static function _resizeMatricesShrink(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) { |
| 2414 | 2422 | if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
@@ -2448,6 +2456,10 @@ discard block |
||
| 2448 | 2456 | * |
| 2449 | 2457 | * @param mixed &$matrix1 First matrix operand |
| 2450 | 2458 | * @param mixed &$matrix2 Second matrix operand |
| 2459 | + * @param integer $matrix1Rows |
|
| 2460 | + * @param integer $matrix1Columns |
|
| 2461 | + * @param integer $matrix2Rows |
|
| 2462 | + * @param integer $matrix2Columns |
|
| 2451 | 2463 | */ |
| 2452 | 2464 | private static function _resizeMatricesExtend(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) { |
| 2453 | 2465 | if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
@@ -2525,7 +2537,7 @@ discard block |
||
| 2525 | 2537 | * Format type and details of an operand for display in the log (based on operand type) |
| 2526 | 2538 | * |
| 2527 | 2539 | * @param mixed $value First matrix operand |
| 2528 | - * @return mixed |
|
| 2540 | + * @return string|null |
|
| 2529 | 2541 | */ |
| 2530 | 2542 | private function _showTypeDetails($value) { |
| 2531 | 2543 | if ($this->writeDebugLog) { |
@@ -2558,6 +2570,9 @@ discard block |
||
| 2558 | 2570 | } // function _showTypeDetails() |
| 2559 | 2571 | |
| 2560 | 2572 | |
| 2573 | + /** |
|
| 2574 | + * @param string $formula |
|
| 2575 | + */ |
|
| 2561 | 2576 | private static function _convertMatrixReferences($formula) { |
| 2562 | 2577 | static $matrixReplaceFrom = array('{',';','}'); |
| 2563 | 2578 | static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))'); |
@@ -2615,6 +2630,10 @@ discard block |
||
| 2615 | 2630 | |
| 2616 | 2631 | |
| 2617 | 2632 | // Convert infix to postfix notation |
| 2633 | + |
|
| 2634 | + /** |
|
| 2635 | + * @param string $formula |
|
| 2636 | + */ |
|
| 2618 | 2637 | private function _parseFormula($formula, PHPExcel_Cell $pCell = null) { |
| 2619 | 2638 | if (($formula = self::_convertMatrixReferences(trim($formula))) === false) { |
| 2620 | 2639 | return FALSE; |
@@ -3001,6 +3020,10 @@ discard block |
||
| 3001 | 3020 | } |
| 3002 | 3021 | |
| 3003 | 3022 | // evaluate postfix notation |
| 3023 | + |
|
| 3024 | + /** |
|
| 3025 | + * @param string $cellID |
|
| 3026 | + */ |
|
| 3004 | 3027 | private function _processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell = null) { |
| 3005 | 3028 | if ($tokens == false) return false; |
| 3006 | 3029 | |
@@ -3500,6 +3523,9 @@ discard block |
||
| 3500 | 3523 | } // function _executeBinaryComparisonOperation() |
| 3501 | 3524 | |
| 3502 | 3525 | |
| 3526 | + /** |
|
| 3527 | + * @param string $matrixFunction |
|
| 3528 | + */ |
|
| 3503 | 3529 | private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) { |
| 3504 | 3530 | // Validate the two operands |
| 3505 | 3531 | if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false; |
@@ -3580,6 +3606,9 @@ discard block |
||
| 3580 | 3606 | } // function _executeNumericBinaryOperation() |
| 3581 | 3607 | |
| 3582 | 3608 | |
| 3609 | + /** |
|
| 3610 | + * @param string $message |
|
| 3611 | + */ |
|
| 3583 | 3612 | private function _writeDebug($message) { |
| 3584 | 3613 | // Only write the debug log if logging is enabled |
| 3585 | 3614 | if ($this->writeDebugLog) { |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** PHPExcel root directory */ |
| 30 | -if (!defined('PHPEXCEL_ROOT')) { |
|
| 30 | +if ( ! defined('PHPEXCEL_ROOT')) { |
|
| 31 | 31 | /** |
| 32 | 32 | * @ignore |
| 33 | 33 | */ |
| 34 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); |
|
| 35 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|
| 34 | + define('PHPEXCEL_ROOT', dirname(__FILE__).'/../'); |
|
| 35 | + require(PHPEXCEL_ROOT.'PHPExcel/Autoloader.php'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
| 39 | -if (!defined('CALCULATION_REGEXP_CELLREF')) { |
|
| 39 | +if ( ! defined('CALCULATION_REGEXP_CELLREF')) { |
|
| 40 | 40 | // Test for support of \P (multibyte options) in PCRE |
| 41 | - if(defined('PREG_BAD_UTF8_ERROR')) { |
|
| 41 | + if (defined('PREG_BAD_UTF8_ERROR')) { |
|
| 42 | 42 | // Cell reference (cell or range of cells, with or without a sheet reference) |
| 43 | - define('CALCULATION_REGEXP_CELLREF','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})'); |
|
| 43 | + define('CALCULATION_REGEXP_CELLREF', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})'); |
|
| 44 | 44 | // Named Range of cells |
| 45 | - define('CALCULATION_REGEXP_NAMEDRANGE','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)'); |
|
| 45 | + define('CALCULATION_REGEXP_NAMEDRANGE', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)'); |
|
| 46 | 46 | } else { |
| 47 | 47 | // Cell reference (cell or range of cells, with or without a sheet reference) |
| 48 | - define('CALCULATION_REGEXP_CELLREF','(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)'); |
|
| 48 | + define('CALCULATION_REGEXP_CELLREF', '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)'); |
|
| 49 | 49 | // Named Range of cells |
| 50 | - define('CALCULATION_REGEXP_NAMEDRANGE','(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)'); |
|
| 50 | + define('CALCULATION_REGEXP_NAMEDRANGE', '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)'); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | // String operand |
| 69 | 69 | const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"'; |
| 70 | 70 | // Opening bracket |
| 71 | - const CALCULATION_REGEXP_OPENBRACE = '\('; |
|
| 71 | + const CALCULATION_REGEXP_OPENBRACE = '\('; |
|
| 72 | 72 | // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it) |
| 73 | - const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\('; |
|
| 73 | + const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\('; |
|
| 74 | 74 | // Cell reference (cell or range of cells, with or without a sheet reference) |
| 75 | - const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF; |
|
| 75 | + const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF; |
|
| 76 | 76 | // Named Range of cells |
| 77 | - const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE; |
|
| 77 | + const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE; |
|
| 78 | 78 | // Error |
| 79 | - const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?'; |
|
| 79 | + const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?'; |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | /** constants */ |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | const RETURN_ARRAY_AS_VALUE = 'value'; |
| 85 | 85 | const RETURN_ARRAY_AS_ARRAY = 'array'; |
| 86 | 86 | |
| 87 | - private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE; |
|
| 87 | + private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE; |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @access private |
| 103 | 103 | * @var array |
| 104 | 104 | */ |
| 105 | - private static $_calculationCache = array (); |
|
| 105 | + private static $_calculationCache = array(); |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @access private |
| 131 | 131 | * @var array |
| 132 | 132 | */ |
| 133 | - private static $_operators = array('+' => true, '-' => true, '*' => true, '/' => true, |
|
| 134 | - '^' => true, '&' => true, '%' => false, '~' => false, |
|
| 135 | - '>' => true, '<' => true, '=' => true, '>=' => true, |
|
| 136 | - '<=' => true, '<>' => true, '|' => true, ':' => true |
|
| 133 | + private static $_operators = array('+' => true, '-' => true, '*' => true, '/' => true, |
|
| 134 | + '^' => true, '&' => true, '%' => false, '~' => false, |
|
| 135 | + '>' => true, '<' => true, '=' => true, '>=' => true, |
|
| 136 | + '<=' => true, '<>' => true, '|' => true, ':' => true |
|
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * @access private |
| 144 | 144 | * @var array |
| 145 | 145 | */ |
| 146 | - private static $_binaryOperators = array('+' => true, '-' => true, '*' => true, '/' => true, |
|
| 147 | - '^' => true, '&' => true, '>' => true, '<' => true, |
|
| 148 | - '=' => true, '>=' => true, '<=' => true, '<>' => true, |
|
| 149 | - '|' => true, ':' => true |
|
| 146 | + private static $_binaryOperators = array('+' => true, '-' => true, '*' => true, '/' => true, |
|
| 147 | + '^' => true, '&' => true, '>' => true, '<' => true, |
|
| 148 | + '=' => true, '>=' => true, '<=' => true, '<>' => true, |
|
| 149 | + '|' => true, ':' => true |
|
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -215,15 +215,15 @@ discard block |
||
| 215 | 215 | public $cyclicFormulaCount = 0; |
| 216 | 216 | |
| 217 | 217 | |
| 218 | - private $_savedPrecision = 12; |
|
| 218 | + private $_savedPrecision = 12; |
|
| 219 | 219 | |
| 220 | 220 | |
| 221 | - private static $_localeLanguage = 'en_us'; // US English (default locale) |
|
| 222 | - private static $_validLocaleLanguages = array( 'en' // English (default language) |
|
| 221 | + private static $_localeLanguage = 'en_us'; // US English (default locale) |
|
| 222 | + private static $_validLocaleLanguages = array('en' // English (default language) |
|
| 223 | 223 | ); |
| 224 | 224 | private static $_localeArgumentSeparator = ','; |
| 225 | 225 | private static $_localeFunctions = array(); |
| 226 | - public static $_localeBoolean = array( 'TRUE' => 'TRUE', |
|
| 226 | + public static $_localeBoolean = array('TRUE' => 'TRUE', |
|
| 227 | 227 | 'FALSE' => 'FALSE', |
| 228 | 228 | 'NULL' => 'NULL' |
| 229 | 229 | ); |
@@ -1682,8 +1682,8 @@ discard block |
||
| 1682 | 1682 | |
| 1683 | 1683 | private function __construct() { |
| 1684 | 1684 | $localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/'; |
| 1685 | - foreach (glob($localeFileDirectory.'/*',GLOB_ONLYDIR) as $filename) { |
|
| 1686 | - $filename = substr($filename,strlen($localeFileDirectory)+1); |
|
| 1685 | + foreach (glob($localeFileDirectory.'/*', GLOB_ONLYDIR) as $filename) { |
|
| 1686 | + $filename = substr($filename, strlen($localeFileDirectory) + 1); |
|
| 1687 | 1687 | if ($filename != 'en') { |
| 1688 | 1688 | self::$_validLocaleLanguages[] = $filename; |
| 1689 | 1689 | } |
@@ -1692,14 +1692,14 @@ discard block |
||
| 1692 | 1692 | $setPrecision = (PHP_INT_SIZE == 4) ? 12 : 16; |
| 1693 | 1693 | $this->_savedPrecision = ini_get('precision'); |
| 1694 | 1694 | if ($this->_savedPrecision < $setPrecision) { |
| 1695 | - ini_set('precision',$setPrecision); |
|
| 1695 | + ini_set('precision', $setPrecision); |
|
| 1696 | 1696 | } |
| 1697 | 1697 | } // function __construct() |
| 1698 | 1698 | |
| 1699 | 1699 | |
| 1700 | 1700 | public function __destruct() { |
| 1701 | 1701 | if ($this->_savedPrecision != ini_get('precision')) { |
| 1702 | - ini_set('precision',$this->_savedPrecision); |
|
| 1702 | + ini_set('precision', $this->_savedPrecision); |
|
| 1703 | 1703 | } |
| 1704 | 1704 | } |
| 1705 | 1705 | |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | * @return PHPExcel_Calculation |
| 1711 | 1711 | */ |
| 1712 | 1712 | public static function getInstance() { |
| 1713 | - if (!isset(self::$_instance) || (self::$_instance === NULL)) { |
|
| 1713 | + if ( ! isset(self::$_instance) || (self::$_instance === NULL)) { |
|
| 1714 | 1714 | self::$_instance = new PHPExcel_Calculation(); |
| 1715 | 1715 | } |
| 1716 | 1716 | |
@@ -1739,7 +1739,7 @@ discard block |
||
| 1739 | 1739 | * @throws Exception |
| 1740 | 1740 | */ |
| 1741 | 1741 | public final function __clone() { |
| 1742 | - throw new Exception ('Cloning a Singleton is not allowed!'); |
|
| 1742 | + throw new Exception('Cloning a Singleton is not allowed!'); |
|
| 1743 | 1743 | } // function __clone() |
| 1744 | 1744 | |
| 1745 | 1745 | |
@@ -1876,15 +1876,15 @@ discard block |
||
| 1876 | 1876 | * |
| 1877 | 1877 | * @return boolean |
| 1878 | 1878 | */ |
| 1879 | - public function setLocale($locale='en_us') { |
|
| 1879 | + public function setLocale($locale = 'en_us') { |
|
| 1880 | 1880 | // Identify our locale and language |
| 1881 | 1881 | $language = $locale = strtolower($locale); |
| 1882 | - if (strpos($locale,'_') !== false) { |
|
| 1883 | - list($language) = explode('_',$locale); |
|
| 1882 | + if (strpos($locale, '_') !== false) { |
|
| 1883 | + list($language) = explode('_', $locale); |
|
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | 1886 | // Test whether we have any language data for this language (any locale) |
| 1887 | - if (in_array($language,self::$_validLocaleLanguages)) { |
|
| 1887 | + if (in_array($language, self::$_validLocaleLanguages)) { |
|
| 1888 | 1888 | // initialise language/locale settings |
| 1889 | 1889 | self::$_localeFunctions = array(); |
| 1890 | 1890 | self::$_localeArgumentSeparator = ','; |
@@ -1892,20 +1892,20 @@ discard block |
||
| 1892 | 1892 | // Default is English, if user isn't requesting english, then read the necessary data from the locale files |
| 1893 | 1893 | if ($locale != 'en_us') { |
| 1894 | 1894 | // Search for a file with a list of function names for locale |
| 1895 | - $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_',DIRECTORY_SEPARATOR,$locale).DIRECTORY_SEPARATOR.'functions'; |
|
| 1896 | - if (!file_exists($functionNamesFile)) { |
|
| 1895 | + $functionNamesFile = PHPEXCEL_ROOT.'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $locale).DIRECTORY_SEPARATOR.'functions'; |
|
| 1896 | + if ( ! file_exists($functionNamesFile)) { |
|
| 1897 | 1897 | // If there isn't a locale specific function file, look for a language specific function file |
| 1898 | - $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'functions'; |
|
| 1899 | - if (!file_exists($functionNamesFile)) { |
|
| 1898 | + $functionNamesFile = PHPEXCEL_ROOT.'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'functions'; |
|
| 1899 | + if ( ! file_exists($functionNamesFile)) { |
|
| 1900 | 1900 | return false; |
| 1901 | 1901 | } |
| 1902 | 1902 | } |
| 1903 | 1903 | // Retrieve the list of locale or language specific function names |
| 1904 | - $localeFunctions = file($functionNamesFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 1904 | + $localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 1905 | 1905 | foreach ($localeFunctions as $localeFunction) { |
| 1906 | - list($localeFunction) = explode('##',$localeFunction); // Strip out comments |
|
| 1907 | - if (strpos($localeFunction,'=') !== false) { |
|
| 1908 | - list($fName,$lfName) = explode('=',$localeFunction); |
|
| 1906 | + list($localeFunction) = explode('##', $localeFunction); // Strip out comments |
|
| 1907 | + if (strpos($localeFunction, '=') !== false) { |
|
| 1908 | + list($fName, $lfName) = explode('=', $localeFunction); |
|
| 1909 | 1909 | $fName = trim($fName); |
| 1910 | 1910 | $lfName = trim($lfName); |
| 1911 | 1911 | if ((isset(self::$_PHPExcelFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) { |
@@ -1917,16 +1917,16 @@ discard block |
||
| 1917 | 1917 | if (isset(self::$_localeFunctions['TRUE'])) { self::$_localeBoolean['TRUE'] = self::$_localeFunctions['TRUE']; } |
| 1918 | 1918 | if (isset(self::$_localeFunctions['FALSE'])) { self::$_localeBoolean['FALSE'] = self::$_localeFunctions['FALSE']; } |
| 1919 | 1919 | |
| 1920 | - $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_',DIRECTORY_SEPARATOR,$locale).DIRECTORY_SEPARATOR.'config'; |
|
| 1921 | - if (!file_exists($configFile)) { |
|
| 1922 | - $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'config'; |
|
| 1920 | + $configFile = PHPEXCEL_ROOT.'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $locale).DIRECTORY_SEPARATOR.'config'; |
|
| 1921 | + if ( ! file_exists($configFile)) { |
|
| 1922 | + $configFile = PHPEXCEL_ROOT.'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'config'; |
|
| 1923 | 1923 | } |
| 1924 | 1924 | if (file_exists($configFile)) { |
| 1925 | - $localeSettings = file($configFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 1925 | + $localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 1926 | 1926 | foreach ($localeSettings as $localeSetting) { |
| 1927 | - list($localeSetting) = explode('##',$localeSetting); // Strip out comments |
|
| 1928 | - if (strpos($localeSetting,'=') !== false) { |
|
| 1929 | - list($settingName,$settingValue) = explode('=',$localeSetting); |
|
| 1927 | + list($localeSetting) = explode('##', $localeSetting); // Strip out comments |
|
| 1928 | + if (strpos($localeSetting, '=') !== false) { |
|
| 1929 | + list($settingName, $settingValue) = explode('=', $localeSetting); |
|
| 1930 | 1930 | $settingName = strtoupper(trim($settingName)); |
| 1931 | 1931 | switch ($settingName) { |
| 1932 | 1932 | case 'ARGUMENTSEPARATOR' : |
@@ -1948,48 +1948,48 @@ discard block |
||
| 1948 | 1948 | |
| 1949 | 1949 | |
| 1950 | 1950 | |
| 1951 | - public static function _translateSeparator($fromSeparator,$toSeparator,$formula,&$inBraces) { |
|
| 1951 | + public static function _translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces) { |
|
| 1952 | 1952 | $strlen = mb_strlen($formula); |
| 1953 | 1953 | for ($i = 0; $i < $strlen; ++$i) { |
| 1954 | - $chr = mb_substr($formula,$i,1); |
|
| 1954 | + $chr = mb_substr($formula, $i, 1); |
|
| 1955 | 1955 | switch ($chr) { |
| 1956 | 1956 | case '{' : $inBraces = true; |
| 1957 | 1957 | break; |
| 1958 | 1958 | case '}' : $inBraces = false; |
| 1959 | 1959 | break; |
| 1960 | 1960 | case $fromSeparator : |
| 1961 | - if (!$inBraces) { |
|
| 1962 | - $formula = mb_substr($formula,0,$i).$toSeparator.mb_substr($formula,$i+1); |
|
| 1961 | + if ( ! $inBraces) { |
|
| 1962 | + $formula = mb_substr($formula, 0, $i).$toSeparator.mb_substr($formula, $i + 1); |
|
| 1963 | 1963 | } |
| 1964 | 1964 | } |
| 1965 | 1965 | } |
| 1966 | 1966 | return $formula; |
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | - private static function _translateFormula($from,$to,$formula,$fromSeparator,$toSeparator) { |
|
| 1969 | + private static function _translateFormula($from, $to, $formula, $fromSeparator, $toSeparator) { |
|
| 1970 | 1970 | // Convert any Excel function names to the required language |
| 1971 | 1971 | if (self::$_localeLanguage !== 'en_us') { |
| 1972 | 1972 | $inBraces = false; |
| 1973 | 1973 | // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators |
| 1974 | - if (strpos($formula,'"') !== false) { |
|
| 1974 | + if (strpos($formula, '"') !== false) { |
|
| 1975 | 1975 | // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded |
| 1976 | 1976 | // the formula |
| 1977 | - $temp = explode('"',$formula); |
|
| 1977 | + $temp = explode('"', $formula); |
|
| 1978 | 1978 | $i = false; |
| 1979 | - foreach($temp as &$value) { |
|
| 1979 | + foreach ($temp as &$value) { |
|
| 1980 | 1980 | // Only count/replace in alternating array entries |
| 1981 | - if ($i = !$i) { |
|
| 1982 | - $value = preg_replace($from,$to,$value); |
|
| 1983 | - $value = self::_translateSeparator($fromSeparator,$toSeparator,$value,$inBraces); |
|
| 1981 | + if ($i = ! $i) { |
|
| 1982 | + $value = preg_replace($from, $to, $value); |
|
| 1983 | + $value = self::_translateSeparator($fromSeparator, $toSeparator, $value, $inBraces); |
|
| 1984 | 1984 | } |
| 1985 | 1985 | } |
| 1986 | 1986 | unset($value); |
| 1987 | 1987 | // Then rebuild the formula string |
| 1988 | - $formula = implode('"',$temp); |
|
| 1988 | + $formula = implode('"', $temp); |
|
| 1989 | 1989 | } else { |
| 1990 | 1990 | // If there's no quoted strings, then we do a simple count/replace |
| 1991 | - $formula = preg_replace($from,$to,$formula); |
|
| 1992 | - $formula = self::_translateSeparator($fromSeparator,$toSeparator,$formula,$inBraces); |
|
| 1991 | + $formula = preg_replace($from, $to, $formula); |
|
| 1992 | + $formula = self::_translateSeparator($fromSeparator, $toSeparator, $formula, $inBraces); |
|
| 1993 | 1993 | } |
| 1994 | 1994 | } |
| 1995 | 1995 | |
@@ -2002,10 +2002,10 @@ discard block |
||
| 2002 | 2002 | public function _translateFormulaToLocale($formula) { |
| 2003 | 2003 | if (self::$functionReplaceFromExcel === NULL) { |
| 2004 | 2004 | self::$functionReplaceFromExcel = array(); |
| 2005 | - foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) { |
|
| 2005 | + foreach (array_keys(self::$_localeFunctions) as $excelFunctionName) { |
|
| 2006 | 2006 | self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelFunctionName).'([\s]*\()/Ui'; |
| 2007 | 2007 | } |
| 2008 | - foreach(array_keys(self::$_localeBoolean) as $excelBoolean) { |
|
| 2008 | + foreach (array_keys(self::$_localeBoolean) as $excelBoolean) { |
|
| 2009 | 2009 | self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui'; |
| 2010 | 2010 | } |
| 2011 | 2011 | |
@@ -2013,49 +2013,49 @@ discard block |
||
| 2013 | 2013 | |
| 2014 | 2014 | if (self::$functionReplaceToLocale === NULL) { |
| 2015 | 2015 | self::$functionReplaceToLocale = array(); |
| 2016 | - foreach(array_values(self::$_localeFunctions) as $localeFunctionName) { |
|
| 2016 | + foreach (array_values(self::$_localeFunctions) as $localeFunctionName) { |
|
| 2017 | 2017 | self::$functionReplaceToLocale[] = '$1'.trim($localeFunctionName).'$2'; |
| 2018 | 2018 | } |
| 2019 | - foreach(array_values(self::$_localeBoolean) as $localeBoolean) { |
|
| 2019 | + foreach (array_values(self::$_localeBoolean) as $localeBoolean) { |
|
| 2020 | 2020 | self::$functionReplaceToLocale[] = '$1'.trim($localeBoolean).'$2'; |
| 2021 | 2021 | } |
| 2022 | 2022 | } |
| 2023 | 2023 | |
| 2024 | - return self::_translateFormula(self::$functionReplaceFromExcel,self::$functionReplaceToLocale,$formula,',',self::$_localeArgumentSeparator); |
|
| 2024 | + return self::_translateFormula(self::$functionReplaceFromExcel, self::$functionReplaceToLocale, $formula, ',', self::$_localeArgumentSeparator); |
|
| 2025 | 2025 | } // function _translateFormulaToLocale() |
| 2026 | 2026 | |
| 2027 | 2027 | |
| 2028 | - private static $functionReplaceFromLocale = null; |
|
| 2029 | - private static $functionReplaceToExcel = null; |
|
| 2028 | + private static $functionReplaceFromLocale = null; |
|
| 2029 | + private static $functionReplaceToExcel = null; |
|
| 2030 | 2030 | |
| 2031 | 2031 | public function _translateFormulaToEnglish($formula) { |
| 2032 | 2032 | if (self::$functionReplaceFromLocale === NULL) { |
| 2033 | 2033 | self::$functionReplaceFromLocale = array(); |
| 2034 | - foreach(array_values(self::$_localeFunctions) as $localeFunctionName) { |
|
| 2034 | + foreach (array_values(self::$_localeFunctions) as $localeFunctionName) { |
|
| 2035 | 2035 | self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($localeFunctionName).'([\s]*\()/Ui'; |
| 2036 | 2036 | } |
| 2037 | - foreach(array_values(self::$_localeBoolean) as $excelBoolean) { |
|
| 2037 | + foreach (array_values(self::$_localeBoolean) as $excelBoolean) { |
|
| 2038 | 2038 | self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui'; |
| 2039 | 2039 | } |
| 2040 | 2040 | } |
| 2041 | 2041 | |
| 2042 | 2042 | if (self::$functionReplaceToExcel === NULL) { |
| 2043 | 2043 | self::$functionReplaceToExcel = array(); |
| 2044 | - foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) { |
|
| 2044 | + foreach (array_keys(self::$_localeFunctions) as $excelFunctionName) { |
|
| 2045 | 2045 | self::$functionReplaceToExcel[] = '$1'.trim($excelFunctionName).'$2'; |
| 2046 | 2046 | } |
| 2047 | - foreach(array_keys(self::$_localeBoolean) as $excelBoolean) { |
|
| 2047 | + foreach (array_keys(self::$_localeBoolean) as $excelBoolean) { |
|
| 2048 | 2048 | self::$functionReplaceToExcel[] = '$1'.trim($excelBoolean).'$2'; |
| 2049 | 2049 | } |
| 2050 | 2050 | } |
| 2051 | 2051 | |
| 2052 | - return self::_translateFormula(self::$functionReplaceFromLocale,self::$functionReplaceToExcel,$formula,self::$_localeArgumentSeparator,','); |
|
| 2052 | + return self::_translateFormula(self::$functionReplaceFromLocale, self::$functionReplaceToExcel, $formula, self::$_localeArgumentSeparator, ','); |
|
| 2053 | 2053 | } // function _translateFormulaToEnglish() |
| 2054 | 2054 | |
| 2055 | 2055 | |
| 2056 | 2056 | public static function _localeFunc($function) { |
| 2057 | 2057 | if (self::$_localeLanguage !== 'en_us') { |
| 2058 | - $functionName = trim($function,'('); |
|
| 2058 | + $functionName = trim($function, '('); |
|
| 2059 | 2059 | if (isset(self::$_localeFunctions[$functionName])) { |
| 2060 | 2060 | $brace = ($functionName != $function); |
| 2061 | 2061 | $function = self::$_localeFunctions[$functionName]; |
@@ -2084,7 +2084,7 @@ discard block |
||
| 2084 | 2084 | // Return strings wrapped in quotes |
| 2085 | 2085 | return '"'.$value.'"'; |
| 2086 | 2086 | // Convert numeric errors to NaN error |
| 2087 | - } else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
|
| 2087 | + } else if ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
|
| 2088 | 2088 | return PHPExcel_Calculation_Functions::NaN(); |
| 2089 | 2089 | } |
| 2090 | 2090 | |
@@ -2100,11 +2100,11 @@ discard block |
||
| 2100 | 2100 | */ |
| 2101 | 2101 | public static function _unwrapResult($value) { |
| 2102 | 2102 | if (is_string($value)) { |
| 2103 | - if ((isset($value{0})) && ($value{0} == '"') && (substr($value,-1) == '"')) { |
|
| 2104 | - return substr($value,1,-1); |
|
| 2103 | + if ((isset($value{0})) && ($value{0} == '"') && (substr($value, -1) == '"')) { |
|
| 2104 | + return substr($value, 1, -1); |
|
| 2105 | 2105 | } |
| 2106 | 2106 | // Convert numeric errors to NaN error |
| 2107 | - } else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
|
| 2107 | + } else if ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
|
| 2108 | 2108 | return PHPExcel_Calculation_Functions::NaN(); |
| 2109 | 2109 | } |
| 2110 | 2110 | return $value; |
@@ -2176,11 +2176,11 @@ discard block |
||
| 2176 | 2176 | // If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it |
| 2177 | 2177 | $r = array_keys($result); |
| 2178 | 2178 | $r = array_shift($r); |
| 2179 | - if (!is_numeric($r)) { return PHPExcel_Calculation_Functions::VALUE(); } |
|
| 2179 | + if ( ! is_numeric($r)) { return PHPExcel_Calculation_Functions::VALUE(); } |
|
| 2180 | 2180 | if (is_array($result[$r])) { |
| 2181 | 2181 | $c = array_keys($result[$r]); |
| 2182 | 2182 | $c = array_shift($c); |
| 2183 | - if (!is_numeric($c)) { |
|
| 2183 | + if ( ! is_numeric($c)) { |
|
| 2184 | 2184 | return PHPExcel_Calculation_Functions::VALUE(); |
| 2185 | 2185 | } |
| 2186 | 2186 | } |
@@ -2190,7 +2190,7 @@ discard block |
||
| 2190 | 2190 | |
| 2191 | 2191 | if ($result === NULL) { |
| 2192 | 2192 | return 0; |
| 2193 | - } elseif((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) { |
|
| 2193 | + } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) { |
|
| 2194 | 2194 | return PHPExcel_Calculation_Functions::NaN(); |
| 2195 | 2195 | } |
| 2196 | 2196 | return $result; |
@@ -2208,9 +2208,9 @@ discard block |
||
| 2208 | 2208 | // Basic validation that this is indeed a formula |
| 2209 | 2209 | // We return an empty array if not |
| 2210 | 2210 | $formula = trim($formula); |
| 2211 | - if ((!isset($formula{0})) || ($formula{0} != '=')) return array(); |
|
| 2212 | - $formula = ltrim(substr($formula,1)); |
|
| 2213 | - if (!isset($formula{0})) return array(); |
|
| 2211 | + if (( ! isset($formula{0})) || ($formula{0} != '=')) return array(); |
|
| 2212 | + $formula = ltrim(substr($formula, 1)); |
|
| 2213 | + if ( ! isset($formula{0})) return array(); |
|
| 2214 | 2214 | |
| 2215 | 2215 | // Parse the formula and return the token stack |
| 2216 | 2216 | return $this->_parseFormula($formula); |
@@ -2224,7 +2224,7 @@ discard block |
||
| 2224 | 2224 | * @return mixed |
| 2225 | 2225 | * @throws Exception |
| 2226 | 2226 | */ |
| 2227 | - public function calculateFormula($formula, $cellID=null, PHPExcel_Cell $pCell = null) { |
|
| 2227 | + public function calculateFormula($formula, $cellID = null, PHPExcel_Cell $pCell = null) { |
|
| 2228 | 2228 | // Initialise the logging settings |
| 2229 | 2229 | $this->formulaError = null; |
| 2230 | 2230 | $this->debugLog = $this->debugLogStack = array(); |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | * @return mixed |
| 2257 | 2257 | * @throws Exception |
| 2258 | 2258 | */ |
| 2259 | - public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pCell = null) { |
|
| 2259 | + public function _calculateFormulaValue($formula, $cellID = null, PHPExcel_Cell $pCell = null) { |
|
| 2260 | 2260 | // echo '<b>'.$cellID.'</b><br />'; |
| 2261 | 2261 | $cellValue = ''; |
| 2262 | 2262 | |
@@ -2264,8 +2264,8 @@ discard block |
||
| 2264 | 2264 | // We simply return the "cell value" (formula) if not |
| 2265 | 2265 | $formula = trim($formula); |
| 2266 | 2266 | if ($formula{0} != '=') return self::_wrapResult($formula); |
| 2267 | - $formula = ltrim(substr($formula,1)); |
|
| 2268 | - if (!isset($formula{0})) return self::_wrapResult($formula); |
|
| 2267 | + $formula = ltrim(substr($formula, 1)); |
|
| 2268 | + if ( ! isset($formula{0})) return self::_wrapResult($formula); |
|
| 2269 | 2269 | |
| 2270 | 2270 | $wsTitle = "\x00Wrk"; |
| 2271 | 2271 | if ($pCell !== NULL) { |
@@ -2304,7 +2304,7 @@ discard block |
||
| 2304 | 2304 | } |
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | - if ((in_array($wsTitle.'!'.$cellID,$this->debugLogStack)) && ($wsTitle != "\x00Wrk")) { |
|
| 2307 | + if ((in_array($wsTitle.'!'.$cellID, $this->debugLogStack)) && ($wsTitle != "\x00Wrk")) { |
|
| 2308 | 2308 | if ($this->cyclicFormulaCount <= 0) { |
| 2309 | 2309 | return $this->_raiseFormulaError('Cyclic Reference in Formula'); |
| 2310 | 2310 | } elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) && |
@@ -2352,33 +2352,33 @@ discard block |
||
| 2352 | 2352 | * 1 = shrink to fit |
| 2353 | 2353 | * 2 = extend to fit |
| 2354 | 2354 | */ |
| 2355 | - private static function _checkMatrixOperands(&$operand1,&$operand2,$resize = 1) { |
|
| 2355 | + private static function _checkMatrixOperands(&$operand1, &$operand2, $resize = 1) { |
|
| 2356 | 2356 | // Examine each of the two operands, and turn them into an array if they aren't one already |
| 2357 | 2357 | // Note that this function should only be called if one or both of the operand is already an array |
| 2358 | - if (!is_array($operand1)) { |
|
| 2359 | - list($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand2); |
|
| 2360 | - $operand1 = array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand1)); |
|
| 2358 | + if ( ! is_array($operand1)) { |
|
| 2359 | + list($matrixRows, $matrixColumns) = self::_getMatrixDimensions($operand2); |
|
| 2360 | + $operand1 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand1)); |
|
| 2361 | 2361 | $resize = 0; |
| 2362 | - } elseif (!is_array($operand2)) { |
|
| 2363 | - list($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand1); |
|
| 2364 | - $operand2 = array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand2)); |
|
| 2362 | + } elseif ( ! is_array($operand2)) { |
|
| 2363 | + list($matrixRows, $matrixColumns) = self::_getMatrixDimensions($operand1); |
|
| 2364 | + $operand2 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand2)); |
|
| 2365 | 2365 | $resize = 0; |
| 2366 | 2366 | } |
| 2367 | 2367 | |
| 2368 | - list($matrix1Rows,$matrix1Columns) = self::_getMatrixDimensions($operand1); |
|
| 2369 | - list($matrix2Rows,$matrix2Columns) = self::_getMatrixDimensions($operand2); |
|
| 2368 | + list($matrix1Rows, $matrix1Columns) = self::_getMatrixDimensions($operand1); |
|
| 2369 | + list($matrix2Rows, $matrix2Columns) = self::_getMatrixDimensions($operand2); |
|
| 2370 | 2370 | if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) { |
| 2371 | 2371 | $resize = 1; |
| 2372 | 2372 | } |
| 2373 | 2373 | |
| 2374 | 2374 | if ($resize == 2) { |
| 2375 | 2375 | // Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger |
| 2376 | - self::_resizeMatricesExtend($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns); |
|
| 2376 | + self::_resizeMatricesExtend($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns); |
|
| 2377 | 2377 | } elseif ($resize == 1) { |
| 2378 | 2378 | // Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller |
| 2379 | - self::_resizeMatricesShrink($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns); |
|
| 2379 | + self::_resizeMatricesShrink($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns); |
|
| 2380 | 2380 | } |
| 2381 | - return array( $matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns); |
|
| 2381 | + return array($matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns); |
|
| 2382 | 2382 | } // function _checkMatrixOperands() |
| 2383 | 2383 | |
| 2384 | 2384 | |
@@ -2391,16 +2391,16 @@ discard block |
||
| 2391 | 2391 | public static function _getMatrixDimensions(&$matrix) { |
| 2392 | 2392 | $matrixRows = count($matrix); |
| 2393 | 2393 | $matrixColumns = 0; |
| 2394 | - foreach($matrix as $rowKey => $rowValue) { |
|
| 2395 | - $matrixColumns = max(count($rowValue),$matrixColumns); |
|
| 2396 | - if (!is_array($rowValue)) { |
|
| 2394 | + foreach ($matrix as $rowKey => $rowValue) { |
|
| 2395 | + $matrixColumns = max(count($rowValue), $matrixColumns); |
|
| 2396 | + if ( ! is_array($rowValue)) { |
|
| 2397 | 2397 | $matrix[$rowKey] = array($rowValue); |
| 2398 | 2398 | } else { |
| 2399 | 2399 | $matrix[$rowKey] = array_values($rowValue); |
| 2400 | 2400 | } |
| 2401 | 2401 | } |
| 2402 | 2402 | $matrix = array_values($matrix); |
| 2403 | - return array($matrixRows,$matrixColumns); |
|
| 2403 | + return array($matrixRows, $matrixColumns); |
|
| 2404 | 2404 | } // function _getMatrixDimensions() |
| 2405 | 2405 | |
| 2406 | 2406 | |
@@ -2410,7 +2410,7 @@ discard block |
||
| 2410 | 2410 | * @param mixed &$matrix1 First matrix operand |
| 2411 | 2411 | * @param mixed &$matrix2 Second matrix operand |
| 2412 | 2412 | */ |
| 2413 | - private static function _resizeMatricesShrink(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) { |
|
| 2413 | + private static function _resizeMatricesShrink(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns) { |
|
| 2414 | 2414 | if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
| 2415 | 2415 | if ($matrix2Columns < $matrix1Columns) { |
| 2416 | 2416 | for ($i = 0; $i < $matrix1Rows; ++$i) { |
@@ -2449,18 +2449,18 @@ discard block |
||
| 2449 | 2449 | * @param mixed &$matrix1 First matrix operand |
| 2450 | 2450 | * @param mixed &$matrix2 Second matrix operand |
| 2451 | 2451 | */ |
| 2452 | - private static function _resizeMatricesExtend(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) { |
|
| 2452 | + private static function _resizeMatricesExtend(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns) { |
|
| 2453 | 2453 | if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
| 2454 | 2454 | if ($matrix2Columns < $matrix1Columns) { |
| 2455 | 2455 | for ($i = 0; $i < $matrix2Rows; ++$i) { |
| 2456 | - $x = $matrix2[$i][$matrix2Columns-1]; |
|
| 2456 | + $x = $matrix2[$i][$matrix2Columns - 1]; |
|
| 2457 | 2457 | for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) { |
| 2458 | 2458 | $matrix2[$i][$j] = $x; |
| 2459 | 2459 | } |
| 2460 | 2460 | } |
| 2461 | 2461 | } |
| 2462 | 2462 | if ($matrix2Rows < $matrix1Rows) { |
| 2463 | - $x = $matrix2[$matrix2Rows-1]; |
|
| 2463 | + $x = $matrix2[$matrix2Rows - 1]; |
|
| 2464 | 2464 | for ($i = 0; $i < $matrix1Rows; ++$i) { |
| 2465 | 2465 | $matrix2[$i] = $x; |
| 2466 | 2466 | } |
@@ -2470,14 +2470,14 @@ discard block |
||
| 2470 | 2470 | if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) { |
| 2471 | 2471 | if ($matrix1Columns < $matrix2Columns) { |
| 2472 | 2472 | for ($i = 0; $i < $matrix1Rows; ++$i) { |
| 2473 | - $x = $matrix1[$i][$matrix1Columns-1]; |
|
| 2473 | + $x = $matrix1[$i][$matrix1Columns - 1]; |
|
| 2474 | 2474 | for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) { |
| 2475 | 2475 | $matrix1[$i][$j] = $x; |
| 2476 | 2476 | } |
| 2477 | 2477 | } |
| 2478 | 2478 | } |
| 2479 | 2479 | if ($matrix1Rows < $matrix2Rows) { |
| 2480 | - $x = $matrix1[$matrix1Rows-1]; |
|
| 2480 | + $x = $matrix1[$matrix1Rows - 1]; |
|
| 2481 | 2481 | for ($i = 0; $i < $matrix2Rows; ++$i) { |
| 2482 | 2482 | $matrix1[$i] = $x; |
| 2483 | 2483 | } |
@@ -2502,18 +2502,18 @@ discard block |
||
| 2502 | 2502 | if (is_array($value)) { |
| 2503 | 2503 | $returnMatrix = array(); |
| 2504 | 2504 | $pad = $rpad = ', '; |
| 2505 | - foreach($value as $row) { |
|
| 2505 | + foreach ($value as $row) { |
|
| 2506 | 2506 | if (is_array($row)) { |
| 2507 | - $returnMatrix[] = implode($pad,array_map(array($this,'_showValue'),$row)); |
|
| 2507 | + $returnMatrix[] = implode($pad, array_map(array($this, '_showValue'), $row)); |
|
| 2508 | 2508 | $rpad = '; '; |
| 2509 | 2509 | } else { |
| 2510 | 2510 | $returnMatrix[] = $this->_showValue($row); |
| 2511 | 2511 | } |
| 2512 | 2512 | } |
| 2513 | - return '{ '.implode($rpad,$returnMatrix).' }'; |
|
| 2514 | - } elseif(is_string($value) && (trim($value,'"') == $value)) { |
|
| 2513 | + return '{ '.implode($rpad, $returnMatrix).' }'; |
|
| 2514 | + } elseif (is_string($value) && (trim($value, '"') == $value)) { |
|
| 2515 | 2515 | return '"'.$value.'"'; |
| 2516 | - } elseif(is_bool($value)) { |
|
| 2516 | + } elseif (is_bool($value)) { |
|
| 2517 | 2517 | return ($value) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE']; |
| 2518 | 2518 | } |
| 2519 | 2519 | } |
@@ -2538,11 +2538,11 @@ discard block |
||
| 2538 | 2538 | return 'a NULL value'; |
| 2539 | 2539 | } elseif (is_float($value)) { |
| 2540 | 2540 | $typeString = 'a floating point number'; |
| 2541 | - } elseif(is_int($value)) { |
|
| 2541 | + } elseif (is_int($value)) { |
|
| 2542 | 2542 | $typeString = 'an integer number'; |
| 2543 | - } elseif(is_bool($value)) { |
|
| 2543 | + } elseif (is_bool($value)) { |
|
| 2544 | 2544 | $typeString = 'a boolean'; |
| 2545 | - } elseif(is_array($value)) { |
|
| 2545 | + } elseif (is_array($value)) { |
|
| 2546 | 2546 | $typeString = 'a matrix'; |
| 2547 | 2547 | } else { |
| 2548 | 2548 | if ($value == '') { |
@@ -2559,35 +2559,35 @@ discard block |
||
| 2559 | 2559 | |
| 2560 | 2560 | |
| 2561 | 2561 | private static function _convertMatrixReferences($formula) { |
| 2562 | - static $matrixReplaceFrom = array('{',';','}'); |
|
| 2563 | - static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))'); |
|
| 2562 | + static $matrixReplaceFrom = array('{', ';', '}'); |
|
| 2563 | + static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))'); |
|
| 2564 | 2564 | |
| 2565 | 2565 | // Convert any Excel matrix references to the MKMATRIX() function |
| 2566 | - if (strpos($formula,'{') !== false) { |
|
| 2566 | + if (strpos($formula, '{') !== false) { |
|
| 2567 | 2567 | // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators |
| 2568 | - if (strpos($formula,'"') !== false) { |
|
| 2568 | + if (strpos($formula, '"') !== false) { |
|
| 2569 | 2569 | // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded |
| 2570 | 2570 | // the formula |
| 2571 | - $temp = explode('"',$formula); |
|
| 2571 | + $temp = explode('"', $formula); |
|
| 2572 | 2572 | // Open and Closed counts used for trapping mismatched braces in the formula |
| 2573 | 2573 | $openCount = $closeCount = 0; |
| 2574 | 2574 | $i = false; |
| 2575 | - foreach($temp as &$value) { |
|
| 2575 | + foreach ($temp as &$value) { |
|
| 2576 | 2576 | // Only count/replace in alternating array entries |
| 2577 | - if ($i = !$i) { |
|
| 2578 | - $openCount += substr_count($value,'{'); |
|
| 2579 | - $closeCount += substr_count($value,'}'); |
|
| 2580 | - $value = str_replace($matrixReplaceFrom,$matrixReplaceTo,$value); |
|
| 2577 | + if ($i = ! $i) { |
|
| 2578 | + $openCount += substr_count($value, '{'); |
|
| 2579 | + $closeCount += substr_count($value, '}'); |
|
| 2580 | + $value = str_replace($matrixReplaceFrom, $matrixReplaceTo, $value); |
|
| 2581 | 2581 | } |
| 2582 | 2582 | } |
| 2583 | 2583 | unset($value); |
| 2584 | 2584 | // Then rebuild the formula string |
| 2585 | - $formula = implode('"',$temp); |
|
| 2585 | + $formula = implode('"', $temp); |
|
| 2586 | 2586 | } else { |
| 2587 | 2587 | // If there's no quoted strings, then we do a simple count/replace |
| 2588 | - $openCount = substr_count($formula,'{'); |
|
| 2589 | - $closeCount = substr_count($formula,'}'); |
|
| 2590 | - $formula = str_replace($matrixReplaceFrom,$matrixReplaceTo,$formula); |
|
| 2588 | + $openCount = substr_count($formula, '{'); |
|
| 2589 | + $closeCount = substr_count($formula, '}'); |
|
| 2590 | + $formula = str_replace($matrixReplaceFrom, $matrixReplaceTo, $formula); |
|
| 2591 | 2591 | } |
| 2592 | 2592 | // Trap for mismatched braces and trigger an appropriate error |
| 2593 | 2593 | if ($openCount < $closeCount) { |
@@ -2627,28 +2627,28 @@ discard block |
||
| 2627 | 2627 | // Binary Operators |
| 2628 | 2628 | // These operators always work on two values |
| 2629 | 2629 | // Array key is the operator, the value indicates whether this is a left or right associative operator |
| 2630 | - $operatorAssociativity = array('^' => 0, // Exponentiation |
|
| 2631 | - '*' => 0, '/' => 0, // Multiplication and Division |
|
| 2632 | - '+' => 0, '-' => 0, // Addition and Subtraction |
|
| 2633 | - '&' => 0, // Concatenation |
|
| 2634 | - '|' => 0, ':' => 0, // Intersect and Range |
|
| 2630 | + $operatorAssociativity = array('^' => 0, // Exponentiation |
|
| 2631 | + '*' => 0, '/' => 0, // Multiplication and Division |
|
| 2632 | + '+' => 0, '-' => 0, // Addition and Subtraction |
|
| 2633 | + '&' => 0, // Concatenation |
|
| 2634 | + '|' => 0, ':' => 0, // Intersect and Range |
|
| 2635 | 2635 | '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison |
| 2636 | 2636 | ); |
| 2637 | 2637 | // Comparison (Boolean) Operators |
| 2638 | 2638 | // These operators work on two values, but always return a boolean result |
| 2639 | - $comparisonOperators = array('>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true); |
|
| 2639 | + $comparisonOperators = array('>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true); |
|
| 2640 | 2640 | |
| 2641 | 2641 | // Operator Precedence |
| 2642 | 2642 | // This list includes all valid operators, whether binary (including boolean) or unary (such as %) |
| 2643 | 2643 | // Array key is the operator, the value is its precedence |
| 2644 | - $operatorPrecedence = array(':' => 8, // Range |
|
| 2645 | - '|' => 7, // Intersect |
|
| 2646 | - '~' => 6, // Negation |
|
| 2647 | - '%' => 5, // Percentage |
|
| 2648 | - '^' => 4, // Exponentiation |
|
| 2649 | - '*' => 3, '/' => 3, // Multiplication and Division |
|
| 2650 | - '+' => 2, '-' => 2, // Addition and Subtraction |
|
| 2651 | - '&' => 1, // Concatenation |
|
| 2644 | + $operatorPrecedence = array(':' => 8, // Range |
|
| 2645 | + '|' => 7, // Intersect |
|
| 2646 | + '~' => 6, // Negation |
|
| 2647 | + '%' => 5, // Percentage |
|
| 2648 | + '^' => 4, // Exponentiation |
|
| 2649 | + '*' => 3, '/' => 3, // Multiplication and Division |
|
| 2650 | + '+' => 2, '-' => 2, // Addition and Subtraction |
|
| 2651 | + '&' => 1, // Concatenation |
|
| 2652 | 2652 | '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison |
| 2653 | 2653 | ); |
| 2654 | 2654 | |
@@ -2665,17 +2665,17 @@ discard block |
||
| 2665 | 2665 | $index = 0; |
| 2666 | 2666 | $stack = new PHPExcel_Token_Stack; |
| 2667 | 2667 | $output = array(); |
| 2668 | - $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a |
|
| 2668 | + $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a |
|
| 2669 | 2669 | // - is a negation or + is a positive operator rather than an operation |
| 2670 | - $expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand |
|
| 2670 | + $expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand |
|
| 2671 | 2671 | // should be null in a function call |
| 2672 | 2672 | // The guts of the lexical parser |
| 2673 | 2673 | // Loop through the formula extracting each operator and operand in turn |
| 2674 | - while(true) { |
|
| 2674 | + while (true) { |
|
| 2675 | 2675 | // echo 'Assessing Expression <b>'.substr($formula, $index).'</b><br />'; |
| 2676 | 2676 | $opCharacter = $formula{$index}; // Get the first character of the value at the current index position |
| 2677 | 2677 | // echo 'Initial character of expression block is '.$opCharacter.'<br />'; |
| 2678 | - if ((isset($comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset($comparisonOperators[$formula{$index+1}]))) { |
|
| 2678 | + if ((isset($comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset($comparisonOperators[$formula{$index + 1}]))) { |
|
| 2679 | 2679 | $opCharacter .= $formula{++$index}; |
| 2680 | 2680 | // echo 'Initial character of expression block is comparison operator '.$opCharacter.'<br />'; |
| 2681 | 2681 | } |
@@ -2685,29 +2685,29 @@ discard block |
||
| 2685 | 2685 | // echo '$isOperandOrFunction is '.(($isOperandOrFunction) ? 'True' : 'False').'<br />'; |
| 2686 | 2686 | // var_dump($match); |
| 2687 | 2687 | |
| 2688 | - if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus? |
|
| 2688 | + if ($opCharacter == '-' && ! $expectingOperator) { // Is it a negation instead of a minus? |
|
| 2689 | 2689 | // echo 'Element is a Negation operator<br />'; |
| 2690 | - $stack->push('Unary Operator','~'); // Put a negation on the stack |
|
| 2691 | - ++$index; // and drop the negation symbol |
|
| 2690 | + $stack->push('Unary Operator', '~'); // Put a negation on the stack |
|
| 2691 | + ++$index; // and drop the negation symbol |
|
| 2692 | 2692 | } elseif ($opCharacter == '%' && $expectingOperator) { |
| 2693 | 2693 | // echo 'Element is a Percentage operator<br />'; |
| 2694 | - $stack->push('Unary Operator','%'); // Put a percentage on the stack |
|
| 2694 | + $stack->push('Unary Operator', '%'); // Put a percentage on the stack |
|
| 2695 | 2695 | ++$index; |
| 2696 | - } elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded? |
|
| 2696 | + } elseif ($opCharacter == '+' && ! $expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded? |
|
| 2697 | 2697 | // echo 'Element is a Positive number, not Plus operator<br />'; |
| 2698 | - ++$index; // Drop the redundant plus symbol |
|
| 2699 | - } elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal |
|
| 2700 | - return $this->_raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression |
|
| 2698 | + ++$index; // Drop the redundant plus symbol |
|
| 2699 | + } elseif ((($opCharacter == '~') || ($opCharacter == '|')) && ( ! $isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal |
|
| 2700 | + return $this->_raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression |
|
| 2701 | 2701 | |
| 2702 | 2702 | } elseif ((isset(self::$_operators[$opCharacter]) or $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack? |
| 2703 | 2703 | // echo 'Element with value '.$opCharacter.' is an Operator<br />'; |
| 2704 | - while($stack->count() > 0 && |
|
| 2704 | + while ($stack->count() > 0 && |
|
| 2705 | 2705 | ($o2 = $stack->last()) && |
| 2706 | 2706 | isset(self::$_operators[$o2['value']]) && |
| 2707 | 2707 | @($operatorAssociativity[$opCharacter] ? $operatorPrecedence[$opCharacter] < $operatorPrecedence[$o2['value']] : $operatorPrecedence[$opCharacter] <= $operatorPrecedence[$o2['value']])) { |
| 2708 | - $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
|
| 2708 | + $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
|
| 2709 | 2709 | } |
| 2710 | - $stack->push('Binary Operator',$opCharacter); // Finally put our current operator onto the stack |
|
| 2710 | + $stack->push('Binary Operator', $opCharacter); // Finally put our current operator onto the stack |
|
| 2711 | 2711 | ++$index; |
| 2712 | 2712 | $expectingOperator = false; |
| 2713 | 2713 | |
@@ -2720,10 +2720,10 @@ discard block |
||
| 2720 | 2720 | } |
| 2721 | 2721 | $d = $stack->last(2); |
| 2722 | 2722 | if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function? |
| 2723 | - $functionName = $matches[1]; // Get the function name |
|
| 2723 | + $functionName = $matches[1]; // Get the function name |
|
| 2724 | 2724 | // echo 'Closed Function is '.$functionName.'<br />'; |
| 2725 | 2725 | $d = $stack->pop(); |
| 2726 | - $argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack) |
|
| 2726 | + $argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack) |
|
| 2727 | 2727 | // if ($argumentCount == 0) { |
| 2728 | 2728 | // echo 'With no arguments<br />'; |
| 2729 | 2729 | // } elseif ($argumentCount == 1) { |
@@ -2731,8 +2731,8 @@ discard block |
||
| 2731 | 2731 | // } else { |
| 2732 | 2732 | // echo 'With '.$argumentCount.' arguments<br />'; |
| 2733 | 2733 | // } |
| 2734 | - $output[] = $d; // Dump the argument count on the output |
|
| 2735 | - $output[] = $stack->pop(); // Pop the function and push onto the output |
|
| 2734 | + $output[] = $d; // Dump the argument count on the output |
|
| 2735 | + $output[] = $stack->pop(); // Pop the function and push onto the output |
|
| 2736 | 2736 | if (isset(self::$_controlFunctions[$functionName])) { |
| 2737 | 2737 | // echo 'Built-in function '.$functionName.'<br />'; |
| 2738 | 2738 | $expectedArgumentCount = self::$_controlFunctions[$functionName]['argumentCount']; |
@@ -2761,7 +2761,7 @@ discard block |
||
| 2761 | 2761 | } |
| 2762 | 2762 | } |
| 2763 | 2763 | } elseif ($expectedArgumentCount != '*') { |
| 2764 | - $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/',$expectedArgumentCount,$argMatch); |
|
| 2764 | + $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/', $expectedArgumentCount, $argMatch); |
|
| 2765 | 2765 | // print_r($argMatch); |
| 2766 | 2766 | // echo '<br />'; |
| 2767 | 2767 | switch ($argMatch[2]) { |
@@ -2795,30 +2795,30 @@ discard block |
||
| 2795 | 2795 | // echo 'Element is a Function argument separator<br />'; |
| 2796 | 2796 | while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last ( |
| 2797 | 2797 | if ($o2 === NULL) return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
| 2798 | - else $output[] = $o2; // pop the argument expression stuff and push onto the output |
|
| 2798 | + else $output[] = $o2; // pop the argument expression stuff and push onto the output |
|
| 2799 | 2799 | } |
| 2800 | 2800 | // If we've a comma when we're expecting an operand, then what we actually have is a null operand; |
| 2801 | 2801 | // so push a null onto the stack |
| 2802 | - if (($expectingOperand) || (!$expectingOperator)) { |
|
| 2802 | + if (($expectingOperand) || ( ! $expectingOperator)) { |
|
| 2803 | 2803 | $output[] = array('type' => 'NULL Value', 'value' => self::$_ExcelConstants['NULL'], 'reference' => null); |
| 2804 | 2804 | } |
| 2805 | 2805 | // make sure there was a function |
| 2806 | 2806 | $d = $stack->last(2); |
| 2807 | - if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) |
|
| 2807 | + if ( ! preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) |
|
| 2808 | 2808 | return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
| 2809 | 2809 | $d = $stack->pop(); |
| 2810 | - $stack->push($d['type'],++$d['value'],$d['reference']); // increment the argument count |
|
| 2811 | - $stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again |
|
| 2810 | + $stack->push($d['type'], ++$d['value'], $d['reference']); // increment the argument count |
|
| 2811 | + $stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again |
|
| 2812 | 2812 | $expectingOperator = false; |
| 2813 | 2813 | $expectingOperand = true; |
| 2814 | 2814 | ++$index; |
| 2815 | 2815 | |
| 2816 | - } elseif ($opCharacter == '(' && !$expectingOperator) { |
|
| 2816 | + } elseif ($opCharacter == '(' && ! $expectingOperator) { |
|
| 2817 | 2817 | // echo 'Element is an Opening Bracket<br />'; |
| 2818 | 2818 | $stack->push('Brace', '('); |
| 2819 | 2819 | ++$index; |
| 2820 | 2820 | |
| 2821 | - } elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number? |
|
| 2821 | + } elseif ($isOperandOrFunction && ! $expectingOperator) { // do we now have a function/variable/number? |
|
| 2822 | 2822 | $expectingOperator = true; |
| 2823 | 2823 | $expectingOperand = false; |
| 2824 | 2824 | $val = $match[1]; |
@@ -2826,11 +2826,11 @@ discard block |
||
| 2826 | 2826 | // echo 'Element with value '.$val.' is an Operand, Variable, Constant, String, Number, Cell Reference or Function<br />'; |
| 2827 | 2827 | |
| 2828 | 2828 | if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $val, $matches)) { |
| 2829 | - $val = preg_replace('/\s/','',$val); |
|
| 2829 | + $val = preg_replace('/\s/', '', $val); |
|
| 2830 | 2830 | // echo 'Element '.$val.' is a Function<br />'; |
| 2831 | 2831 | if (isset(self::$_PHPExcelFunctions[strtoupper($matches[1])]) || isset(self::$_controlFunctions[strtoupper($matches[1])])) { // it's a function |
| 2832 | 2832 | $stack->push('Function', strtoupper($val)); |
| 2833 | - $ax = preg_match('/^\s*(\s*\))/i', substr($formula, $index+$length), $amatch); |
|
| 2833 | + $ax = preg_match('/^\s*(\s*\))/i', substr($formula, $index + $length), $amatch); |
|
| 2834 | 2834 | if ($ax) { |
| 2835 | 2835 | $stack->push('Operand Count for Function '.strtoupper($val).')', 0); |
| 2836 | 2836 | $expectingOperator = true; |
@@ -2854,7 +2854,7 @@ discard block |
||
| 2854 | 2854 | if ($matches[2] == '') { |
| 2855 | 2855 | // Otherwise, we 'inherit' the worksheet reference from the start cell reference |
| 2856 | 2856 | // The start of the cell range reference should be the last entry in $output |
| 2857 | - $startCellRef = $output[count($output)-1]['value']; |
|
| 2857 | + $startCellRef = $output[count($output) - 1]['value']; |
|
| 2858 | 2858 | preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $startCellRef, $startMatches); |
| 2859 | 2859 | if ($startMatches[2] > '') { |
| 2860 | 2860 | $val = $startMatches[2].'!'.$val; |
@@ -2871,28 +2871,28 @@ discard block |
||
| 2871 | 2871 | // If the last entry on the stack was a : operator, then we may have a row or column range reference |
| 2872 | 2872 | $testPrevOp = $stack->last(1); |
| 2873 | 2873 | if ($testPrevOp['value'] == ':') { |
| 2874 | - $startRowColRef = $output[count($output)-1]['value']; |
|
| 2874 | + $startRowColRef = $output[count($output) - 1]['value']; |
|
| 2875 | 2875 | $rangeWS1 = ''; |
| 2876 | - if (strpos('!',$startRowColRef) !== false) { |
|
| 2877 | - list($rangeWS1,$startRowColRef) = explode('!',$startRowColRef); |
|
| 2876 | + if (strpos('!', $startRowColRef) !== false) { |
|
| 2877 | + list($rangeWS1, $startRowColRef) = explode('!', $startRowColRef); |
|
| 2878 | 2878 | } |
| 2879 | 2879 | if ($rangeWS1 != '') $rangeWS1 .= '!'; |
| 2880 | 2880 | $rangeWS2 = $rangeWS1; |
| 2881 | - if (strpos('!',$val) !== false) { |
|
| 2882 | - list($rangeWS2,$val) = explode('!',$val); |
|
| 2881 | + if (strpos('!', $val) !== false) { |
|
| 2882 | + list($rangeWS2, $val) = explode('!', $val); |
|
| 2883 | 2883 | } |
| 2884 | 2884 | if ($rangeWS2 != '') $rangeWS2 .= '!'; |
| 2885 | 2885 | if ((is_integer($startRowColRef)) && (ctype_digit($val)) && |
| 2886 | 2886 | ($startRowColRef <= 1048576) && ($val <= 1048576)) { |
| 2887 | 2887 | // Row range |
| 2888 | - $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007 |
|
| 2889 | - $output[count($output)-1]['value'] = $rangeWS1.'A'.$startRowColRef; |
|
| 2888 | + $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007 |
|
| 2889 | + $output[count($output) - 1]['value'] = $rangeWS1.'A'.$startRowColRef; |
|
| 2890 | 2890 | $val = $rangeWS2.$endRowColRef.$val; |
| 2891 | 2891 | } elseif ((ctype_alpha($startRowColRef)) && (ctype_alpha($val)) && |
| 2892 | 2892 | (strlen($startRowColRef) <= 3) && (strlen($val) <= 3)) { |
| 2893 | 2893 | // Column range |
| 2894 | - $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007 |
|
| 2895 | - $output[count($output)-1]['value'] = $rangeWS1.strtoupper($startRowColRef).'1'; |
|
| 2894 | + $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007 |
|
| 2895 | + $output[count($output) - 1]['value'] = $rangeWS1.strtoupper($startRowColRef).'1'; |
|
| 2896 | 2896 | $val = $rangeWS2.$val.$endRowColRef; |
| 2897 | 2897 | } |
| 2898 | 2898 | } |
@@ -2901,10 +2901,10 @@ discard block |
||
| 2901 | 2901 | if ($opCharacter == '"') { |
| 2902 | 2902 | // echo 'Element is a String<br />'; |
| 2903 | 2903 | // UnEscape any quotes within the string |
| 2904 | - $val = self::_wrapResult(str_replace('""','"',self::_unwrapResult($val))); |
|
| 2904 | + $val = self::_wrapResult(str_replace('""', '"', self::_unwrapResult($val))); |
|
| 2905 | 2905 | } elseif (is_numeric($val)) { |
| 2906 | 2906 | // echo 'Element is a Number<br />'; |
| 2907 | - if ((strpos($val,'.') !== false) || (stripos($val,'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) { |
|
| 2907 | + if ((strpos($val, '.') !== false) || (stripos($val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) { |
|
| 2908 | 2908 | // echo 'Casting '.$val.' to float<br />'; |
| 2909 | 2909 | $val = (float) $val; |
| 2910 | 2910 | } else { |
@@ -2935,7 +2935,7 @@ discard block |
||
| 2935 | 2935 | } else { |
| 2936 | 2936 | return $this->_raiseFormulaError("Formula Error: Unexpected ')'"); |
| 2937 | 2937 | } |
| 2938 | - } elseif (isset(self::$_operators[$opCharacter]) && !$expectingOperator) { |
|
| 2938 | + } elseif (isset(self::$_operators[$opCharacter]) && ! $expectingOperator) { |
|
| 2939 | 2939 | return $this->_raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'"); |
| 2940 | 2940 | } else { // I don't even want to know what you did to get here |
| 2941 | 2941 | return $this->_raiseFormulaError("Formula Error: An unexpected error occured"); |
@@ -2962,15 +2962,15 @@ discard block |
||
| 2962 | 2962 | // Cell References) then we have an INTERSECTION operator |
| 2963 | 2963 | // echo 'Possible Intersect Operator<br />'; |
| 2964 | 2964 | if (($expectingOperator) && (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'.*/Ui', substr($formula, $index), $match)) && |
| 2965 | - ($output[count($output)-1]['type'] == 'Cell Reference')) { |
|
| 2965 | + ($output[count($output) - 1]['type'] == 'Cell Reference')) { |
|
| 2966 | 2966 | // echo 'Element is an Intersect Operator<br />'; |
| 2967 | - while($stack->count() > 0 && |
|
| 2967 | + while ($stack->count() > 0 && |
|
| 2968 | 2968 | ($o2 = $stack->last()) && |
| 2969 | 2969 | isset(self::$_operators[$o2['value']]) && |
| 2970 | 2970 | @($operatorAssociativity[$opCharacter] ? $operatorPrecedence[$opCharacter] < $operatorPrecedence[$o2['value']] : $operatorPrecedence[$opCharacter] <= $operatorPrecedence[$o2['value']])) { |
| 2971 | - $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
|
| 2971 | + $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
|
| 2972 | 2972 | } |
| 2973 | - $stack->push('Binary Operator','|'); // Put an Intersect Operator on the stack |
|
| 2973 | + $stack->push('Binary Operator', '|'); // Put an Intersect Operator on the stack |
|
| 2974 | 2974 | $expectingOperator = false; |
| 2975 | 2975 | } |
| 2976 | 2976 | } |
@@ -2978,7 +2978,7 @@ discard block |
||
| 2978 | 2978 | |
| 2979 | 2979 | while (($op = $stack->pop()) !== NULL) { // pop everything off the stack and push onto output |
| 2980 | 2980 | if ((is_array($opCharacter) && $opCharacter['value'] == '(') || ($opCharacter === '(')) |
| 2981 | - return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced |
|
| 2981 | + return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced |
|
| 2982 | 2982 | $output[] = $op; |
| 2983 | 2983 | } |
| 2984 | 2984 | return $output; |
@@ -3041,18 +3041,18 @@ discard block |
||
| 3041 | 3041 | case '<=' : // Less than or Equal to |
| 3042 | 3042 | case '=' : // Equality |
| 3043 | 3043 | case '<>' : // Inequality |
| 3044 | - $this->_executeBinaryComparisonOperation($cellID,$operand1,$operand2,$token,$stack); |
|
| 3044 | + $this->_executeBinaryComparisonOperation($cellID, $operand1, $operand2, $token, $stack); |
|
| 3045 | 3045 | break; |
| 3046 | 3046 | // Binary Operators |
| 3047 | 3047 | case ':' : // Range |
| 3048 | 3048 | $sheet1 = $sheet2 = ''; |
| 3049 | - if (strpos($operand1Data['reference'],'!') !== false) { |
|
| 3050 | - list($sheet1,$operand1Data['reference']) = explode('!',$operand1Data['reference']); |
|
| 3049 | + if (strpos($operand1Data['reference'], '!') !== false) { |
|
| 3050 | + list($sheet1, $operand1Data['reference']) = explode('!', $operand1Data['reference']); |
|
| 3051 | 3051 | } else { |
| 3052 | 3052 | $sheet1 = ($pCellParent !== NULL) ? $pCellParent->getTitle() : ''; |
| 3053 | 3053 | } |
| 3054 | - if (strpos($operand2Data['reference'],'!') !== false) { |
|
| 3055 | - list($sheet2,$operand2Data['reference']) = explode('!',$operand2Data['reference']); |
|
| 3054 | + if (strpos($operand2Data['reference'], '!') !== false) { |
|
| 3055 | + list($sheet2, $operand2Data['reference']) = explode('!', $operand2Data['reference']); |
|
| 3056 | 3056 | } else { |
| 3057 | 3057 | $sheet2 = $sheet1; |
| 3058 | 3058 | } |
@@ -3076,9 +3076,9 @@ discard block |
||
| 3076 | 3076 | } |
| 3077 | 3077 | } |
| 3078 | 3078 | |
| 3079 | - $oData = array_merge(explode(':',$operand1Data['reference']),explode(':',$operand2Data['reference'])); |
|
| 3079 | + $oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference'])); |
|
| 3080 | 3080 | $oCol = $oRow = array(); |
| 3081 | - foreach($oData as $oDatum) { |
|
| 3081 | + foreach ($oData as $oDatum) { |
|
| 3082 | 3082 | $oCR = PHPExcel_Cell::coordinateFromString($oDatum); |
| 3083 | 3083 | $oCol[] = PHPExcel_Cell::columnIndexFromString($oCR[0]) - 1; |
| 3084 | 3084 | $oRow[] = $oCR[1]; |
@@ -3089,26 +3089,26 @@ discard block |
||
| 3089 | 3089 | } else { |
| 3090 | 3090 | return $this->_raiseFormulaError('Unable to access Cell Reference'); |
| 3091 | 3091 | } |
| 3092 | - $stack->push('Cell Reference',$cellValue,$cellRef); |
|
| 3092 | + $stack->push('Cell Reference', $cellValue, $cellRef); |
|
| 3093 | 3093 | } else { |
| 3094 | - $stack->push('Error',PHPExcel_Calculation_Functions::REF(),null); |
|
| 3094 | + $stack->push('Error', PHPExcel_Calculation_Functions::REF(), null); |
|
| 3095 | 3095 | } |
| 3096 | 3096 | |
| 3097 | 3097 | break; |
| 3098 | 3098 | case '+' : // Addition |
| 3099 | - $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'plusEquals',$stack); |
|
| 3099 | + $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'plusEquals', $stack); |
|
| 3100 | 3100 | break; |
| 3101 | 3101 | case '-' : // Subtraction |
| 3102 | - $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'minusEquals',$stack); |
|
| 3102 | + $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'minusEquals', $stack); |
|
| 3103 | 3103 | break; |
| 3104 | 3104 | case '*' : // Multiplication |
| 3105 | - $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayTimesEquals',$stack); |
|
| 3105 | + $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayTimesEquals', $stack); |
|
| 3106 | 3106 | break; |
| 3107 | 3107 | case '/' : // Division |
| 3108 | - $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayRightDivide',$stack); |
|
| 3108 | + $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayRightDivide', $stack); |
|
| 3109 | 3109 | break; |
| 3110 | 3110 | case '^' : // Exponential |
| 3111 | - $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'power',$stack); |
|
| 3111 | + $this->_executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'power', $stack); |
|
| 3112 | 3112 | break; |
| 3113 | 3113 | case '&' : // Concatenation |
| 3114 | 3114 | // If either of the operands is a matrix, we need to treat them both as matrices |
@@ -3122,7 +3122,7 @@ discard block |
||
| 3122 | 3122 | } |
| 3123 | 3123 | if ((is_array($operand1)) || (is_array($operand2))) { |
| 3124 | 3124 | // Ensure that both operands are arrays/matrices |
| 3125 | - self::_checkMatrixOperands($operand1,$operand2,2); |
|
| 3125 | + self::_checkMatrixOperands($operand1, $operand2, 2); |
|
| 3126 | 3126 | try { |
| 3127 | 3127 | // Convert operand 1 from a PHP array to a matrix |
| 3128 | 3128 | $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1); |
@@ -3134,24 +3134,24 @@ discard block |
||
| 3134 | 3134 | $result = '#VALUE!'; |
| 3135 | 3135 | } |
| 3136 | 3136 | } else { |
| 3137 | - $result = '"'.str_replace('""','"',self::_unwrapResult($operand1,'"').self::_unwrapResult($operand2,'"')).'"'; |
|
| 3137 | + $result = '"'.str_replace('""', '"', self::_unwrapResult($operand1, '"').self::_unwrapResult($operand2, '"')).'"'; |
|
| 3138 | 3138 | } |
| 3139 | 3139 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); |
| 3140 | - $stack->push('Value',$result); |
|
| 3140 | + $stack->push('Value', $result); |
|
| 3141 | 3141 | break; |
| 3142 | 3142 | case '|' : // Intersect |
| 3143 | - $rowIntersect = array_intersect_key($operand1,$operand2); |
|
| 3143 | + $rowIntersect = array_intersect_key($operand1, $operand2); |
|
| 3144 | 3144 | $cellIntersect = $oCol = $oRow = array(); |
| 3145 | - foreach(array_keys($rowIntersect) as $row) { |
|
| 3145 | + foreach (array_keys($rowIntersect) as $row) { |
|
| 3146 | 3146 | $oRow[] = $row; |
| 3147 | - foreach($rowIntersect[$row] as $col => $data) { |
|
| 3147 | + foreach ($rowIntersect[$row] as $col => $data) { |
|
| 3148 | 3148 | $oCol[] = PHPExcel_Cell::columnIndexFromString($col) - 1; |
| 3149 | - $cellIntersect[$row] = array_intersect_key($operand1[$row],$operand2[$row]); |
|
| 3149 | + $cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]); |
|
| 3150 | 3150 | } |
| 3151 | 3151 | } |
| 3152 | 3152 | $cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow); |
| 3153 | 3153 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($cellIntersect)); |
| 3154 | - $stack->push('Value',$cellIntersect,$cellRef); |
|
| 3154 | + $stack->push('Value', $cellIntersect, $cellRef); |
|
| 3155 | 3155 | break; |
| 3156 | 3156 | } |
| 3157 | 3157 | |
@@ -3170,7 +3170,7 @@ discard block |
||
| 3170 | 3170 | $multiplier = 0.01; |
| 3171 | 3171 | } |
| 3172 | 3172 | if (is_array($arg)) { |
| 3173 | - self::_checkMatrixOperands($arg,$multiplier,2); |
|
| 3173 | + self::_checkMatrixOperands($arg, $multiplier, 2); |
|
| 3174 | 3174 | try { |
| 3175 | 3175 | $matrix1 = new PHPExcel_Shared_JAMA_Matrix($arg); |
| 3176 | 3176 | $matrixResult = $matrix1->arrayTimesEquals($multiplier); |
@@ -3180,9 +3180,9 @@ discard block |
||
| 3180 | 3180 | $result = '#VALUE!'; |
| 3181 | 3181 | } |
| 3182 | 3182 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); |
| 3183 | - $stack->push('Value',$result); |
|
| 3183 | + $stack->push('Value', $result); |
|
| 3184 | 3184 | } else { |
| 3185 | - $this->_executeNumericBinaryOperation($cellID,$multiplier,$arg,'*','arrayTimesEquals',$stack); |
|
| 3185 | + $this->_executeNumericBinaryOperation($cellID, $multiplier, $arg, '*', 'arrayTimesEquals', $stack); |
|
| 3186 | 3186 | } |
| 3187 | 3187 | |
| 3188 | 3188 | } elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) { |
@@ -3196,12 +3196,12 @@ discard block |
||
| 3196 | 3196 | } else { |
| 3197 | 3197 | $cellRef = $matches[6].$matches[7].':'.$matches[9].$matches[10]; |
| 3198 | 3198 | if ($matches[2] > '') { |
| 3199 | - $matches[2] = trim($matches[2],"\"'"); |
|
| 3200 | - if ((strpos($matches[2],'[') !== false) || (strpos($matches[2],']') !== false)) { |
|
| 3199 | + $matches[2] = trim($matches[2], "\"'"); |
|
| 3200 | + if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) { |
|
| 3201 | 3201 | // It's a Reference to an external workbook (not currently supported) |
| 3202 | 3202 | return $this->_raiseFormulaError('Unable to access External Workbook'); |
| 3203 | 3203 | } |
| 3204 | - $matches[2] = trim($matches[2],"\"'"); |
|
| 3204 | + $matches[2] = trim($matches[2], "\"'"); |
|
| 3205 | 3205 | // echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />'; |
| 3206 | 3206 | $this->_writeDebug('Evaluating Cell Range '.$cellRef.' in worksheet '.$matches[2]); |
| 3207 | 3207 | if ($pCellParent !== NULL) { |
@@ -3230,8 +3230,8 @@ discard block |
||
| 3230 | 3230 | } else { |
| 3231 | 3231 | $cellRef = $matches[6].$matches[7]; |
| 3232 | 3232 | if ($matches[2] > '') { |
| 3233 | - $matches[2] = trim($matches[2],"\"'"); |
|
| 3234 | - if ((strpos($matches[2],'[') !== false) || (strpos($matches[2],']') !== false)) { |
|
| 3233 | + $matches[2] = trim($matches[2], "\"'"); |
|
| 3234 | + if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) { |
|
| 3235 | 3235 | // It's a Reference to an external workbook (not currently supported) |
| 3236 | 3236 | return $this->_raiseFormulaError('Unable to access External Workbook'); |
| 3237 | 3237 | } |
@@ -3262,7 +3262,7 @@ discard block |
||
| 3262 | 3262 | } |
| 3263 | 3263 | } |
| 3264 | 3264 | } |
| 3265 | - $stack->push('Value',$cellValue,$cellRef); |
|
| 3265 | + $stack->push('Value', $cellValue, $cellRef); |
|
| 3266 | 3266 | |
| 3267 | 3267 | // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on |
| 3268 | 3268 | } elseif (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $token, $matches)) { |
@@ -3316,7 +3316,7 @@ discard block |
||
| 3316 | 3316 | if ($functionName != 'MKMATRIX') { |
| 3317 | 3317 | if ($this->writeDebugLog) { |
| 3318 | 3318 | krsort($argArrayVals); |
| 3319 | - $this->_writeDebug('Evaluating '. self::_localeFunc($functionName).'( '.implode(self::$_localeArgumentSeparator.' ',PHPExcel_Calculation_Functions::flattenArray($argArrayVals)).' )'); |
|
| 3319 | + $this->_writeDebug('Evaluating '.self::_localeFunc($functionName).'( '.implode(self::$_localeArgumentSeparator.' ', PHPExcel_Calculation_Functions::flattenArray($argArrayVals)).' )'); |
|
| 3320 | 3320 | } |
| 3321 | 3321 | } |
| 3322 | 3322 | // Process each argument in turn, building the return value as an array |
@@ -3346,20 +3346,20 @@ discard block |
||
| 3346 | 3346 | if ($passCellReference) { |
| 3347 | 3347 | $args[] = $pCell; |
| 3348 | 3348 | } |
| 3349 | - if (strpos($functionCall,'::') !== false) { |
|
| 3350 | - $result = call_user_func_array(explode('::',$functionCall),$args); |
|
| 3349 | + if (strpos($functionCall, '::') !== false) { |
|
| 3350 | + $result = call_user_func_array(explode('::', $functionCall), $args); |
|
| 3351 | 3351 | } else { |
| 3352 | - foreach($args as &$arg) { |
|
| 3352 | + foreach ($args as &$arg) { |
|
| 3353 | 3353 | $arg = PHPExcel_Calculation_Functions::flattenSingleValue($arg); |
| 3354 | 3354 | } |
| 3355 | 3355 | unset($arg); |
| 3356 | - $result = call_user_func_array($functionCall,$args); |
|
| 3356 | + $result = call_user_func_array($functionCall, $args); |
|
| 3357 | 3357 | } |
| 3358 | 3358 | // } |
| 3359 | 3359 | if ($functionName != 'MKMATRIX') { |
| 3360 | 3360 | $this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($result)); |
| 3361 | 3361 | } |
| 3362 | - $stack->push('Value',self::_wrapResult($result)); |
|
| 3362 | + $stack->push('Value', self::_wrapResult($result)); |
|
| 3363 | 3363 | } |
| 3364 | 3364 | |
| 3365 | 3365 | } else { |
@@ -3367,11 +3367,11 @@ discard block |
||
| 3367 | 3367 | if (isset(self::$_ExcelConstants[strtoupper($token)])) { |
| 3368 | 3368 | $excelConstant = strtoupper($token); |
| 3369 | 3369 | // echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />'; |
| 3370 | - $stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]); |
|
| 3370 | + $stack->push('Constant Value', self::$_ExcelConstants[$excelConstant]); |
|
| 3371 | 3371 | $this->_writeDebug('Evaluating Constant '.$excelConstant.' as '.$this->_showTypeDetails(self::$_ExcelConstants[$excelConstant])); |
| 3372 | 3372 | } elseif ((is_numeric($token)) || ($token === NULL) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) { |
| 3373 | 3373 | // echo 'Token is a number, boolean, string, null or an Excel error<br />'; |
| 3374 | - $stack->push('Value',$token); |
|
| 3374 | + $stack->push('Value', $token); |
|
| 3375 | 3375 | // if the token is a named range, push the named range name onto the stack |
| 3376 | 3376 | } elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $token, $matches)) { |
| 3377 | 3377 | // echo 'Token is a named range<br />'; |
@@ -3381,7 +3381,7 @@ discard block |
||
| 3381 | 3381 | $cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false); |
| 3382 | 3382 | $pCell->attach($pCellParent); |
| 3383 | 3383 | $this->_writeDebug('Evaluation Result for named range '.$namedRange.' is '.$this->_showTypeDetails($cellValue)); |
| 3384 | - $stack->push('Named Range',$cellValue,$namedRange); |
|
| 3384 | + $stack->push('Named Range', $cellValue, $namedRange); |
|
| 3385 | 3385 | } else { |
| 3386 | 3386 | return $this->_raiseFormulaError("undefined variable '$token'"); |
| 3387 | 3387 | } |
@@ -3399,20 +3399,20 @@ discard block |
||
| 3399 | 3399 | } // function _processTokenStack() |
| 3400 | 3400 | |
| 3401 | 3401 | |
| 3402 | - private function _validateBinaryOperand($cellID,&$operand,&$stack) { |
|
| 3402 | + private function _validateBinaryOperand($cellID, &$operand, &$stack) { |
|
| 3403 | 3403 | // Numbers, matrices and booleans can pass straight through, as they're already valid |
| 3404 | 3404 | if (is_string($operand)) { |
| 3405 | 3405 | // We only need special validations for the operand if it is a string |
| 3406 | 3406 | // Start by stripping off the quotation marks we use to identify true excel string values internally |
| 3407 | 3407 | if ($operand > '' && $operand{0} == '"') { $operand = self::_unwrapResult($operand); } |
| 3408 | 3408 | // If the string is a numeric value, we treat it as a numeric, so no further testing |
| 3409 | - if (!is_numeric($operand)) { |
|
| 3409 | + if ( ! is_numeric($operand)) { |
|
| 3410 | 3410 | // If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations |
| 3411 | 3411 | if ($operand > '' && $operand{0} == '#') { |
| 3412 | 3412 | $stack->push('Value', $operand); |
| 3413 | 3413 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($operand)); |
| 3414 | 3414 | return false; |
| 3415 | - } elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) { |
|
| 3415 | + } elseif ( ! PHPExcel_Shared_String::convertToNumberIfFraction($operand)) { |
|
| 3416 | 3416 | // If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations |
| 3417 | 3417 | $stack->push('Value', '#VALUE!'); |
| 3418 | 3418 | $this->_writeDebug('Evaluation Result is a '.$this->_showTypeDetails('#VALUE!')); |
@@ -3426,29 +3426,29 @@ discard block |
||
| 3426 | 3426 | } // function _validateBinaryOperand() |
| 3427 | 3427 | |
| 3428 | 3428 | |
| 3429 | - private function _executeBinaryComparisonOperation($cellID,$operand1,$operand2,$operation,&$stack,$recursingArrays=false) { |
|
| 3429 | + private function _executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = false) { |
|
| 3430 | 3430 | // If we're dealing with matrix operations, we want a matrix result |
| 3431 | 3431 | if ((is_array($operand1)) || (is_array($operand2))) { |
| 3432 | 3432 | $result = array(); |
| 3433 | - if ((is_array($operand1)) && (!is_array($operand2))) { |
|
| 3434 | - foreach($operand1 as $x => $operandData) { |
|
| 3433 | + if ((is_array($operand1)) && ( ! is_array($operand2))) { |
|
| 3434 | + foreach ($operand1 as $x => $operandData) { |
|
| 3435 | 3435 | $this->_writeDebug('Evaluating Comparison '.$this->_showValue($operandData).' '.$operation.' '.$this->_showValue($operand2)); |
| 3436 | - $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2,$operation,$stack); |
|
| 3436 | + $this->_executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack); |
|
| 3437 | 3437 | $r = $stack->pop(); |
| 3438 | 3438 | $result[$x] = $r['value']; |
| 3439 | 3439 | } |
| 3440 | - } elseif ((!is_array($operand1)) && (is_array($operand2))) { |
|
| 3441 | - foreach($operand2 as $x => $operandData) { |
|
| 3440 | + } elseif (( ! is_array($operand1)) && (is_array($operand2))) { |
|
| 3441 | + foreach ($operand2 as $x => $operandData) { |
|
| 3442 | 3442 | $this->_writeDebug('Evaluating Comparison '.$this->_showValue($operand1).' '.$operation.' '.$this->_showValue($operandData)); |
| 3443 | - $this->_executeBinaryComparisonOperation($cellID,$operand1,$operandData,$operation,$stack); |
|
| 3443 | + $this->_executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack); |
|
| 3444 | 3444 | $r = $stack->pop(); |
| 3445 | 3445 | $result[$x] = $r['value']; |
| 3446 | 3446 | } |
| 3447 | 3447 | } else { |
| 3448 | - if (!$recursingArrays) { self::_checkMatrixOperands($operand1,$operand2,2); } |
|
| 3449 | - foreach($operand1 as $x => $operandData) { |
|
| 3448 | + if ( ! $recursingArrays) { self::_checkMatrixOperands($operand1, $operand2, 2); } |
|
| 3449 | + foreach ($operand1 as $x => $operandData) { |
|
| 3450 | 3450 | $this->_writeDebug('Evaluating Comparison '.$this->_showValue($operandData).' '.$operation.' '.$this->_showValue($operand2[$x])); |
| 3451 | - $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2[$x],$operation,$stack,true); |
|
| 3451 | + $this->_executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, true); |
|
| 3452 | 3452 | $r = $stack->pop(); |
| 3453 | 3453 | $result[$x] = $r['value']; |
| 3454 | 3454 | } |
@@ -3456,7 +3456,7 @@ discard block |
||
| 3456 | 3456 | // Log the result details |
| 3457 | 3457 | $this->_writeDebug('Comparison Evaluation Result is '.$this->_showTypeDetails($result)); |
| 3458 | 3458 | // And push the result onto the stack |
| 3459 | - $stack->push('Array',$result); |
|
| 3459 | + $stack->push('Array', $result); |
|
| 3460 | 3460 | return true; |
| 3461 | 3461 | } |
| 3462 | 3462 | |
@@ -3495,15 +3495,15 @@ discard block |
||
| 3495 | 3495 | // Log the result details |
| 3496 | 3496 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); |
| 3497 | 3497 | // And push the result onto the stack |
| 3498 | - $stack->push('Value',$result); |
|
| 3498 | + $stack->push('Value', $result); |
|
| 3499 | 3499 | return true; |
| 3500 | 3500 | } // function _executeBinaryComparisonOperation() |
| 3501 | 3501 | |
| 3502 | 3502 | |
| 3503 | - private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) { |
|
| 3503 | + private function _executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack) { |
|
| 3504 | 3504 | // Validate the two operands |
| 3505 | - if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false; |
|
| 3506 | - if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return false; |
|
| 3505 | + if ( ! $this->_validateBinaryOperand($cellID, $operand1, $stack)) return false; |
|
| 3506 | + if ( ! $this->_validateBinaryOperand($cellID, $operand2, $stack)) return false; |
|
| 3507 | 3507 | |
| 3508 | 3508 | $executeMatrixOperation = false; |
| 3509 | 3509 | // If either of the operands is a matrix, we need to treat them both as matrices |
@@ -3513,7 +3513,7 @@ discard block |
||
| 3513 | 3513 | // Ensure that both operands are arrays/matrices |
| 3514 | 3514 | $executeMatrixOperation = true; |
| 3515 | 3515 | $mSize = array(); |
| 3516 | - list($mSize[],$mSize[],$mSize[],$mSize[]) = self::_checkMatrixOperands($operand1,$operand2,2); |
|
| 3516 | + list($mSize[], $mSize[], $mSize[], $mSize[]) = self::_checkMatrixOperands($operand1, $operand2, 2); |
|
| 3517 | 3517 | |
| 3518 | 3518 | // But if they're both single cell matrices, then we can treat them as simple values |
| 3519 | 3519 | if (array_sum($mSize) == 4) { |
@@ -3536,37 +3536,37 @@ discard block |
||
| 3536 | 3536 | } |
| 3537 | 3537 | } else { |
| 3538 | 3538 | if ((PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) && |
| 3539 | - ((is_string($operand1) && !is_numeric($operand1)) || (is_string($operand2) && !is_numeric($operand2)))) { |
|
| 3539 | + ((is_string($operand1) && ! is_numeric($operand1)) || (is_string($operand2) && ! is_numeric($operand2)))) { |
|
| 3540 | 3540 | $result = PHPExcel_Calculation_Functions::VALUE(); |
| 3541 | 3541 | } else { |
| 3542 | 3542 | // If we're dealing with non-matrix operations, execute the necessary operation |
| 3543 | 3543 | switch ($operation) { |
| 3544 | 3544 | // Addition |
| 3545 | 3545 | case '+': |
| 3546 | - $result = $operand1+$operand2; |
|
| 3546 | + $result = $operand1 + $operand2; |
|
| 3547 | 3547 | break; |
| 3548 | 3548 | // Subtraction |
| 3549 | 3549 | case '-': |
| 3550 | - $result = $operand1-$operand2; |
|
| 3550 | + $result = $operand1 - $operand2; |
|
| 3551 | 3551 | break; |
| 3552 | 3552 | // Multiplication |
| 3553 | 3553 | case '*': |
| 3554 | - $result = $operand1*$operand2; |
|
| 3554 | + $result = $operand1 * $operand2; |
|
| 3555 | 3555 | break; |
| 3556 | 3556 | // Division |
| 3557 | 3557 | case '/': |
| 3558 | 3558 | if ($operand2 == 0) { |
| 3559 | 3559 | // Trap for Divide by Zero error |
| 3560 | - $stack->push('Value','#DIV/0!'); |
|
| 3560 | + $stack->push('Value', '#DIV/0!'); |
|
| 3561 | 3561 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails('#DIV/0!')); |
| 3562 | 3562 | return false; |
| 3563 | 3563 | } else { |
| 3564 | - $result = $operand1/$operand2; |
|
| 3564 | + $result = $operand1 / $operand2; |
|
| 3565 | 3565 | } |
| 3566 | 3566 | break; |
| 3567 | 3567 | // Power |
| 3568 | 3568 | case '^': |
| 3569 | - $result = pow($operand1,$operand2); |
|
| 3569 | + $result = pow($operand1, $operand2); |
|
| 3570 | 3570 | break; |
| 3571 | 3571 | } |
| 3572 | 3572 | } |
@@ -3575,7 +3575,7 @@ discard block |
||
| 3575 | 3575 | // Log the result details |
| 3576 | 3576 | $this->_writeDebug('Evaluation Result is '.$this->_showTypeDetails($result)); |
| 3577 | 3577 | // And push the result onto the stack |
| 3578 | - $stack->push('Value',$result); |
|
| 3578 | + $stack->push('Value', $result); |
|
| 3579 | 3579 | return true; |
| 3580 | 3580 | } // function _executeNumericBinaryOperation() |
| 3581 | 3581 | |
@@ -3584,9 +3584,9 @@ discard block |
||
| 3584 | 3584 | // Only write the debug log if logging is enabled |
| 3585 | 3585 | if ($this->writeDebugLog) { |
| 3586 | 3586 | if ($this->echoDebugLog) { |
| 3587 | - echo implode(' -> ',$this->debugLogStack).' -> '.$message,'<br />'; |
|
| 3587 | + echo implode(' -> ', $this->debugLogStack).' -> '.$message, '<br />'; |
|
| 3588 | 3588 | } |
| 3589 | - $this->debugLog[] = implode(' -> ',$this->debugLogStack).' -> '.$message; |
|
| 3589 | + $this->debugLog[] = implode(' -> ', $this->debugLogStack).' -> '.$message; |
|
| 3590 | 3590 | } |
| 3591 | 3591 | } // function _writeDebug() |
| 3592 | 3592 | |
@@ -3595,7 +3595,7 @@ discard block |
||
| 3595 | 3595 | protected function _raiseFormulaError($errorMessage) { |
| 3596 | 3596 | $this->formulaError = $errorMessage; |
| 3597 | 3597 | $this->debugLogStack = array(); |
| 3598 | - if (!$this->suppressFormulaErrors) throw new Exception($errorMessage); |
|
| 3598 | + if ( ! $this->suppressFormulaErrors) throw new Exception($errorMessage); |
|
| 3599 | 3599 | trigger_error($errorMessage, E_USER_ERROR); |
| 3600 | 3600 | } // function _raiseFormulaError() |
| 3601 | 3601 | |
@@ -3608,15 +3608,15 @@ discard block |
||
| 3608 | 3608 | * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned. |
| 3609 | 3609 | * @throws Exception |
| 3610 | 3610 | */ |
| 3611 | - public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog=true) { |
|
| 3611 | + public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true) { |
|
| 3612 | 3612 | // Return value |
| 3613 | - $returnValue = array (); |
|
| 3613 | + $returnValue = array(); |
|
| 3614 | 3614 | |
| 3615 | 3615 | // echo 'extractCellRange('.$pRange.')<br />'; |
| 3616 | 3616 | if ($pSheet !== NULL) { |
| 3617 | 3617 | // echo 'Passed sheet name is '.$pSheet->getTitle().'<br />'; |
| 3618 | 3618 | // echo 'Range reference is '.$pRange.'<br />'; |
| 3619 | - if (strpos ($pRange, '!') !== false) { |
|
| 3619 | + if (strpos($pRange, '!') !== false) { |
|
| 3620 | 3620 | // echo '$pRange reference includes sheet reference<br />'; |
| 3621 | 3621 | $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pRange, true); |
| 3622 | 3622 | $pSheet = $pSheet->getParent()->getSheetByName($worksheetReference[0]); |
@@ -3628,9 +3628,9 @@ discard block |
||
| 3628 | 3628 | // Extract range |
| 3629 | 3629 | $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange); |
| 3630 | 3630 | $pRange = $pSheet->getTitle().'!'.$pRange; |
| 3631 | - if (!isset($aReferences[1])) { |
|
| 3631 | + if ( ! isset($aReferences[1])) { |
|
| 3632 | 3632 | // Single cell in range |
| 3633 | - list($currentCol,$currentRow) = sscanf($aReferences[0],'%[A-Z]%d'); |
|
| 3633 | + list($currentCol, $currentRow) = sscanf($aReferences[0], '%[A-Z]%d'); |
|
| 3634 | 3634 | if ($pSheet->cellExists($aReferences[0])) { |
| 3635 | 3635 | $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog); |
| 3636 | 3636 | } else { |
@@ -3640,7 +3640,7 @@ discard block |
||
| 3640 | 3640 | // Extract cell data for all cells in the range |
| 3641 | 3641 | foreach ($aReferences as $reference) { |
| 3642 | 3642 | // Extract range |
| 3643 | - list($currentCol,$currentRow) = sscanf($reference,'%[A-Z]%d'); |
|
| 3643 | + list($currentCol, $currentRow) = sscanf($reference, '%[A-Z]%d'); |
|
| 3644 | 3644 | |
| 3645 | 3645 | if ($pSheet->cellExists($reference)) { |
| 3646 | 3646 | $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog); |
@@ -3664,15 +3664,15 @@ discard block |
||
| 3664 | 3664 | * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned. |
| 3665 | 3665 | * @throws Exception |
| 3666 | 3666 | */ |
| 3667 | - public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog=true) { |
|
| 3667 | + public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true) { |
|
| 3668 | 3668 | // Return value |
| 3669 | - $returnValue = array (); |
|
| 3669 | + $returnValue = array(); |
|
| 3670 | 3670 | |
| 3671 | 3671 | // echo 'extractNamedRange('.$pRange.')<br />'; |
| 3672 | 3672 | if ($pSheet !== NULL) { |
| 3673 | 3673 | // echo 'Current sheet name is '.$pSheet->getTitle().'<br />'; |
| 3674 | 3674 | // echo 'Range reference is '.$pRange.'<br />'; |
| 3675 | - if (strpos ($pRange, '!') !== false) { |
|
| 3675 | + if (strpos($pRange, '!') !== false) { |
|
| 3676 | 3676 | // echo '$pRange reference includes sheet reference<br />'; |
| 3677 | 3677 | $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pRange, true); |
| 3678 | 3678 | $pSheet = $pSheet->getParent()->getSheetByName($worksheetReference[0]); |
@@ -3690,9 +3690,9 @@ discard block |
||
| 3690 | 3690 | $splitRange = PHPExcel_Cell::splitRange($pRange); |
| 3691 | 3691 | // Convert row and column references |
| 3692 | 3692 | if (ctype_alpha($splitRange[0][0])) { |
| 3693 | - $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow(); |
|
| 3694 | - } elseif(ctype_digit($splitRange[0][0])) { |
|
| 3695 | - $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1]; |
|
| 3693 | + $pRange = $splitRange[0][0].'1:'.$splitRange[0][1].$namedRange->getWorksheet()->getHighestRow(); |
|
| 3694 | + } elseif (ctype_digit($splitRange[0][0])) { |
|
| 3695 | + $pRange = 'A'.$splitRange[0][0].':'.$namedRange->getWorksheet()->getHighestColumn().$splitRange[0][1]; |
|
| 3696 | 3696 | } |
| 3697 | 3697 | // echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />'; |
| 3698 | 3698 | |
@@ -3710,9 +3710,9 @@ discard block |
||
| 3710 | 3710 | // Extract range |
| 3711 | 3711 | $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange); |
| 3712 | 3712 | // var_dump($aReferences); |
| 3713 | - if (!isset($aReferences[1])) { |
|
| 3713 | + if ( ! isset($aReferences[1])) { |
|
| 3714 | 3714 | // Single cell (or single column or row) in range |
| 3715 | - list($currentCol,$currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]); |
|
| 3715 | + list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]); |
|
| 3716 | 3716 | if ($pSheet->cellExists($aReferences[0])) { |
| 3717 | 3717 | $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog); |
| 3718 | 3718 | } else { |
@@ -3722,7 +3722,7 @@ discard block |
||
| 3722 | 3722 | // Extract cell data for all cells in the range |
| 3723 | 3723 | foreach ($aReferences as $reference) { |
| 3724 | 3724 | // Extract range |
| 3725 | - list($currentCol,$currentRow) = PHPExcel_Cell::coordinateFromString($reference); |
|
| 3725 | + list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference); |
|
| 3726 | 3726 | // echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />'; |
| 3727 | 3727 | if ($pSheet->cellExists($reference)) { |
| 3728 | 3728 | $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog); |
@@ -3747,7 +3747,7 @@ discard block |
||
| 3747 | 3747 | * @return boolean |
| 3748 | 3748 | */ |
| 3749 | 3749 | public function isImplemented($pFunction = '') { |
| 3750 | - $pFunction = strtoupper ($pFunction); |
|
| 3750 | + $pFunction = strtoupper($pFunction); |
|
| 3751 | 3751 | if (isset(self::$_PHPExcelFunctions[$pFunction])) { |
| 3752 | 3752 | return (self::$_PHPExcelFunctions[$pFunction]['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY'); |
| 3753 | 3753 | } else { |
@@ -3765,7 +3765,7 @@ discard block |
||
| 3765 | 3765 | // Return value |
| 3766 | 3766 | $returnValue = array(); |
| 3767 | 3767 | // Loop functions |
| 3768 | - foreach(self::$_PHPExcelFunctions as $functionName => $function) { |
|
| 3768 | + foreach (self::$_PHPExcelFunctions as $functionName => $function) { |
|
| 3769 | 3769 | if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') { |
| 3770 | 3770 | $returnValue[$functionName] = new PHPExcel_Calculation_Function($function['category'], |
| 3771 | 3771 | $functionName, |
@@ -3797,7 +3797,7 @@ discard block |
||
| 3797 | 3797 | // Return value |
| 3798 | 3798 | $returnValue = array(); |
| 3799 | 3799 | // Loop functions |
| 3800 | - foreach(self::$_PHPExcelFunctions as $functionName => $function) { |
|
| 3800 | + foreach (self::$_PHPExcelFunctions as $functionName => $function) { |
|
| 3801 | 3801 | if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') { |
| 3802 | 3802 | $returnValue[] = $functionName; |
| 3803 | 3803 | } |
@@ -3824,7 +3824,7 @@ discard block |
||
| 3824 | 3824 | } // function count() |
| 3825 | 3825 | |
| 3826 | 3826 | |
| 3827 | - public function push($type,$value,$reference=null) { |
|
| 3827 | + public function push($type, $value, $reference = null) { |
|
| 3828 | 3828 | $this->_stack[$this->_count++] = array('type' => $type, |
| 3829 | 3829 | 'value' => $value, |
| 3830 | 3830 | 'reference' => $reference |
@@ -3846,11 +3846,11 @@ discard block |
||
| 3846 | 3846 | } // function pop() |
| 3847 | 3847 | |
| 3848 | 3848 | |
| 3849 | - public function last($n=1) { |
|
| 3850 | - if ($this->_count-$n < 0) { |
|
| 3849 | + public function last($n = 1) { |
|
| 3850 | + if ($this->_count - $n < 0) { |
|
| 3851 | 3851 | return null; |
| 3852 | 3852 | } |
| 3853 | - return $this->_stack[$this->_count-$n]; |
|
| 3853 | + return $this->_stack[$this->_count - $n]; |
|
| 3854 | 3854 | } // function last() |
| 3855 | 3855 | |
| 3856 | 3856 | |
@@ -2208,9 +2208,13 @@ discard block |
||
| 2208 | 2208 | // Basic validation that this is indeed a formula |
| 2209 | 2209 | // We return an empty array if not |
| 2210 | 2210 | $formula = trim($formula); |
| 2211 | - if ((!isset($formula{0})) || ($formula{0} != '=')) return array(); |
|
| 2211 | + if ((!isset($formula{0})) || ($formula{0} != '=')) { |
|
| 2212 | + return array(); |
|
| 2213 | + } |
|
| 2212 | 2214 | $formula = ltrim(substr($formula,1)); |
| 2213 | - if (!isset($formula{0})) return array(); |
|
| 2215 | + if (!isset($formula{0})) { |
|
| 2216 | + return array(); |
|
| 2217 | + } |
|
| 2214 | 2218 | |
| 2215 | 2219 | // Parse the formula and return the token stack |
| 2216 | 2220 | return $this->_parseFormula($formula); |
@@ -2263,9 +2267,13 @@ discard block |
||
| 2263 | 2267 | // Basic validation that this is indeed a formula |
| 2264 | 2268 | // We simply return the "cell value" (formula) if not |
| 2265 | 2269 | $formula = trim($formula); |
| 2266 | - if ($formula{0} != '=') return self::_wrapResult($formula); |
|
| 2270 | + if ($formula{0} != '=') { |
|
| 2271 | + return self::_wrapResult($formula); |
|
| 2272 | + } |
|
| 2267 | 2273 | $formula = ltrim(substr($formula,1)); |
| 2268 | - if (!isset($formula{0})) return self::_wrapResult($formula); |
|
| 2274 | + if (!isset($formula{0})) { |
|
| 2275 | + return self::_wrapResult($formula); |
|
| 2276 | + } |
|
| 2269 | 2277 | |
| 2270 | 2278 | $wsTitle = "\x00Wrk"; |
| 2271 | 2279 | if ($pCell !== NULL) { |
@@ -2715,8 +2723,11 @@ discard block |
||
| 2715 | 2723 | // echo 'Element is a Closing bracket<br />'; |
| 2716 | 2724 | $expectingOperand = false; |
| 2717 | 2725 | while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last ( |
| 2718 | - if ($o2 === NULL) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"'); |
|
| 2719 | - else $output[] = $o2; |
|
| 2726 | + if ($o2 === NULL) { |
|
| 2727 | + return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"'); |
|
| 2728 | + } else { |
|
| 2729 | + $output[] = $o2; |
|
| 2730 | + } |
|
| 2720 | 2731 | } |
| 2721 | 2732 | $d = $stack->last(2); |
| 2722 | 2733 | if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function? |
@@ -2794,8 +2805,12 @@ discard block |
||
| 2794 | 2805 | } elseif ($opCharacter == ',') { // Is this the separator for function arguments? |
| 2795 | 2806 | // echo 'Element is a Function argument separator<br />'; |
| 2796 | 2807 | while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last ( |
| 2797 | - if ($o2 === NULL) return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
|
| 2798 | - else $output[] = $o2; // pop the argument expression stuff and push onto the output |
|
| 2808 | + if ($o2 === NULL) { |
|
| 2809 | + return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
|
| 2810 | + } else { |
|
| 2811 | + $output[] = $o2; |
|
| 2812 | + } |
|
| 2813 | + // pop the argument expression stuff and push onto the output |
|
| 2799 | 2814 | } |
| 2800 | 2815 | // If we've a comma when we're expecting an operand, then what we actually have is a null operand; |
| 2801 | 2816 | // so push a null onto the stack |
@@ -2804,8 +2819,9 @@ discard block |
||
| 2804 | 2819 | } |
| 2805 | 2820 | // make sure there was a function |
| 2806 | 2821 | $d = $stack->last(2); |
| 2807 | - if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) |
|
| 2808 | - return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
|
| 2822 | + if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { |
|
| 2823 | + return $this->_raiseFormulaError("Formula Error: Unexpected ,"); |
|
| 2824 | + } |
|
| 2809 | 2825 | $d = $stack->pop(); |
| 2810 | 2826 | $stack->push($d['type'],++$d['value'],$d['reference']); // increment the argument count |
| 2811 | 2827 | $stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again |
@@ -2876,12 +2892,16 @@ discard block |
||
| 2876 | 2892 | if (strpos('!',$startRowColRef) !== false) { |
| 2877 | 2893 | list($rangeWS1,$startRowColRef) = explode('!',$startRowColRef); |
| 2878 | 2894 | } |
| 2879 | - if ($rangeWS1 != '') $rangeWS1 .= '!'; |
|
| 2895 | + if ($rangeWS1 != '') { |
|
| 2896 | + $rangeWS1 .= '!'; |
|
| 2897 | + } |
|
| 2880 | 2898 | $rangeWS2 = $rangeWS1; |
| 2881 | 2899 | if (strpos('!',$val) !== false) { |
| 2882 | 2900 | list($rangeWS2,$val) = explode('!',$val); |
| 2883 | 2901 | } |
| 2884 | - if ($rangeWS2 != '') $rangeWS2 .= '!'; |
|
| 2902 | + if ($rangeWS2 != '') { |
|
| 2903 | + $rangeWS2 .= '!'; |
|
| 2904 | + } |
|
| 2885 | 2905 | if ((is_integer($startRowColRef)) && (ctype_digit($val)) && |
| 2886 | 2906 | ($startRowColRef <= 1048576) && ($val <= 1048576)) { |
| 2887 | 2907 | // Row range |
@@ -2977,8 +2997,10 @@ discard block |
||
| 2977 | 2997 | } |
| 2978 | 2998 | |
| 2979 | 2999 | while (($op = $stack->pop()) !== NULL) { // pop everything off the stack and push onto output |
| 2980 | - if ((is_array($opCharacter) && $opCharacter['value'] == '(') || ($opCharacter === '(')) |
|
| 2981 | - return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced |
|
| 3000 | + if ((is_array($opCharacter) && $opCharacter['value'] == '(') || ($opCharacter === '(')) { |
|
| 3001 | + return $this->_raiseFormulaError("Formula Error: Expecting ')'"); |
|
| 3002 | + } |
|
| 3003 | + // if there are any opening braces on the stack, then braces were unbalanced |
|
| 2982 | 3004 | $output[] = $op; |
| 2983 | 3005 | } |
| 2984 | 3006 | return $output; |
@@ -3002,7 +3024,9 @@ discard block |
||
| 3002 | 3024 | |
| 3003 | 3025 | // evaluate postfix notation |
| 3004 | 3026 | private function _processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell = null) { |
| 3005 | - if ($tokens == false) return false; |
|
| 3027 | + if ($tokens == false) { |
|
| 3028 | + return false; |
|
| 3029 | + } |
|
| 3006 | 3030 | |
| 3007 | 3031 | // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet), |
| 3008 | 3032 | // so we store the parent worksheet so that we can re-attach it when necessary |
@@ -3019,8 +3043,12 @@ discard block |
||
| 3019 | 3043 | if (isset(self::$_binaryOperators[$token])) { |
| 3020 | 3044 | // echo 'Token is a binary operator<br />'; |
| 3021 | 3045 | // We must have two operands, error if we don't |
| 3022 | - if (($operand2Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3023 | - if (($operand1Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3046 | + if (($operand2Data = $stack->pop()) === NULL) { |
|
| 3047 | + return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3048 | + } |
|
| 3049 | + if (($operand1Data = $stack->pop()) === NULL) { |
|
| 3050 | + return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3051 | + } |
|
| 3024 | 3052 | |
| 3025 | 3053 | $operand1 = self::_dataTestReference($operand1Data); |
| 3026 | 3054 | $operand2 = self::_dataTestReference($operand2Data); |
@@ -3158,7 +3186,9 @@ discard block |
||
| 3158 | 3186 | // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on |
| 3159 | 3187 | } elseif (($token === '~') || ($token === '%')) { |
| 3160 | 3188 | // echo 'Token is a unary operator<br />'; |
| 3161 | - if (($arg = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3189 | + if (($arg = $stack->pop()) === NULL) { |
|
| 3190 | + return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); |
|
| 3191 | + } |
|
| 3162 | 3192 | $arg = $arg['value']; |
| 3163 | 3193 | if ($token === '~') { |
| 3164 | 3194 | // echo 'Token is a negation operator<br />'; |
@@ -3388,7 +3418,9 @@ discard block |
||
| 3388 | 3418 | } |
| 3389 | 3419 | } |
| 3390 | 3420 | // when we're out of tokens, the stack should have a single element, the final result |
| 3391 | - if ($stack->count() != 1) return $this->_raiseFormulaError("internal error"); |
|
| 3421 | + if ($stack->count() != 1) { |
|
| 3422 | + return $this->_raiseFormulaError("internal error"); |
|
| 3423 | + } |
|
| 3392 | 3424 | $output = $stack->pop(); |
| 3393 | 3425 | $output = $output['value']; |
| 3394 | 3426 | |
@@ -3502,8 +3534,12 @@ discard block |
||
| 3502 | 3534 | |
| 3503 | 3535 | private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) { |
| 3504 | 3536 | // Validate the two operands |
| 3505 | - if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false; |
|
| 3506 | - if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return false; |
|
| 3537 | + if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) { |
|
| 3538 | + return false; |
|
| 3539 | + } |
|
| 3540 | + if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) { |
|
| 3541 | + return false; |
|
| 3542 | + } |
|
| 3507 | 3543 | |
| 3508 | 3544 | $executeMatrixOperation = false; |
| 3509 | 3545 | // If either of the operands is a matrix, we need to treat them both as matrices |
@@ -3595,7 +3631,9 @@ discard block |
||
| 3595 | 3631 | protected function _raiseFormulaError($errorMessage) { |
| 3596 | 3632 | $this->formulaError = $errorMessage; |
| 3597 | 3633 | $this->debugLogStack = array(); |
| 3598 | - if (!$this->suppressFormulaErrors) throw new Exception($errorMessage); |
|
| 3634 | + if (!$this->suppressFormulaErrors) { |
|
| 3635 | + throw new Exception($errorMessage); |
|
| 3636 | + } |
|
| 3599 | 3637 | trigger_error($errorMessage, E_USER_ERROR); |
| 3600 | 3638 | } // function _raiseFormulaError() |
| 3601 | 3639 | |