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

mimmi20 / monolog-factory / 13471467265

22 Feb 2025 09:02AM UTC coverage: 87.861% (-0.1%) from 87.966%
13471467265

push

github

web-flow
Merge pull request #662 from mimmi20/dependabot/composer/4.x/phpstan/phpstan-tw-2.1.6

composer (4.x)(deps-dev): update phpstan/phpstan requirement from ^2.1.5 to ^2.1.6

2497 of 2842 relevant lines covered (87.86%)

8.72 hits per line

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

14.81
/src/Client/ElasticsearchV8Factory.php
1
<?php
2

3
/**
4
 * This file is part of the mimmi20/monolog-factory package.
5
 *
6
 * Copyright (c) 2022-2025, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace Mimmi20\MonologFactory\Client;
15

16
use Elastic\Elasticsearch\Client as V8Client;
17
use Elastic\Elasticsearch\ClientBuilder;
18
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
19
use Laminas\ServiceManager\Factory\FactoryInterface;
20
use Override;
21
use Psr\Container\ContainerInterface;
22

23
use function array_filter;
24
use function array_key_exists;
25
use function assert;
26
use function is_array;
27
use function is_string;
28

29
final class ElasticsearchV8Factory implements FactoryInterface
30
{
31
    /**
32
     * @param string                                              $requestedName
33
     * @param array<string, (array<string>|bool|int|string)>|null $options
34
     * @phpstan-param array{hosts?: bool|array<string>, retries?: int, api-id?: string, api-key?: string, username?: string, password?: string, metadata?: bool|int}|null $options
35
     *
36
     * @throws ServiceNotCreatedException if an exception is raised when creating a service
37
     *
38
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
39
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
40
     */
41
    #[Override]
1✔
42
    public function __invoke(ContainerInterface $container, $requestedName, array | null $options = null): V8Client
43
    {
44
        if (!is_array($options)) {
1✔
45
            throw new ServiceNotCreatedException('Options must be an Array');
×
46
        }
47

48
        if (!array_key_exists('hosts', $options)) {
1✔
49
            throw new ServiceNotCreatedException('No Hosts provided');
1✔
50
        }
51

52
        if (!is_array($options['hosts'])) {
×
53
            throw new ServiceNotCreatedException('No Host data provided');
×
54
        }
55

56
        $metadata = true;
×
57

58
        $builder = ClientBuilder::create();
×
59
        $builder->setHosts(
×
60
            array_filter(
×
61
                $options['hosts'],
×
62
                /** @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter */
63
                static fn (string $host): bool => true,
×
64
            ),
×
65
        );
×
66

67
        if (array_key_exists('retries', $options)) {
×
68
            $builder->setRetries($options['retries']);
×
69
        }
70

71
        if (array_key_exists('api-id', $options) && array_key_exists('api-key', $options)) {
×
72
            assert(is_string($options['api-id']));
×
73
            assert(is_string($options['api-key']));
×
74

75
            $builder->setApiKey($options['api-key'], $options['api-id']);
×
76
        } elseif (array_key_exists('username', $options) && array_key_exists('password', $options)) {
×
77
            $builder->setBasicAuthentication($options['username'], $options['password']);
×
78
        }
79

80
        if (array_key_exists('metadata', $options)) {
×
81
            $metadata = (bool) $options['metadata'];
×
82
        }
83

84
        $builder->setElasticMetaHeader($metadata);
×
85

86
        return $builder->build();
×
87
    }
88
}
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