Test Failed
Pull Request — master (#28)
by
unknown
02:40
created

getServiceOrRef()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
6
use Karser\Recaptcha3Bundle\Services\IpResolver;
7
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3Validator;
8
use ReCaptcha\ReCaptcha;
9
use ReCaptcha\RequestMethod\Curl;
10
use ReCaptcha\RequestMethod\CurlPost;
11
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
12
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
13
14
return static function (ContainerConfigurator $containerConfigurator): void {
15
    $services = $containerConfigurator->services();
16
17
    $services->set('karser_recaptcha3.form.type', Recaptcha3Type::class)
18
        ->private()
19
        ->args(['%karser_recaptcha3.site_key%', '%karser_recaptcha3.enabled%'])
20
        ->tag('form.type', []);
21
22
    $services->set('karser_recaptcha3.validator', Recaptcha3Validator::class)
23
        ->private()
24
        ->args([getServiceOrRef('karser_recaptcha3.google.recaptcha'), '%karser_recaptcha3.enabled%', getServiceOrRef('karser_recaptcha3.ip_resolver')])
25
        ->tag('validator.constraint_validator', ['alias' => 'karser_recaptcha3_validator']);
26
27
    $services->set('karser_recaptcha3.ip_resolver', IpResolver::class)
28
        ->private()
29
        ->args([getServiceOrRef('request_stack')]);
30
31
    $services->set('karser_recaptcha3.google.recaptcha', ReCaptcha::class)
32
        ->arg('$secret', '%karser_recaptcha3.secret_key%')
33
        ->arg('$requestMethod', getServiceOrRef('karser_recaptcha3.google.request_method'))
34
        ->call('setScoreThreshold', ['%karser_recaptcha3.score_threshold%']);
35
36
    $services->alias('karser_recaptcha3.google.request_method', 'karser_recaptcha3.google.request_method.curl_post');
37
38
    $services->set('karser_recaptcha3.google.request_method.curl_post', CurlPost::class);
39
40
    $services->set('karser_recaptcha3.google.request_method.curl', Curl::class);
41
};
42
43
function getServiceOrRef (string $id): ReferenceConfigurator {
44
    if (function_exists('\Symfony\Component\DependencyInjection\Loader\Configurator\service')) {
45
        // >= sf 5.1 forward compatibility
46
        return \Symfony\Component\DependencyInjection\Loader\Configurator\service($id);
0 ignored issues
show
Bug introduced by
The function service was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        return /** @scrutinizer ignore-call */ \Symfony\Component\DependencyInjection\Loader\Configurator\service($id);
Loading history...
47
    }
48
    return \Symfony\Component\DependencyInjection\Loader\Configurator\ref($id);
49
}
50