Complex classes like NavigationContext 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 NavigationContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class NavigationContext extends AbstractContext |
||
41 | { |
||
42 | /** |
||
43 | * @var DefaultPage |
||
44 | */ |
||
45 | private $defaultPage; |
||
46 | |||
47 | /** |
||
48 | * @var AdminPanel |
||
49 | */ |
||
50 | private $adminPanelPage; |
||
51 | |||
52 | /** |
||
53 | * @var CustomNewsEdit |
||
54 | */ |
||
55 | private $customNewsEditPage; |
||
56 | |||
57 | /** |
||
58 | * @var CustomNewsList |
||
59 | */ |
||
60 | private $customNewsListPage; |
||
61 | |||
62 | /** |
||
63 | * @var CustomSubscribersList |
||
64 | */ |
||
65 | private $customSubscribersListPage; |
||
66 | |||
67 | /** |
||
68 | * @var DTOForm |
||
69 | */ |
||
70 | private $dtoFormPage; |
||
71 | |||
72 | /** |
||
73 | * @var HomePageEdit |
||
74 | */ |
||
75 | private $homePageEditPage; |
||
76 | |||
77 | /** |
||
78 | * @var NewsCreate |
||
79 | */ |
||
80 | private $newsCreatePage; |
||
81 | |||
82 | /** |
||
83 | * @var NewsDisplay |
||
84 | */ |
||
85 | private $newsDisplayPage; |
||
86 | |||
87 | /** |
||
88 | * @var NewsEdit |
||
89 | */ |
||
90 | private $newsEditPage; |
||
91 | |||
92 | /** |
||
93 | * @var CategoryList |
||
94 | */ |
||
95 | private $categoryListPage; |
||
96 | |||
97 | /** |
||
98 | * @var CategoryNewsList |
||
99 | */ |
||
100 | private $categoryNewsListPage; |
||
101 | |||
102 | /** |
||
103 | * @var CategoryNewsCreate |
||
104 | */ |
||
105 | private $categoryNewsCreatePage; |
||
106 | |||
107 | /** |
||
108 | * @var CategoryNewsEdit |
||
109 | */ |
||
110 | private $categoryNewsEditPage; |
||
111 | |||
112 | /** |
||
113 | * @va NewsList |
||
114 | */ |
||
115 | private $newsListPage; |
||
116 | |||
117 | /** |
||
118 | * @var PersonAddForm |
||
119 | */ |
||
120 | private $personAddFormPage; |
||
121 | |||
122 | /** |
||
123 | * @var PersonEditForm |
||
124 | */ |
||
125 | private $personEditFormPage; |
||
126 | |||
127 | /** |
||
128 | * @var PersonList |
||
129 | */ |
||
130 | private $personListPage; |
||
131 | |||
132 | /** |
||
133 | * @var SubscriberEdit |
||
134 | */ |
||
135 | private $subscriberEditPage; |
||
136 | |||
137 | /** |
||
138 | * @var SubscriberForm |
||
139 | */ |
||
140 | private $subscriberFormPage; |
||
141 | |||
142 | /** |
||
143 | * @var SubscribersList |
||
144 | */ |
||
145 | private $subscribersListPage; |
||
146 | |||
147 | public function __construct( |
||
192 | |||
193 | /** |
||
194 | * @transform :page |
||
195 | */ |
||
196 | public function transformToPageObject($pageName) |
||
245 | |||
246 | /** |
||
247 | * @When /^I follow "([^"]*)" url from top bar$/ |
||
248 | * @Given /^I follow "([^"]*)" menu element$/ |
||
249 | */ |
||
250 | public function iFollowUrlFromTopBar($menuElement) |
||
254 | |||
255 | /** |
||
256 | * @Then /^menu with following elements should be visible at the top of the page$/ |
||
257 | */ |
||
258 | public function menuWithFollowingElementsShouldBeVisibleAtTheTopOfThePage(TableNode $table) |
||
269 | |||
270 | /** |
||
271 | * @Then :link link in the top bar should be highlighted |
||
272 | */ |
||
273 | public function linkInTheTopBarShouldBeHighlighted($link) |
||
279 | |||
280 | /** |
||
281 | * @Given I am on the :page page |
||
282 | */ |
||
283 | public function iAmOnThePage(Page $page) |
||
287 | |||
288 | /** |
||
289 | * @Given I am on the :page page with id :id |
||
290 | */ |
||
291 | public function iAmOnThePageWithId(Page $page, $id) |
||
295 | |||
296 | /** |
||
297 | * @Given I should be on the :page page |
||
298 | * @Given I should be redirected to :page page |
||
299 | */ |
||
300 | public function iShouldBeOnThePage(Page $page) |
||
304 | |||
305 | /** |
||
306 | * @Given I try to open the :page page |
||
307 | */ |
||
308 | public function iTryToOpenPage(Page $page) |
||
312 | |||
313 | /** |
||
314 | * @Given /^I press "New element" link$/ |
||
315 | */ |
||
316 | public function iPressNewElementLink() |
||
320 | |||
321 | /** |
||
322 | * @When /^I press "([^"]*)" button at pagination$/ |
||
323 | */ |
||
324 | public function iPressButtonAtPagination($button) |
||
328 | |||
329 | /** |
||
330 | * @Then /^I should see pagination with following buttons$/ |
||
331 | */ |
||
332 | public function iShouldSeePaginationWithFollowingButtons(TableNode $table) |
||
352 | |||
353 | /** |
||
354 | * @Then page :page should display OK status |
||
355 | */ |
||
356 | public function pageShouldDisplayOKStatus(Page $page) |
||
360 | |||
361 | /** |
||
362 | * @Then page :page should display not found exception |
||
363 | */ |
||
364 | public function pageShouldDisplayNotFoundException(Page $page) |
||
368 | |||
369 | /** |
||
370 | * @Then page :page should throw an error exception |
||
371 | */ |
||
372 | public function pageShouldThrowAnErrorExceptionException(Page $page) |
||
376 | |||
377 | private function expectPageStatus(Page $page, int $expectedStatus): void |
||
388 | } |
||
389 |