Complex classes like FormTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FormTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | trait FormTrait |
||
13 | { |
||
14 | /** |
||
15 | * Insert content into all POST forms. |
||
16 | * |
||
17 | * @param ResponseInterface $response |
||
18 | * @param string $input |
||
19 | * |
||
20 | * @return ResponseInterface |
||
21 | */ |
||
22 | protected function insertIntoPostForms(ResponseInterface $response, $input) |
||
45 | |||
46 | /** |
||
47 | * Check whether the request is post (or any similar method). |
||
48 | * |
||
49 | * @param RequestInterface $request |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | protected function isPost(RequestInterface $request) |
||
66 | } |
||
67 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: