|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rector\Tests\DeadCode\Rector\If_\RemoveOverriddenAssignBeforeIfElseRector\Fixture; |
| 4 | + |
| 5 | +final class OverrideInBothBranches |
| 6 | +{ |
| 7 | + public function run(string $state, array $present, int $id): array |
| 8 | + { |
| 9 | + $settings = []; |
| 10 | + if ($state === 'enabled') { |
| 11 | + $settings = $this->getDefaults(); |
| 12 | + foreach ($settings as $key => $value) { |
| 13 | + if (array_key_exists($key, $present)) { |
| 14 | + unset($settings[$key]); |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + $settings['enabled'] = 'yes'; |
| 19 | + } else { |
| 20 | + $settings = ['enabled' => 'no', 'id' => $id]; |
| 21 | + } |
| 22 | + |
| 23 | + return $settings; |
| 24 | + } |
| 25 | + |
| 26 | + private function getDefaults(): array |
| 27 | + { |
| 28 | + return []; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +?> |
| 33 | +----- |
| 34 | +<?php |
| 35 | + |
| 36 | +namespace Rector\Tests\DeadCode\Rector\If_\RemoveOverriddenAssignBeforeIfElseRector\Fixture; |
| 37 | + |
| 38 | +final class OverrideInBothBranches |
| 39 | +{ |
| 40 | + public function run(string $state, array $present, int $id): array |
| 41 | + { |
| 42 | + if ($state === 'enabled') { |
| 43 | + $settings = $this->getDefaults(); |
| 44 | + foreach ($settings as $key => $value) { |
| 45 | + if (array_key_exists($key, $present)) { |
| 46 | + unset($settings[$key]); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + $settings['enabled'] = 'yes'; |
| 51 | + } else { |
| 52 | + $settings = ['enabled' => 'no', 'id' => $id]; |
| 53 | + } |
| 54 | + |
| 55 | + return $settings; |
| 56 | + } |
| 57 | + |
| 58 | + private function getDefaults(): array |
| 59 | + { |
| 60 | + return []; |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +?> |
0 commit comments