| Conditions | 3 |
| Paths | 4 |
| Total Lines | 55 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 31 | #[Route( |
||
| 32 | '/gamercard/{id}/mini', |
||
| 33 | name: 'vgr_core_player_gamercard_mini', |
||
| 34 | methods: ['GET'], |
||
| 35 | requirements: ['id' => '[1-9]\d*'] |
||
| 36 | )] |
||
| 37 | #[Cache(public: true, maxage: 3600, mustRevalidate: true)] |
||
| 38 | public function __invoke(Player $player): void |
||
| 39 | { |
||
| 40 | chdir(__DIR__); |
||
| 41 | $gamercard = PictureCreatorFactory::fromFile('../../../Resources/img/gamercard/mini.png'); |
||
| 42 | |||
| 43 | // Ranking Points |
||
| 44 | $fontSize = 8; |
||
| 45 | $gamercard |
||
| 46 | ->addColor('lightBrown', 255, 218, 176) |
||
| 47 | ->addFont('segoeUISemiBold', '../../../Resources/fonts/seguisb.ttf') |
||
| 48 | ->write($this->numberFormat($player->getPointGame()) . ' Pts', $fontSize, 40, 20) |
||
| 49 | ->write('/', $fontSize, 124, 20) |
||
| 50 | ->addColor('darkYellow', 255, 191, 1) |
||
| 51 | ->write($player->getRankPointGame() . ' ' . $this->getOrdinalSuffix($player->getRankPointGame()), $fontSize, 130, 20); |
||
| 52 | |||
| 53 | |||
| 54 | // Ranking Medals |
||
| 55 | $sprite = PictureCreatorFactory::fromFile('../../../Resources/img/sprite.png'); |
||
| 56 | $gamercard |
||
| 57 | ->copyResized($sprite, 164, 8, 126, 160, 16, 16, 16, 16) |
||
| 58 | ->copyResized($sprite, 211, 8, 108, 160, 16, 16, 16, 16) |
||
| 59 | ->copyResized($sprite, 258, 8, 92, 160, 16, 16, 16, 16) |
||
| 60 | ->copyResized($sprite, 305, 8, 74, 160, 16, 16, 16, 16); |
||
| 61 | |||
| 62 | $gamercard->getColor('lightBrown'); |
||
| 63 | $gamercard |
||
| 64 | ->write($player->getChartRank0(), $fontSize, 180, 20) |
||
| 65 | ->write($player->getChartRank1(), $fontSize, 227, 20) |
||
| 66 | ->write($player->getChartRank2(), $fontSize, 274, 20) |
||
| 67 | ->write($player->getChartRank3(), $fontSize, 321, 20); |
||
| 68 | $gamercard->write('/', $fontSize, 350, 20); |
||
| 69 | $gamercard->getColor('darkYellow'); |
||
| 70 | $rank = $player->getRankMedal(); |
||
| 71 | if ($rank <= 99) { |
||
| 72 | $rank .= $this->getOrdinalSuffix($rank); |
||
| 73 | } |
||
| 74 | $gamercard->write($rank, $fontSize, 356, 20); |
||
| 75 | |||
| 76 | // Add avatar |
||
| 77 | $avatar = PictureCreatorFactory::fromStream($this->getAvatar($player)); |
||
| 78 | $gamercard->copyResized($avatar, 4, 2, 0, 0, 26, 26); |
||
| 79 | |||
| 80 | try { |
||
| 81 | $gamercard->downloadPicture('png', 'VGR-GamerCard-Mini-' . $player->getSlug() . '.png'); |
||
| 82 | } catch (Exception $e) { |
||
| 83 | exit; |
||
|
|
|||
| 84 | } |
||
| 85 | exit; |
||
| 86 | } |
||
| 127 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.