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

vysokeskoly / image-api-sdk / 12023120951

17 Oct 2024 11:09AM UTC coverage: 94.526%. Remained the same
12023120951

push

github

MortalFlesh
Version 3.3.0

259 of 274 relevant lines covered (94.53%)

20.3 hits per line

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

100.0
/src/Command/UploadImageCommand.php
1
<?php declare(strict_types=1);
2

3
namespace VysokeSkoly\ImageApi\Sdk\Command;
4

5
use Http\Message\MultipartStream\MultipartStreamBuilder;
6
use Lmc\Cqrs\Http\Command\AbstractHttpPostCommand;
7
use Psr\Http\Message\RequestFactoryInterface;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\StreamFactoryInterface;
10
use Psr\Http\Message\StreamInterface;
11
use VysokeSkoly\ImageApi\Sdk\ValueObject\Api;
12
use VysokeSkoly\ImageApi\Sdk\ValueObject\ImageHash;
13
use VysokeSkoly\ImageApi\Sdk\ValueObject\ImageInterface;
14

15
class UploadImageCommand extends AbstractHttpPostCommand
16
{
17
    private ?MultipartStreamBuilder $builder = null;
18

19
    public function __construct(
20
        RequestFactoryInterface $requestFactory,
21
        private StreamFactoryInterface $streamFactory,
22
        private Api $api,
23
        private ImageInterface $image,
24
    ) {
25
        parent::__construct($requestFactory);
28✔
26
    }
27

28
    public function getUri(): string
29
    {
30
        return $this->api->createUrl('/image/');
20✔
31
    }
32

33
    public function createBody(): StreamInterface
34
    {
35
        return $this->buildBody()->build();
20✔
36
    }
37

38
    private function buildBody(): MultipartStreamBuilder
39
    {
40
        if ($this->builder === null) {
20✔
41
            $this->builder = new MultipartStreamBuilder($this->streamFactory);
20✔
42
            $this->builder->addResource(
20✔
43
                $this->image->getPath()->getFilename(),
20✔
44
                $this->image->asStream($this->streamFactory),
20✔
45
                [
10✔
46
                    'filename' => $this->image->getHash()->getHash(),
20✔
47
                ],
10✔
48
            );
10✔
49
        }
50

51
        return $this->builder;
20✔
52
    }
53

54
    public function modifyRequest(RequestInterface $request): RequestInterface
55
    {
56
        $builder = $this->buildBody();
4✔
57

58
        return $request
2✔
59
            ->withHeader('Content-Type', 'multipart/form-data; boundary="' . $builder->getBoundary() . '"');
4✔
60
    }
61

62
    public function getImageHash(): ImageHash
63
    {
64
        return $this->image->getHash();
8✔
65
    }
66
}
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

© 2026 Coveralls, Inc