ReadinessCheckerFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 23 6
1
<?php
2
/**
3
 * This file is part of codeception-phiremock-extension.
4
 *
5
 * phiremock-codeception-extension is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * phiremock-codeception-extension is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with phiremock-codeception-extension.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Codeception\Extension;
20
21
use Mcustiel\Phiremock\Client\Connection\Host;
0 ignored issues
show
Bug introduced by
The type Mcustiel\Phiremock\Client\Connection\Host was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Mcustiel\Phiremock\Client\Connection\Port;
0 ignored issues
show
Bug introduced by
The type Mcustiel\Phiremock\Client\Connection\Port was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Mcustiel\Phiremock\Client\Connection\Scheme;
0 ignored issues
show
Bug introduced by
The type Mcustiel\Phiremock\Client\Connection\Scheme was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Mcustiel\Phiremock\Client\Factory;
0 ignored issues
show
Bug introduced by
The type Mcustiel\Phiremock\Client\Factory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker\CurlChecker;
26
use Mcustiel\Phiremock\Codeception\Extension\ReadinessChecker\PhiremockClientChecker;
27
28
class ReadinessCheckerFactory
29
{
30
    public static function create(string $host, string $port, bool $isSecure): ReadinessCheckerInterface
31
    {
32
        if (class_exists(Factory::class)) {
33
            $phiremockClient = Factory::createDefault()
34
                ->createPhiremockClient(
35
                    new Host($host),
36
                    new Port($port),
37
                    $isSecure ? Scheme::createHttps() : Scheme::createHttp()
38
                );
39
40
            return new PhiremockClientChecker(
41
                $phiremockClient
42
            );
43
        } elseif (extension_loaded('curl')) {
44
            $url = 'http' . ($isSecure ? 's' : '')
45
                . '://' . $host
46
                . ($port !== '' ? ':' . $port : '');
47
48
            return new CurlChecker($url);
49
        }
50
51
        throw new \RuntimeException(
52
            'Config wait_until_ready is enabled but no readiness checker can be run. Check if you have Phiremock Client installed or curl extension enabled.'
53
        );
54
    }
55
}
56