Skip to content

Commit a14cab1

Browse files
committed
schedule fix + CreditChecker (#2) + generics improve
1 parent 04a795f commit a14cab1

File tree

89 files changed

+436
-283
lines changed

Some content is hidden

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

89 files changed

+436
-283
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.github export-ignore
4+
phpstan.neon export-ignore
5+
tests/ export-ignore
6+
docs/ export-ignore
7+
examples/ export-ignore

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.idea/
22
vendor/
33
composer.lock
4-
test.php
5-
src/Connection/ConnectionMock.php
64
coverage.html
5+
tests/**/output/*.actual
6+
tests/**/output/*.expected
7+
test.php
8+
example.php

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2021, BulkGate
3+
Copyright (c) 2022, BulkGate
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"authors": [
88
{
99
"name": "TOPefekt s.r.o.",
10-
"homepage": "http://www.topefekt.com"
10+
"homepage": "https://www.bulkgate.com"
1111
},
1212
{
1313
"name": "Lukáš Piják",
@@ -22,15 +22,15 @@
2222
},
2323
"require-dev": {
2424
"nette/tester": "~2.0",
25-
"tracy/tracy": "^2.4",
26-
"phpstan/phpstan": "^1.2",
27-
"mockery/mockery": "^1.4",
25+
"tracy/tracy": "^2.9",
26+
"phpstan/phpstan": "^1.9",
27+
"mockery/mockery": "^1.5",
2828
"nette/di": "^3.0"
2929
},
3030
"autoload": {
3131
"classmap": ["src/"]
3232
},
33-
"minimum-stability": "dev",
33+
"minimum-stability": "RC",
3434
"scripts": {
3535
"tester": "tester tests -s -C",
3636
"coverage": "tester -C tests --coverage=coverage.html --coverage-src=src",

examples/nette/DIContainerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php declare(strict_types=1);
22

33
/**
4-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
4+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
55
* @link https://www.bulkgate.com/
66
*/
77

examples/nette/promotional.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
<?php declare(strict_types=1);
22

33
/**
4-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
4+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
55
* @link https://www.bulkgate.com/
66
*/
77

8-
use BulkGate\Sdk\{
9-
Message\Bulk,
10-
Message\Component\Button,
11-
Message\Component\Image,
12-
Message\Component\SimpleText,
13-
Message\MultiChannel,
14-
Message\Sms,
15-
Message\Viber,
16-
Sender
17-
};
8+
use BulkGate\{Sdk\Message\Bulk, Sdk\Message\Component\Button, Sdk\Message\Component\Image, Sdk\Message\Component\SimpleText, Sdk\Message\MultiChannel, Sdk\Message\Sms, Sdk\Message\Viber, Sdk\Sender};
189

1910
require_once __DIR__ . '/../../vendor/autoload.php';
2011
require __DIR__ . '/DIContainerFactory.php';

examples/nette/transactional.sms.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php declare(strict_types=1);
22

33
/**
4-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
4+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
55
* @link https://www.bulkgate.com/
66
*/
77

examples/nette/transactional.viber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php declare(strict_types=1);
22

33
/**
4-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
4+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
55
* @link https://www.bulkgate.com/
66
*/
77

phpstan.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ parameters:
22
level: 8
33
paths:
44
- src
5-
ignoreErrors:
6-
-
7-
message: '~Class ReturnTypeWillChange is not an Attribute class\.~'
8-
path: src/Utils/Iterator.php
9-
reportUnmatchedIgnoredErrors: false

src/Configurator/Configurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Configurator;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/Configurator/PrefixMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Configurator;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/Configurator/SmsConfigurator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Configurator;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

@@ -68,6 +68,9 @@ public function mobileConnect(string $key): void
6868
}
6969

7070

71+
/**
72+
* @param int<1, max> $id
73+
*/
7174
public function portalProfile(int $id): void
7275
{
7376
$this->sender_id = SmsSender::GATE_PORTAL_PROFILE;

src/Configurator/SmsCountryConfigurator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Configurator;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

@@ -15,11 +15,13 @@ class SmsCountryConfigurator implements Configurator
1515
{
1616
use Strict;
1717

18-
private const PREFIX_REGEX = '~^(1|7|20|27|30|31|32|33|34|36|39|40|41|43|44|45|46|47|48|49|51|52|53|54|55|56|57|58|60|61|62|63|64|65|66|81|82|84|86|90|91|92|93|94|95|98|211|212|213|216|218|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|248|249|250|251|252|253|254|255|256|257|258|260|261|262|263|264|265|266|267|268|269|291|297|298|299|350|351|352|353|354|355|356|357|358|359|370|371|372|373|374|375|376|377|378|380|381|382|383|385|386|387|389|420|421|423|500|501|502|503|504|505|506|507|508|509|590|591|592|593|594|595|596|597|598|599|673|674|675|676|677|678|679|680|682|685|686|687|688|689|852|853|855|856|880|886|960|961|962|963|964|965|966|967|968|971|972|973|974|975|976|977|992|993|994|995|996|998).*~sD';
18+
private const PrefixRegex = '~^(1|7|20|27|30|31|32|33|34|36|39|40|41|43|44|45|46|47|48|49|51|52|53|54|55|56|57|58|60|61|62|63|64|65|66|81|82|84|86|90|91|92|93|94|95|98|211|212|213|216|218|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|248|249|250|251|252|253|254|255|256|257|258|260|261|262|263|264|265|266|267|268|269|291|297|298|299|350|351|352|353|354|355|356|357|358|359|370|371|372|373|374|375|376|377|378|380|381|382|383|385|386|387|389|420|421|423|500|501|502|503|504|505|506|507|508|509|590|591|592|593|594|595|596|597|598|599|673|674|675|676|677|678|679|680|682|685|686|687|688|689|852|853|855|856|880|886|960|961|962|963|964|965|966|967|968|971|972|973|974|975|976|977|992|993|994|995|996|998).*~sD';
1919

2020
private bool $unicode;
2121

22-
/** @var array<string, array<string>> */
22+
/**
23+
* @var array<string, array<string>>
24+
*/
2325
protected array $profile = [];
2426

2527

@@ -51,7 +53,7 @@ public function removeCountry(string $iso): void
5153

5254
public function configure(Base $message): void
5355
{
54-
if (preg_match(self::PREFIX_REGEX, $message->phone_number->phone_number, $match))
56+
if (preg_match(self::PrefixRegex, $message->phone_number->phone_number, $match))
5557
{
5658
[, $prefix] = $match;
5759

src/Configurator/ViberConfigurator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace BulkGate\Sdk\Configurator;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

10-
use BulkGate\Sdk\Utils\Strict;
11-
use BulkGate\Sdk\Message\{Base, Channel, Component\Button, Component\Image};
10+
use BulkGate\Sdk\{Utils\Strict, Message\Base, Message\Channel, Message\Component\Button, Message\Component\Image};
1211

1312
class ViberConfigurator implements Configurator
1413
{
@@ -20,6 +19,9 @@ class ViberConfigurator implements Configurator
2019

2120
private ?Image $image = null;
2221

22+
/**
23+
* @var int<60, max>|null
24+
*/
2325
private ?int $expiration = null;
2426

2527

@@ -41,6 +43,9 @@ public function image(string $url, bool $zoom = false): void
4143
}
4244

4345

46+
/**
47+
* @param int<60, max>|null $expiration
48+
*/
4449
public function expiration(?int $expiration): void
4550
{
4651
$this->expiration = $expiration;

src/Connection/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Connection;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/Connection/ConnectionStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Connection;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/Connection/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk\Connection;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/Connection/Request.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BulkGate\Sdk\Connection;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

1010
use BulkGate\Sdk\{Message\Send, Utils\CompressJson, Utils\Json, Utils\Strict};
11+
use function array_merge;
1112

1213
class Request
1314
{
@@ -17,15 +18,19 @@ class Request
1718

1819
private Send $send;
1920

20-
/** @var array<mixed> */
21+
/**
22+
* @var array<array-key, mixed>
23+
*/
2124
private array $parameters;
2225

23-
/** @var array<callable> */
26+
/**
27+
* @var array<array-key, callable>
28+
*/
2429
public array $encoders = [];
2530

2631

2732
/**
28-
* @param array<mixed> $parameters
33+
* @param array<array-key, mixed> $parameters
2934
*/
3035
public function __construct(string $action, Send $send, array $parameters = [])
3136
{
@@ -38,8 +43,8 @@ public function __construct(string $action, Send $send, array $parameters = [])
3843

3944

4045
/**
41-
* @param array<mixed> $data
42-
* @return array<mixed>
46+
* @param array<array-key, mixed> $data
47+
* @return array{string, string, array<array-key, mixed>}
4348
*/
4449
public function encode(string $content_type = 'application/json', array $data = []): array
4550
{

src/Connection/Response.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
namespace BulkGate\Sdk\Connection;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

10-
use BulkGate\Sdk\ApiException;
11-
use BulkGate\Sdk\Utils\{CompressJson, Json, Strict};
1210
use Throwable;
11+
use BulkGate\{Sdk\ApiException, Sdk\Utils\CompressJson, Sdk\Utils\Json, Sdk\Utils\Strict};
1312

1413
class Response
1514
{
1615
use Strict;
1716

18-
/** @var array<mixed> */
17+
/**
18+
* @var array<array-key, mixed>
19+
*/
1920
private array $data = [];
2021

21-
/** @var array<callable> */
22+
/**
23+
* @var array<string, callable>
24+
*/
2225
public array $decoders = [];
2326

24-
/** @var array<mixed>|null */
27+
/**
28+
* @var array<string, mixed>|null
29+
*/
2530
private ?array $error = null;
2631

2732

@@ -84,7 +89,7 @@ public function __construct(?string $content_type, string $data)
8489

8590

8691
/**
87-
* @return array<mixed>
92+
* @return array<array-key, mixed>
8893
*/
8994
public function getData(): array
9095
{

src/Country.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace BulkGate\Sdk;
44

55
/**
6-
* @author Lukáš Piják 2021 TOPefekt s.r.o.
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
77
* @link https://www.bulkgate.com/
88
*/
99

src/CreditChecker.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace BulkGate\Sdk;
4+
5+
/**
6+
* @author Lukáš Piják 2022 TOPefekt s.r.o.
7+
* @link https://www.bulkgate.com/
8+
*/
9+
10+
class CreditChecker
11+
{
12+
use Utils\Strict;
13+
14+
private Connection\Connection $connection;
15+
16+
17+
public function __construct(Connection\Connection $connection)
18+
{
19+
$this->connection = $connection;
20+
}
21+
22+
23+
/**
24+
* @return array{wallet: string, credit: float, currency: string, free_messages: int, datetime: string}|array<array-key, mixed>
25+
* @throws ApiException
26+
*/
27+
public function check(): array
28+
{
29+
$response = $this->connection->send(new Connection\Request('info', new Message\Api()));
30+
31+
$response->checkException();
32+
33+
return $response->getData();
34+
}
35+
}

0 commit comments

Comments
 (0)