• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lmc-eu / matej-client-php / 7529439147

15 Jan 2024 01:18PM UTC coverage: 100.0%. Remained the same
7529439147

Pull #145

github

web-flow
Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #145: Bump actions/checkout from 3 to 4

712 of 712 relevant lines covered (100.0%)

35.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Http/HmacAuthentication.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\Http;
4

5
use Http\Message\Authentication;
6
use Psr\Http\Message\RequestInterface;
7

8
/**
9
 * Use api key to sign request with hmac_timestamp and hmac_sign query parameters.
10
 *
11
 * @internal
12
 */
13
class HmacAuthentication implements Authentication
14
{
15
    /** @var string */
16
    private $apiKey;
17

18
    public function __construct(string $apiKey)
19
    {
20
        $this->apiKey = $apiKey;
28✔
21
    }
22

23
    public function authenticate(RequestInterface $request): RequestInterface
24
    {
25
        $params = $this->addAuthenticationToParamsFromRequest($request);
28✔
26

27
        return $this->createRequestWithParams($request, $params);
28✔
28
    }
29

30
    private function addAuthenticationToParamsFromRequest(RequestInterface $request): array
31
    {
32
        $params = $this->parseQueryParamsFromRequest($request);
28✔
33

34
        $params['hmac_timestamp'] = time();
28✔
35

36
        $unsignedRequest = $this->createRequestWithParams($request, $params);
28✔
37

38
        $params['hmac_sign'] = hash_hmac('sha1', $unsignedRequest->getRequestTarget(), $this->apiKey);
28✔
39

40
        return $params;
28✔
41
    }
42

43
    private function parseQueryParamsFromRequest(RequestInterface $request): array
44
    {
45
        $uri = $request->getUri();
28✔
46
        $query = $uri->getQuery();
28✔
47

48
        $params = [];
28✔
49
        parse_str($query, $params);
28✔
50

51
        return $params;
28✔
52
    }
53

54
    private function createRequestWithParams(RequestInterface $request, array $params): RequestInterface
55
    {
56
        $uri = $request->getUri();
28✔
57

58
        $query = http_build_query($params, '', '&');
28✔
59
        $uri = $uri->withQuery($query);
28✔
60

61
        return $request->withUri($uri);
28✔
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc