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

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

23.59 hits per line

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

0.0
/src/General/Infrastructure/Service/ElasticsearchService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\General\Infrastructure\Service;
6

7
use App\General\Domain\Service\Interfaces\ElasticsearchServiceInterface;
8
use DateTimeInterface;
9
use Elasticsearch\Client;
10
use Elasticsearch\ClientBuilder;
11

12
/**
13
 * Class ElasticsearchService
14
 *
15
 * @package App\General
16
 */
17
class ElasticsearchService implements ElasticsearchServiceInterface
18
{
19
    public const INDEX_PREFIX = 'index';
20
    public const INDEX_DATE_FORMAT = 'Y_m_d';
21
    public const TEMPLATE_NAME = 'template_1';
22

23
    private Client $client;
24

25
    /**
26
     * Constructor
27
     */
28
    public function __construct(
29
        private string $host,
30
        private string $username,
31
        private string $password,
32
    ) {
33
        $this->instantiate();
×
34
    }
35

36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function instantiate(): void
40
    {
41
        $this->client = ClientBuilder::create()->setHosts([$this->host])
×
42
            ->setBasicAuthentication($this->username, $this->password)
×
43
            ->build();
×
44
    }
45

46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function index(string $index, string $documentId, array $body): mixed
50
    {
51
        return $this->client->index([
×
52
            'index' => $index,
×
53
            'id' => $documentId,
×
54
            'body' => $body,
×
55
        ]);
×
56
    }
57

58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function info(array $params = []): mixed
62
    {
63
        return $this->client->info($params);
×
64
    }
65

66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getTemplate(array $params): array
70
    {
71
        return $this->client->indices()->getTemplate($params);
×
72
    }
73

74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function putTemplate(array $params): array
78
    {
79
        return $this->client->indices()->putTemplate($params);
×
80
    }
81

82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function search(string $index, array $body, int $from = 0, int $size = 100): mixed
86
    {
87
        return $this->client->search(
×
88
            [
×
89
                'index' => $index,
×
90
                'from' => $from,
×
91
                'size' => $size,
×
92
                'body' => $body,
×
93
            ]
×
94
        );
×
95
    }
96

97
    /**
98
     * {@inheritdoc}
99
     */
100
    public static function generateIndexName(?int $timestamp = null): string
101
    {
102
        return self::INDEX_PREFIX . '_' .
×
103
            ($timestamp ? date(self::INDEX_DATE_FORMAT, $timestamp) : date(self::INDEX_DATE_FORMAT));
×
104
    }
105

106
    /**
107
     * {@inheritdoc}
108
     */
109
    public static function getDateTimeFormat(): string
110
    {
111
        return DateTimeInterface::RFC3339;
×
112
    }
113

114
    /**
115
     * {@inheritdoc}
116
     */
117
    public static function getPropertiesData(): array
118
    {
119
        return [
×
120
            'row_hash' => [
×
121
                'type' => 'text',
×
122
            ],
×
123
            'time_local' => [
×
124
                'type' => 'date',
×
125
            ],
×
126
            // TODO: extend/edit elastic properties according to your needs
×
127
        ];
×
128
    }
129
}
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