Conditions | 12 |
Total Lines | 61 |
Code Lines | 58 |
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:
Complex classes like GamePage.render 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.
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.
1 | import React, { Component } from "react" |
||
43 | |||
44 | render() { |
||
45 | if (this.state.loading === false && this.state.data) { |
||
46 | const { general, substitutes, lineup, events } = this.state.data |
||
47 | const homeTeamId = general.homeClub.id |
||
48 | const awayTeamId = general.awayClub.id |
||
49 | const ogImage = { |
||
50 | src: general?.homeClub.logo, |
||
51 | width: 180, |
||
52 | height: 180, |
||
53 | } |
||
54 | |||
55 | return ( |
||
56 | <Layout> |
||
57 | <SEO |
||
58 | lang="nl-BE" |
||
59 | title={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
60 | description={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
61 | path={`/game/${general?.id}`} |
||
62 | image={ogImage} |
||
63 | /> |
||
64 | <section className="grid-container site-content"> |
||
65 | <div className="grid-x grid-margin-x"> |
||
66 | <div className={"cell large-12 center"}> |
||
67 | {general.date} |
||
68 | <br /> |
||
69 | {general.status} |
||
70 | <br /> |
||
71 | {general.homeClub.name} |
||
72 | <img src={general.homeClub.logo} alt={general.homeClub.name} /> |
||
73 | {general.goalsHomeTeam} - {general.goalsAwayTeam} |
||
74 | {general.awayClub.name} |
||
75 | <img src={general.awayClub.logo} alt={general.awayClub.name} /> |
||
76 | <br /> |
||
77 | {general.competitionType} |
||
78 | </div> |
||
79 | |||
80 | <div className={"cell large-6"}> |
||
81 | <strong>{general.homeClub.name}</strong> |
||
82 | {this.renderLineup(lineup.home, substitutes.home)} |
||
83 | </div> |
||
84 | <div className={"cell large-6"}> |
||
85 | <strong>{general.awayClub.name}</strong> |
||
86 | {this.renderLineup(lineup.away, substitutes.away)} |
||
87 | </div> |
||
88 | |||
89 | <div className={"cell large-12"}> |
||
90 | <strong>Events</strong> |
||
91 | {this.renderEvents(events, homeTeamId)} |
||
92 | </div> |
||
93 | </div> |
||
94 | </section> |
||
95 | </Layout> |
||
96 | ) |
||
97 | } else { |
||
98 | return ( |
||
99 | <Layout> |
||
100 | <section className="grid-container site-content"> |
||
101 | Matchverslag inladen... |
||
102 | </section> |
||
103 | </Layout> |
||
104 | ) |
||
233 |