| Total Complexity | 42 |
| Total Lines | 312 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Country 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.
While breaking up the class, it is a good idea to analyze how other classes use Country, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | #[ApiResource( |
||
| 23 | operations: [new Get(security: 'is_granted(\'ROLE_CLIENT\')')], |
||
| 24 | formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']], |
||
| 25 | normalizationContext: ['groups' => ['country:read']], |
||
| 26 | denormalizationContext: ['groups' => ['country:write']] |
||
| 27 | )] |
||
| 28 | #[Table(name: 'country')] |
||
| 29 | #[UniqueConstraint(name: 'countryCode', columns: ['countryCode'])] |
||
| 30 | #[EntityListeners([LogListener::class])] |
||
| 31 | #[Entity(repositoryClass: CountryRepository::class)] |
||
| 32 | class Country |
||
| 33 | { |
||
| 34 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 35 | #[Column(name: 'id', type: 'integer', nullable: false)] |
||
| 36 | #[Id] |
||
| 37 | #[GeneratedValue(strategy: 'IDENTITY')] |
||
| 38 | private int $id = 0; |
||
| 39 | |||
| 40 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 41 | #[Column(name: 'countryCode', type: 'string', length: 3, nullable: false)] |
||
| 42 | private string $countrycode; |
||
| 43 | |||
| 44 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 45 | #[Column(name: 'countryName', type: 'string', length: 45, nullable: false)] |
||
| 46 | private string $countryname; |
||
| 47 | |||
| 48 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 49 | #[Column(name: 'currencyCode', type: 'string', length: 3, nullable: true)] |
||
| 50 | private ?string $currencycode = null; |
||
| 51 | |||
| 52 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 53 | #[Column(name: 'population', type: 'integer', nullable: true)] |
||
| 54 | private ?int $population = null; |
||
| 55 | |||
| 56 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 57 | #[Column(name: 'fipsCode', type: 'string', length: 2, nullable: true)] |
||
| 58 | private ?string $fipscode = null; |
||
| 59 | |||
| 60 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 61 | #[Column(name: 'isoNumeric', type: 'string', length: 4, nullable: true)] |
||
| 62 | private ?string $isonumeric = null; |
||
| 63 | |||
| 64 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 65 | #[Column(name: 'north', type: 'string', length: 30, nullable: true)] |
||
| 66 | private ?string $north = null; |
||
| 67 | |||
| 68 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 69 | #[Column(name: 'south', type: 'string', length: 30, nullable: true)] |
||
| 70 | private ?string $south = null; |
||
| 71 | |||
| 72 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 73 | #[Column(name: 'east', type: 'string', length: 30, nullable: true)] |
||
| 74 | private ?string $east = null; |
||
| 75 | |||
| 76 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 77 | #[Column(name: 'west', type: 'string', length: 30, nullable: true)] |
||
| 78 | private ?string $west = null; |
||
| 79 | |||
| 80 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 81 | #[Column(name: 'capital', type: 'string', length: 30, nullable: true)] |
||
| 82 | private ?string $capital = null; |
||
| 83 | |||
| 84 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 85 | #[Column(name: 'continentName', type: 'string', length: 15, nullable: true)] |
||
| 86 | private ?string $continentname = null; |
||
| 87 | |||
| 88 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 89 | #[Column(name: 'continent', type: 'string', length: 2, nullable: true)] |
||
| 90 | private ?string $continent = null; |
||
| 91 | |||
| 92 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 93 | #[Column(name: 'areaInSqKm', type: 'string', length: 20, nullable: true)] |
||
| 94 | private ?string $areainsqkm = null; |
||
| 95 | |||
| 96 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 97 | #[Column(name: 'isoAlpha3', type: 'string', length: 3, nullable: true)] |
||
| 98 | private ?string $isoalpha3 = null; |
||
| 99 | |||
| 100 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 101 | #[Column(name: 'geonameId', type: 'integer', nullable: true)] |
||
| 102 | private ?int $geonameid = null; |
||
| 103 | |||
| 104 | #[Groups(['city:read', 'logistic:read', 'state:read', 'people:read', 'order_details:read', 'order:write', 'address:read'])] |
||
| 105 | #[OneToMany(targetEntity: LanguageCountry::class, mappedBy: 'country')] |
||
| 106 | private Collection $languageCountry; |
||
| 107 | |||
| 108 | #[OneToMany(targetEntity: State::class, mappedBy: 'country')] |
||
| 109 | private Collection $state; |
||
| 110 | |||
| 111 | public function __construct() |
||
| 112 | { |
||
| 113 | $this->languageCountry = new ArrayCollection(); |
||
| 114 | $this->state = new ArrayCollection(); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getId(): int |
||
| 118 | { |
||
| 119 | return $this->id; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function setCountrycode(string $countrycode): self |
||
| 123 | { |
||
| 124 | $this->countrycode = $countrycode; |
||
| 125 | return $this; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getCountrycode(): string |
||
| 129 | { |
||
| 130 | return $this->countrycode; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function setCountryname(string $countryname): self |
||
| 134 | { |
||
| 135 | $this->countryname = $countryname; |
||
| 136 | return $this; |
||
| 137 | } |
||
| 138 | |||
| 139 | public function getCountryname(): string |
||
| 140 | { |
||
| 141 | return $this->countryname; |
||
| 142 | } |
||
| 143 | |||
| 144 | public function setCurrencycode(?string $currencycode): self |
||
| 145 | { |
||
| 146 | $this->currencycode = $currencycode; |
||
| 147 | return $this; |
||
| 148 | } |
||
| 149 | |||
| 150 | public function getCurrencycode(): ?string |
||
| 151 | { |
||
| 152 | return $this->currencycode; |
||
| 153 | } |
||
| 154 | |||
| 155 | public function setPopulation(?int $population): self |
||
| 156 | { |
||
| 157 | $this->population = $population; |
||
| 158 | return $this; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getPopulation(): ?int |
||
| 162 | { |
||
| 163 | return $this->population; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function setFipscode(?string $fipscode): self |
||
| 167 | { |
||
| 168 | $this->fipscode = $fipscode; |
||
| 169 | return $this; |
||
| 170 | } |
||
| 171 | |||
| 172 | public function getFipscode(): ?string |
||
| 173 | { |
||
| 174 | return $this->fipscode; |
||
| 175 | } |
||
| 176 | |||
| 177 | public function setIsonumeric(?string $isonumeric): self |
||
| 178 | { |
||
| 179 | $this->isonumeric = $isonumeric; |
||
| 180 | return $this; |
||
| 181 | } |
||
| 182 | |||
| 183 | public function getIsonumeric(): ?string |
||
| 184 | { |
||
| 185 | return $this->isonumeric; |
||
| 186 | } |
||
| 187 | |||
| 188 | public function setNorth(?string $north): self |
||
| 189 | { |
||
| 190 | $this->north = $north; |
||
| 191 | return $this; |
||
| 192 | } |
||
| 193 | |||
| 194 | public function getNorth(): ?string |
||
| 195 | { |
||
| 196 | return $this->north; |
||
| 197 | } |
||
| 198 | |||
| 199 | public function setSouth(?string $south): self |
||
| 200 | { |
||
| 201 | $this->south = $south; |
||
| 202 | return $this; |
||
| 203 | } |
||
| 204 | |||
| 205 | public function getSouth(): ?string |
||
| 206 | { |
||
| 207 | return $this->south; |
||
| 208 | } |
||
| 209 | |||
| 210 | public function setEast(?string $east): self |
||
| 211 | { |
||
| 212 | $this->east = $east; |
||
| 213 | return $this; |
||
| 214 | } |
||
| 215 | |||
| 216 | public function getEast(): ?string |
||
| 217 | { |
||
| 218 | return $this->east; |
||
| 219 | } |
||
| 220 | |||
| 221 | public function setWest(?string $west): self |
||
| 222 | { |
||
| 223 | $this->west = $west; |
||
| 224 | return $this; |
||
| 225 | } |
||
| 226 | |||
| 227 | public function getWest(): ?string |
||
| 228 | { |
||
| 229 | return $this->west; |
||
| 230 | } |
||
| 231 | |||
| 232 | public function setCapital(?string $capital): self |
||
| 233 | { |
||
| 234 | $this->capital = $capital; |
||
| 235 | return $this; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function getCapital(): ?string |
||
| 239 | { |
||
| 240 | return $this->capital; |
||
| 241 | } |
||
| 242 | |||
| 243 | public function setContinentname(?string $continentname): self |
||
| 244 | { |
||
| 245 | $this->continentname = $continentname; |
||
| 246 | return $this; |
||
| 247 | } |
||
| 248 | |||
| 249 | public function getContinentname(): ?string |
||
| 250 | { |
||
| 251 | return $this->continentname; |
||
| 252 | } |
||
| 253 | |||
| 254 | public function setContinent(?string $continent): self |
||
| 255 | { |
||
| 256 | $this->continent = $continent; |
||
| 257 | return $this; |
||
| 258 | } |
||
| 259 | |||
| 260 | public function getContinent(): ?string |
||
| 261 | { |
||
| 262 | return $this->continent; |
||
| 263 | } |
||
| 264 | |||
| 265 | public function setAreainsqkm(?string $areainsqkm): self |
||
| 266 | { |
||
| 267 | $this->areainsqkm = $areainsqkm; |
||
| 268 | return $this; |
||
| 269 | } |
||
| 270 | |||
| 271 | public function getAreainsqkm(): ?string |
||
| 272 | { |
||
| 273 | return $this->areainsqkm; |
||
| 274 | } |
||
| 275 | |||
| 276 | public function setIsoalpha3(?string $isoalpha3): self |
||
| 277 | { |
||
| 278 | $this->isoalpha3 = $isoalpha3; |
||
| 279 | return $this; |
||
| 280 | } |
||
| 281 | |||
| 282 | public function getIsoalpha3(): ?string |
||
| 283 | { |
||
| 284 | return $this->isoalpha3; |
||
| 285 | } |
||
| 286 | |||
| 287 | public function setGeonameid(?int $geonameid): self |
||
| 288 | { |
||
| 289 | $this->geonameid = $geonameid; |
||
| 290 | return $this; |
||
| 291 | } |
||
| 292 | |||
| 293 | public function getGeonameid(): ?int |
||
| 294 | { |
||
| 295 | return $this->geonameid; |
||
| 296 | } |
||
| 297 | |||
| 298 | public function addLanguageCountry(LanguageCountry $languageCountry): self |
||
| 299 | { |
||
| 300 | if (!$this->languageCountry->contains($languageCountry)) { |
||
| 301 | $this->languageCountry[] = $languageCountry; |
||
| 302 | } |
||
| 303 | return $this; |
||
| 304 | } |
||
| 305 | |||
| 306 | public function removeLanguageCountry(LanguageCountry $languageCountry): self |
||
| 307 | { |
||
| 308 | $this->languageCountry->removeElement($languageCountry); |
||
| 309 | return $this; |
||
| 310 | } |
||
| 311 | |||
| 312 | public function getLanguageCountry(): Collection |
||
| 313 | { |
||
| 314 | return $this->languageCountry; |
||
| 315 | } |
||
| 316 | |||
| 317 | public function addState(State $state): self |
||
| 318 | { |
||
| 319 | if (!$this->state->contains($state)) { |
||
| 320 | $this->state[] = $state; |
||
| 321 | } |
||
| 322 | return $this; |
||
| 323 | } |
||
| 324 | |||
| 325 | public function removeState(State $state): self |
||
| 326 | { |
||
| 327 | $this->state->removeElement($state); |
||
| 328 | return $this; |
||
| 329 | } |
||
| 330 | |||
| 331 | public function getState(): Collection |
||
| 334 | } |
||
| 335 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths