Skip to content

Commit 82e42ae

Browse files
committed
Simplify some stuff in the Client
1 parent 5b3a06f commit 82e42ae

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

composer.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"webmozart/assert": "^1.11"
2222
},
2323
"require-dev": {
24-
"infection/infection": "^0.26",
25-
"kriswallsmith/buzz": "^1.2",
26-
"nyholm/psr7": "^1.5",
27-
"phpunit/phpunit": "^9.5",
28-
"psalm/plugin-phpunit": "^0.17",
29-
"setono/code-quality-pack": "^2.2",
30-
"shipmonk/composer-dependency-analyser": "^1.8"
24+
"infection/infection": "^0.26.21",
25+
"kriswallsmith/buzz": "^1.3",
26+
"nyholm/psr7": "^1.8",
27+
"phpunit/phpunit": "^9.6",
28+
"psalm/plugin-phpunit": "^0.19",
29+
"setono/code-quality-pack": "^2.9",
30+
"shipmonk/composer-dependency-analyser": "^1.8.2"
3131
},
3232
"prefer-stable": true,
3333
"autoload": {
@@ -48,11 +48,6 @@
4848
},
4949
"sort-packages": true
5050
},
51-
"extra": {
52-
"branch-alias": {
53-
"dev-master": "1.0-dev"
54-
}
55-
},
5651
"scripts": {
5752
"analyse": "psalm",
5853
"check-style": "ecs check",

psalm.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?xml version="1.0"?>
22
<psalm
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
errorLevel="1"
54
xmlns="https://getpsalm.org/schema/config"
65
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
6+
findUnusedVariablesAndParams="false"
7+
findUnusedPsalmSuppress="false"
8+
findUnusedCode="false"
9+
findUnusedBaselineEntry="false"
10+
errorLevel="1"
711
phpVersion="8.1"
812
>
913
<projectFiles>

src/Client/Client.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Setono\MetaConversionsApi\Client;
66

77
use Buzz\Client\Curl;
8-
use Composer\InstalledVersions;
8+
use FacebookAds\ApiConfig;
99
use Nyholm\Psr7\Factory\Psr17Factory;
1010
use Psr\Http\Client\ClientInterface as HttpClientInterface;
1111
use Psr\Http\Message\RequestFactoryInterface;
@@ -16,7 +16,6 @@
1616
use Psr\Log\NullLogger;
1717
use Setono\MetaConversionsApi\Event\Event;
1818
use Setono\MetaConversionsApi\Exception\ClientException;
19-
use Webmozart\Assert\Assert;
2019

2120
final class Client implements ClientInterface, LoggerAwareInterface
2221
{
@@ -60,7 +59,7 @@ public function sendEvent(Event $event): void
6059

6160
$request = $requestFactory->createRequest(
6261
'POST',
63-
sprintf('https://graph.facebook.com/%s/%s/events', self::getEndpointVersion(), $pixel->id),
62+
sprintf('https://graph.facebook.com/%s/%s/events', sprintf('v%s', ApiConfig::APIVersion), $pixel->id),
6463
)
6564
->withHeader('Content-Type', 'application/x-www-form-urlencoded')
6665
->withHeader('Accept', 'application/json')
@@ -162,14 +161,4 @@ public function setLogger(LoggerInterface $logger): void
162161
{
163162
$this->logger = $logger;
164163
}
165-
166-
private static function getEndpointVersion(): string
167-
{
168-
$version = InstalledVersions::getVersion('facebook/php-business-sdk');
169-
Assert::notNull($version);
170-
171-
[$major, $minor] = explode('.', $version, 3);
172-
173-
return sprintf('v%s.%s', $major, $minor);
174-
}
175164
}

tests/Client/ClientTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ public function sendRequest(RequestInterface $request): ResponseInterface
8484

8585
final class TestLogger extends AbstractLogger
8686
{
87-
/** @var list<string> */
87+
/** @var list<non-empty-string> */
8888
public array $messages = [];
8989

90-
public function log($level, $message, array $context = []): void
90+
public function log($level, string|\Stringable $message, array $context = []): void
9191
{
92-
/** @psalm-suppress RedundantCastGivenDocblockType */
93-
$this->messages[] = (string) $message;
92+
$message = (string) $message;
93+
if ('' === $message) {
94+
return;
95+
}
96+
97+
$this->messages[] = $message;
9498
}
9599

96100
public function hasMessageMatching(string $regexp): bool

0 commit comments

Comments
 (0)