| Total Complexity | 10 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class PlayerTeamCollectionTransformer implements DataTransformerInterface |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param Team $value |
||
| 16 | * @return Team|null |
||
| 17 | */ |
||
| 18 | public function transform($value) |
||
| 19 | { |
||
| 20 | if ($value === null) { |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | // In want to have 16 players in the list, no less, no more |
||
| 25 | |||
| 26 | $usedNumbers = []; |
||
| 27 | |||
| 28 | foreach ($value->getPlayers() as $player) { |
||
| 29 | $usedNumbers[$player->getNumber()] = $player; |
||
| 30 | } |
||
| 31 | for ($i=1; $i<=16; $i++) { |
||
| 32 | if (!isset($usedNumbers[$i])) { |
||
| 33 | $value->addPlayer((new Player())->setNumber($i)); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | return $value; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param Team $value |
||
| 41 | * @return Team |
||
| 42 | */ |
||
| 43 | public function reverseTransform($value) |
||
| 55 | } |
||
| 56 | } |
||
| 57 |