Completed
Push — master ( e1725f...dd3f0d )
by Владислав
07:40 queued 04:12
created

AnticaptchaReCaptchaProxeless::init()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
c 5
b 2
f 0
dl 0
loc 81
rs 8.8076
cc 1
eloc 49
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace jumper423\decaptcha\services;
4
5
/**
6
 * Class AnticaptchaReCaptchaProxeless.
7
 */
8
class AnticaptchaReCaptchaProxeless extends Anticaptcha
9
{
10
    public function init()
11
    {
12
        parent::init();
13
14
        unset(
15
            $this->paramsNames[static::ACTION_FIELD_FILE],
16
            $this->paramsNames[static::ACTION_FIELD_PHRASE],
17
            $this->paramsNames[static::ACTION_FIELD_PINGBACK],
18
            $this->paramsNames[static::ACTION_FIELD_REGSENSE],
19
            $this->paramsNames[static::ACTION_FIELD_NUMERIC],
20
            $this->paramsNames[static::ACTION_FIELD_CALC],
21
            $this->paramsNames[static::ACTION_FIELD_MIN_LEN],
22
            $this->paramsNames[static::ACTION_FIELD_MAX_LEN],
23
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_FILE],
24
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_PHRASE],
25
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_PINGBACK],
26
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_REGSENSE],
27
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_NUMERIC],
28
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_CALC],
29
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_MIN_LEN],
30
            $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS][self::ACTION_FIELD_MAX_LEN]
31
        );
32
33
        $this->paramsNames[static::ACTION_FIELD_PAGEURL] = 'websiteURL';
34
        $this->paramsNames[static::ACTION_FIELD_GOOGLEKEY] = 'websiteKey';
35
        $this->paramsNames[static::ACTION_FIELD_GOOGLETOKEN] = 'websiteSToken';
36
37
        $task = &$this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_TASK][static::ACTION_FIELDS];
38
        $task[static::ACTION_FIELD_METHOD][static::PARAM_SLUG_DEFAULT] = 'NoCaptchaTask';
39
        $task[static::ACTION_FIELD_PAGEURL] = [
40
            static::PARAM_SLUG_REQUIRE => true,
41
            static::PARAM_SLUG_TYPE    => static::PARAM_FIELD_TYPE_STRING,
42
        ];
43
        $task[static::ACTION_FIELD_GOOGLEKEY] = [
44
            static::PARAM_SLUG_REQUIRE => true,
45
            static::PARAM_SLUG_TYPE    => static::PARAM_FIELD_TYPE_STRING,
46
        ];
47
        $task[static::ACTION_FIELD_GOOGLETOKEN] = [
48
            static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_STRING,
49
        ];
50
51
        $this->decodeSettings[static::DECODE_ACTION][static::DECODE_ACTION_GET][static::DECODE_PARAMS][static::DECODE_PARAM_CODE][static::DECODE_PARAM_SETTING_MARKER] = 'solution.gRecaptchaResponse';
52
53
        $this->wiki->setText(['service', 'name'], [
54
            'ru' => 'AntiCaptcha ReCaptcha v2 без браузера',
55
            'en' => 'AntiCaptcha ReCaptcha v2 without a browser',
56
        ]);
57
        $this->wiki->setText(['recognize', 'price'], [
58
            'ru' => 'Стоимость Рекапчи: от 2 USD за 1000 решений.',
59
            'en' => 'The cost Recaptcha: 2 USD per 1000 solutions.',
60
        ]);
61
        $this->wiki->setText(['recognize', 'desc'], [
62
            'ru' => 'Вам не нужно эмулировать браузер и запускать яваскрипты.
63
            
64
Вы присылаете нам значение "sitekey".
65
66
Мы передаем вам "g-recaptcha-response" и вы просто делаете сабмит формы с этим параметром.
67
68
Объект содержит данные о задаче на решение рекапчи гугла в браузере на компьютере работника. 
69
Такая задача будет выполняться нашим сервисом с использованием наших собственных прокси-серверов и/или с IP адресов работников. 
70
Стоимость решения такой задачи на 10% выше, чем у AnticaptchaReCaptcha, так как на нас ложится проблема обхода лимитов на количество решений рекапч с 1 IP адреса.',
71
            'en' => 'You do not need to emulate a browser and run JavaScript.
72
            
73
You send us the meaning of "sitekey".
74
75
We give you the "g-recaptcha-response" and you just do Submitting the form with this parameter.
76
77
The object contains information about the problem to solve Google\'s reCAPTCHA in the browser on the employee\'s computer.
78
This task will be performed by our service using our own proxy servers and / or IP addresses of employees.
79
The cost of solving this problem is 10% higher than the AnticaptchaReCaptcha, as it falls on us to circumvent the problem of limits on the number of reCAPTCHA solutions with 1 IP address.',
80
        ]);
81
        $this->wiki->setText(['recognize', 'data'], [
82
            static::ACTION_FIELD_GOOGLEKEY => '54as5c6a5s4ca4s56a4sc56a',
83
            static::ACTION_FIELD_PAGEURL   => 'http://site.com/recaptcha-ex',
84
        ]);
85
        $this->wiki->setText(['recognize', 'file'], false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
86
        $this->wiki->setText(['menu', 'from_service'], [
87
            Anticaptcha::class,
88
            AnticaptchaReCaptcha::class,
89
        ]);
90
    }
91
92
    public function recognize($additionally = [], $null = null)
93
    {
94
        return parent::recognize(null, $additionally);
95
    }
96
}
97