Skip to content

Commit e209d21

Browse files
author
Vítězslav Dvořák
committed
code reformat
1 parent 016787b commit e209d21

File tree

54 files changed

+1428
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1428
-602
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ composer.phar
2929
/.phpdoc/
3030
/.env
3131
/node_modules/
32-
/debian/files
33-
/examples/*.xml

.openapi-generator/templates/Statementor.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Statementor extends \Ease\Sand
111111
*
112112
* @throws \Exception
113113
*/
114-
public function setScope(string $scope): void
114+
public function setScope($scope): \DatePeriod
115115
{
116116
switch ($scope) {
117117
case 'yesterday':
@@ -194,7 +194,6 @@ class Statementor extends \Ease\Sand
194194
$this->since = new \DateTime($scope);
195195
$this->until = (new \DateTime($scope))->setTime(23, 59, 59, 999);
196196
197-
break;
198197
}
199198

200199
throw new \InvalidArgumentException('Unknown scope '.$scope);

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'strict_param' => true,
2121
'no_trailing_whitespace' => false,
2222
'no_trailing_whitespace_in_comment' => false,
23-
'braces' => false,
23+
'single_space_around_construct' => true,
2424
'single_blank_line_at_eof' => false,
2525
'blank_line_after_namespace' => false,
2626
'no_leading_import_slash' => false,

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ vendor: composer.json composer.lock ## Installs composer dependencies
2121

2222
.PHONY: cs
2323
cs: ## Update Coding Standards
24-
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose
24+
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose --allow-risky=yes
2525

2626
.PHONY: phpunit
2727
phpunit: ## Run Tests

lib/ApiClient.php

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

33
/**
4-
*
4+
*
55
*
66
* @author Vitex <vitex@hippy.cz>
77
* @copyright 2023 Vitex@hippy.cz (G)
8-
*
8+
*
99
* PHP 7
1010
*/
1111

@@ -25,12 +25,12 @@ class ApiClient extends \GuzzleHttp\Client
2525
protected $xIBMClientId = null;
2626

2727
/**
28-
* the end IP address of the client application (no server) in IPv4 or IPv6
29-
* format. If the bank client (your user) uses a browser by which he
30-
* accesses your server app, we need to know the IP address of his browser.
31-
* Always provide the closest IP address to the real end-user possible.
28+
* the end IP address of the client application (no server) in IPv4 or IPv6
29+
* format. If the bank client (your user) uses a browser by which he
30+
* accesses your server app, we need to know the IP address of his browser.
31+
* Always provide the closest IP address to the real end-user possible.
3232
* (optional)
33-
*
33+
*
3434
* @var string
3535
*/
3636
protected $pSUIPAddress = null;
@@ -43,13 +43,13 @@ class ApiClient extends \GuzzleHttp\Client
4343

4444
/**
4545
* @inheritDoc
46-
*
46+
*
4747
* $config['clientid'] - obtained from Developer Portal - when you registered your app with us.
4848
* $config['cert'] = ['/path/to/cert.p12','certificat password']
4949
* $config['clientpubip'] = the closest IP address to the real end-user
5050
* $config['mocking'] = true to use /rbcz/premium/mock/* endpoints
51-
*
52-
* @param array $config
51+
*
52+
* @param array $config
5353
* @throws \Exception CERT_FILE is not set
5454
* @throws \Exception CERT_PASS is not set
5555
*/
@@ -73,7 +73,7 @@ public function __construct(array $config = [])
7373

7474
if (array_key_exists('debug', $config) === false) {
7575
$config['debug'] = \Ease\Shared::cfg('API_DEBUG', false);
76-
}
76+
}
7777

7878
if (array_key_exists('clientpubip', $config)) {
7979
$this->pSUIPAddress = $config['clientpubip'];
@@ -88,7 +88,7 @@ public function __construct(array $config = [])
8888

8989
/**
9090
* ClientID obtained from Developer Portal
91-
*
91+
*
9292
* @return string
9393
*/
9494
public function getXIBMClientId()
@@ -98,17 +98,17 @@ public function getXIBMClientId()
9898

9999
/**
100100
* Keep user public IP here
101-
*
101+
*
102102
* @return string
103103
*/
104104
public function getpSUIPAddress()
105105
{
106106
return $this->pSUIPAddress;
107-
}
107+
}
108108

109109
/**
110110
* Use mocking uri for api calls ?
111-
*
111+
*
112112
* @return boolean
113113
*/
114114
public function getMockMode()
@@ -118,9 +118,9 @@ public function getMockMode()
118118

119119
/**
120120
* Obtain Your current Public IP
121-
*
121+
*
122122
* @deprecated since version 0.1 - Do not use in production Environment!
123-
*
123+
*
124124
* @return string
125125
*/
126126
public static function getPublicIP()
@@ -136,9 +136,9 @@ public static function getPublicIP()
136136

137137
/**
138138
* Source Identifier
139-
*
139+
*
140140
* @deprecated since version 0.1 - Do not use in production Environment!
141-
*
141+
*
142142
* @return string
143143
*/
144144
public static function sourceString()
@@ -148,15 +148,15 @@ public static function sourceString()
148148

149149
/**
150150
* Try to check certificate readibilty
151-
*
152-
*
151+
*
152+
*
153153
* @param string $certFile path to certificate
154154
* @param boolean $die throw exception or return false ?
155155
* @throws Exception - Certificate file not found
156-
*
156+
*
157157
* @return boolean certificate file
158158
*/
159-
public static function checkCertificatePresence($certFile, $die = false)
159+
public static function checkCertificatePresence(string $certFile, bool $die = false): bool
160160
{
161161
$found = false;
162162
if ((file_exists($certFile) === false) || (is_readable($certFile) === false)) {
@@ -168,14 +168,30 @@ public static function checkCertificatePresence($certFile, $die = false)
168168
} else {
169169
$found = true;
170170
}
171-
return $found;
171+
return $found;
172+
}
173+
174+
public static function checkCertificate($certFile, $password): bool
175+
{
176+
return self::checkCertificatePresence($certFile) && self::checkCertificatePassword($certFile, $password);
177+
}
178+
179+
public static function checkCertificatePassword(string $certFile, string $password): bool
180+
{
181+
$certContent = file_get_contents($certFile);
182+
if (openssl_pkcs12_read($certContent, $certs, $password) === false) {
183+
fwrite(\STDERR, 'Cannot read PKCS12 certificate file: '.$certFile.\PHP_EOL);
184+
exit(1);
185+
}
186+
return true;
172187
}
173188

189+
174190
/**
175191
* Request Identifier
176-
*
192+
*
177193
* @deprecated since version 0.1 - Do not use in production Environment!
178-
*
194+
*
179195
* @return string
180196
*/
181197
public static function getxRequestId()

lib/ApiException.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* ApiException
5-
* PHP version 7.4
5+
* PHP version 7.4+
66
*
77
* @category Class
88
* @package VitexSoftware\Raiffeisenbank
@@ -29,7 +29,7 @@
2929

3030
namespace VitexSoftware\Raiffeisenbank;
3131

32-
use Exception;
32+
use \Exception;
3333

3434
/**
3535
* ApiException Class Doc Comment
@@ -51,7 +51,7 @@ class ApiException extends Exception
5151
/**
5252
* The HTTP header of the server response.
5353
*
54-
* @var string[]|null
54+
* @var string[][]|null
5555
*/
5656
protected $responseHeaders;
5757

@@ -67,7 +67,7 @@ class ApiException extends Exception
6767
*
6868
* @param string $message Error message
6969
* @param int $code HTTP status code
70-
* @param string[]|null $responseHeaders HTTP response header
70+
* @param string[][]|null $responseHeaders HTTP response header
7171
* @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string
7272
*/
7373
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
@@ -80,7 +80,7 @@ public function __construct($message = "", $code = 0, $responseHeaders = [], $re
8080
/**
8181
* Gets the HTTP response header
8282
*
83-
* @return string[]|null HTTP response header
83+
* @return string[][]|null HTTP response header
8484
*/
8585
public function getResponseHeaders()
8686
{

lib/Configuration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Configuration
5-
* PHP version 7.4
5+
* PHP version 7.4+
66
*
77
* @category Class
88
* @package VitexSoftware\Raiffeisenbank
@@ -211,7 +211,7 @@ public function getAccessToken()
211211
/**
212212
* Sets boolean format for query string.
213213
*
214-
* @param string $booleanFormatForQueryString Boolean format for query string
214+
* @param string $booleanFormat Boolean format for query string
215215
*
216216
* @return $this
217217
*/
@@ -497,7 +497,7 @@ public static function getHostString(array $hostsSettings, $hostIndex, array $va
497497

498498
// check array index out of bound
499499
if ($hostIndex < 0 || $hostIndex >= count($hostsSettings)) {
500-
throw new \InvalidArgumentException("Invalid index $hostIndex when selecting the host. Must be less than " . count($hostsSettings));
500+
throw new \InvalidArgumentException("Invalid index $hostIndex when selecting the host. Must be less than ".count($hostsSettings));
501501
}
502502

503503
$host = $hostsSettings[$hostIndex];
@@ -507,13 +507,13 @@ public static function getHostString(array $hostsSettings, $hostIndex, array $va
507507
foreach ($host["variables"] ?? [] as $name => $variable) {
508508
if (array_key_exists($name, $variables)) { // check to see if it's in the variables provided by the user
509509
if (!isset($variable['enum_values']) || in_array($variables[$name], $variable["enum_values"], true)) { // check to see if the value is in the enum
510-
$url = str_replace("{" . $name . "}", $variables[$name], $url);
510+
$url = str_replace("{".$name."}", $variables[$name], $url);
511511
} else {
512-
throw new \InvalidArgumentException("The variable `$name` in the host URL has invalid value " . $variables[$name] . ". Must be " . join(',', $variable["enum_values"]) . ".");
512+
throw new \InvalidArgumentException("The variable `$name` in the host URL has invalid value ".$variables[$name].". Must be ".join(',', $variable["enum_values"]).".");
513513
}
514514
} else {
515515
// use default value
516-
$url = str_replace("{" . $name . "}", $variable["default_value"], $url);
516+
$url = str_replace("{".$name."}", $variable["default_value"], $url);
517517
}
518518
}
519519

lib/HeaderSelector.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* HeaderSelector
5-
* PHP version 7.4
5+
* PHP version 7.4+
66
*
77
* @category Class
88
* @package VitexSoftware\Raiffeisenbank
@@ -87,7 +87,7 @@ private function selectAcceptHeader(array $accept): ?string
8787
}
8888

8989
# If none of the available Accept headers is of type "json", then just use all them
90-
$headersWithJson = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept);
90+
$headersWithJson = $this->selectJsonMimeList($accept);
9191
if (count($headersWithJson) === 0) {
9292
return implode(',', $accept);
9393
}
@@ -97,6 +97,35 @@ private function selectAcceptHeader(array $accept): ?string
9797
return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson);
9898
}
9999

100+
/**
101+
* Detects whether a string contains a valid JSON mime type
102+
*
103+
* @param string $searchString
104+
* @return bool
105+
*/
106+
public function isJsonMime(string $searchString): bool
107+
{
108+
return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1;
109+
}
110+
111+
/**
112+
* Select all items from a list containing a JSON mime type
113+
*
114+
* @param array $mimeList
115+
* @return array
116+
*/
117+
private function selectJsonMimeList(array $mimeList): array
118+
{
119+
$jsonMimeList = [];
120+
foreach ($mimeList as $mime) {
121+
if ($this->isJsonMime($mime)) {
122+
$jsonMimeList[] = $mime;
123+
}
124+
}
125+
return $jsonMimeList;
126+
}
127+
128+
100129
/**
101130
* Create an Accept header string from the given "Accept" headers array, recalculating all weights
102131
*
@@ -114,6 +143,7 @@ private function getAcceptHeaderWithAdjustedWeight(array $accept, array $headers
114143
];
115144

116145
foreach ($accept as $header) {
146+
117147
$headerData = $this->getHeaderAndWeight($header);
118148

119149
if (stripos($headerData['header'], 'application/json') === 0) {

lib/Model/DownloadStatementRequest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
namespace VitexSoftware\Raiffeisenbank\Model;
3232

33-
use ArrayAccess;
34-
use VitexSoftware\Raiffeisenbank\ObjectSerializer;
33+
use \ArrayAccess;
34+
use \VitexSoftware\Raiffeisenbank\ObjectSerializer;
3535

3636
/**
3737
* DownloadStatementRequest Class Doc Comment
@@ -555,3 +555,5 @@ public function toHeaderValue()
555555
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
556556
}
557557
}
558+
559+

lib/Model/GetBalance200Response.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
namespace VitexSoftware\Raiffeisenbank\Model;
3232

33-
use ArrayAccess;
34-
use VitexSoftware\Raiffeisenbank\ObjectSerializer;
33+
use \ArrayAccess;
34+
use \VitexSoftware\Raiffeisenbank\ObjectSerializer;
3535

3636
/**
3737
* GetBalance200Response Class Doc Comment
@@ -516,3 +516,5 @@ public function toHeaderValue()
516516
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
517517
}
518518
}
519+
520+

0 commit comments

Comments
 (0)