Conditions | 4 |
Paths | 8 |
Total Lines | 65 |
Code Lines | 41 |
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 |
||
51 | public function behaviors() |
||
52 | { |
||
53 | $behaviors = parent::behaviors(); |
||
54 | |||
55 | $authenticator = false; |
||
56 | |||
57 | if (isset($behaviors['authenticator'])) { |
||
58 | $authenticator = $behaviors['authenticator']; |
||
59 | unset($behaviors['authenticator']); |
||
60 | } |
||
61 | |||
62 | $behaviors['contentNegotiator'] = [ |
||
63 | 'class' => ContentNegotiator::class, |
||
64 | 'formats' => [ |
||
65 | 'application/json' => Response::FORMAT_JSON, |
||
66 | 'application/vnd.25519+json' => Response::FORMAT_JSON25519, |
||
67 | 'application/vnd.ncryptf+json' => Response::FORMAT_NCRYPTF_JSON, |
||
68 | 'application/xml' => Response::FORMAT_XML, |
||
69 | ] |
||
70 | ]; |
||
71 | |||
72 | $behaviors['corsFilter'] = [ |
||
73 | 'class' => Cors::class, |
||
74 | 'cors' => [ |
||
75 | 'Origin' => ['*'], |
||
76 | 'Access-Control-Request-Method' => $this->getHttpVerbMethodsFromClass($this->actions()[$this->action->id]), |
||
77 | 'Access-Control-Request-Headers' => ['*'], |
||
78 | 'Access-Control-Expose-Headers' => [ |
||
79 | 'Access-Control-Allow-Origin', |
||
80 | 'X-Pagination-Per-Page', |
||
81 | 'X-Pagination-Total-Count', |
||
82 | 'X-Pagination-Current-Page', |
||
83 | 'X-Pagination-Page-Count', |
||
84 | 'Allow', |
||
85 | 'X-Rate-Limit-Limit', |
||
86 | 'X-Rate-Limit-Remaining', |
||
87 | 'X-Rate-Limit-Reset' |
||
88 | ], |
||
89 | ] |
||
90 | ]; |
||
91 | |||
92 | $behaviors['verbs'] = [ |
||
93 | 'class' => VerbFilter::class, |
||
94 | 'actions' => $this->getVerbFilterActionMap() |
||
95 | ]; |
||
96 | |||
97 | // Move authenticator after verbs and cors |
||
98 | if ($authenticator != false) { |
||
99 | $behaviors['authenticator'] = $authenticator; |
||
100 | } |
||
101 | |||
102 | $behaviors['rateLimiter'] = [ |
||
103 | 'class' => RateLimiter::class, |
||
104 | 'enableRateLimitHeaders' => true |
||
105 | ]; |
||
106 | |||
107 | $access = $this->getAccessControl(); |
||
108 | |||
109 | if ($access !== null) { |
||
110 | $behaviors['access'] = $access; |
||
111 | } |
||
112 | |||
113 | // Manually add the ACAO header because Yii2 is terrible at doing it |
||
114 | header("Access-Control-Allow-Origin: " . \implode(',', $behaviors['corsFilter']['cors']['Origin'])); |
||
115 | return $behaviors; |
||
116 | } |
||
208 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.