Conditions | 1 |
Paths | 1 |
Total Lines | 106 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
12 | public function init() |
||
13 | { |
||
14 | parent::init(); |
||
15 | |||
16 | unset( |
||
17 | $this->paramsNames[static::ACTION_FIELD_FILE], |
||
18 | $this->paramsNames[static::ACTION_FIELD_PHRASE], |
||
19 | $this->paramsNames[static::ACTION_FIELD_REGSENSE], |
||
20 | $this->paramsNames[static::ACTION_FIELD_NUMERIC], |
||
21 | $this->paramsNames[static::ACTION_FIELD_MIN_LEN], |
||
22 | $this->paramsNames[static::ACTION_FIELD_MAX_LEN], |
||
23 | $this->paramsNames[static::ACTION_FIELD_LANGUAGE], |
||
24 | $this->paramsNames[static::ACTION_FIELD_LANG], |
||
25 | $this->paramsNames[static::ACTION_FIELD_QUESTION], |
||
26 | $this->paramsNames[static::ACTION_FIELD_INSTRUCTIONS], |
||
27 | $this->paramsNames[static::ACTION_FIELD_CALC], |
||
28 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_FILE], |
||
29 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_PHRASE], |
||
30 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_REGSENSE], |
||
31 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_NUMERIC], |
||
32 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_MIN_LEN], |
||
33 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_MAX_LEN], |
||
34 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_LANGUAGE], |
||
35 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_LANG], |
||
36 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_QUESTION], |
||
37 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_INSTRUCTIONS], |
||
38 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_CALC] |
||
39 | ); |
||
40 | |||
41 | $this->paramsNames[static::ACTION_FIELD_PAGEURL] = 'pageurl'; |
||
42 | $this->paramsNames[static::ACTION_FIELD_GT] = 'gt'; |
||
43 | $this->paramsNames[static::ACTION_FIELD_CHALLENGE] = 'challenge'; |
||
44 | $this->paramsNames[static::ACTION_FIELD_API_SERVER] = 'api_server'; |
||
45 | |||
46 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_METHOD][static::PARAM_SLUG_DEFAULT] = 'geetest'; |
||
47 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_PAGEURL] = [ |
||
48 | static::PARAM_SLUG_REQUIRE => true, |
||
49 | static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_STRING, |
||
50 | ]; |
||
51 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_GT] = [ |
||
52 | static::PARAM_SLUG_REQUIRE => true, |
||
53 | static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_STRING, |
||
54 | ]; |
||
55 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_CHALLENGE] = [ |
||
56 | static::PARAM_SLUG_REQUIRE => true, |
||
57 | static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_STRING, |
||
58 | ]; |
||
59 | $this->actions[static::ACTION_RECOGNIZE][static::ACTION_FIELDS][static::ACTION_FIELD_API_SERVER] = [ |
||
60 | static::PARAM_SLUG_REQUIRE => true, |
||
61 | static::PARAM_SLUG_TYPE => static::PARAM_FIELD_TYPE_STRING, |
||
62 | ]; |
||
63 | |||
64 | $this->wiki->setText(['service', 'name'], [ |
||
65 | 'ru' => 'RuCaptcha GeeTest', |
||
66 | 'en' => 'RuCaptcha GeeTest', |
||
67 | ]); |
||
68 | $this->wiki->setText(['recognize', 'price'], [ |
||
69 | 'ru' => '1000 решений стоят 39 рублей.', |
||
70 | 'en' => '1000 for $0,7', |
||
71 | ]); |
||
72 | $this->wiki->setText(['recognize', 'desc'], [ |
||
73 | 'ru' => '1) Найти следующие параметры на странице сайта с капчей (обычно их можно найти внутри функции initGeetest): |
||
74 | |||
75 | gt - публичный ключ сайта (статический) |
||
76 | challenge - динамический ключ задания |
||
77 | api_server - домен API (обязателен для некоторых сайтов) |
||
78 | |||
79 | 2) Отправьте запрос |
||
80 | |||
81 | 3) Используйте значения, полученные в ответе в запросе к сайту, передавая их в соотстветствующих полях запроса: |
||
82 | |||
83 | geetest_challenge |
||
84 | geetest_validate |
||
85 | geetest_seccode', |
||
86 | 'en' => '1) Find the following parameters on the site page with captcha (they can usually be found inside the initGeetest function): |
||
87 | |||
88 | gt - site public key (static) |
||
89 | challenge - dynamic task key |
||
90 | api_server - API domain (required for some sites) |
||
91 | |||
92 | 2) Submit a request |
||
93 | |||
94 | 3) Use the values received in the response in the request to the site, passing them in the corresponding request fields: |
||
95 | |||
96 | geetest_challenge |
||
97 | geetest_validate |
||
98 | geetest_seccode', |
||
99 | ]); |
||
100 | $this->wiki->setText(['recognize', 'data'], [ |
||
101 | static::ACTION_FIELD_PAGEURL => 'http://mysite.com/page/with/gettest/', |
||
102 | static::ACTION_FIELD_GT => 'f1ab2cdefa3456789012345b6c78d90e', |
||
103 | static::ACTION_FIELD_CHALLENGE => '12345678abc90123d45678ef90123a456b', |
||
104 | static::ACTION_FIELD_API_SERVER => 'api-na.geetest.com', |
||
105 | ]); |
||
106 | $this->wiki->setText(['recognize', 'file'], false); |
||
107 | $this->wiki->setText(['menu', 'from_service'], [ |
||
108 | RuCaptcha::class, |
||
109 | RuCaptchaClick::class, |
||
110 | RuCaptchaInstruction::class, |
||
111 | RuCaptchaGrid::class, |
||
112 | RuCaptchaReCaptcha::class, |
||
113 | RuCaptchaFunCaptcha::class, |
||
114 | RuCaptchaReCaptchaV3::class, |
||
115 | RuCaptchaKeyCaptcha::class, |
||
116 | ]); |
||
117 | } |
||
118 | |||
155 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.