bankiru /
doctrine-api-client
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bankiru\Api\Doctrine\ApiFactory; |
||
| 4 | |||
| 5 | use Bankiru\Api\Doctrine\ApiFactoryInterface; |
||
| 6 | use Bankiru\Api\Doctrine\ApiFactoryRegistryInterface; |
||
| 7 | use Bankiru\Api\Doctrine\Exception\MappingException; |
||
| 8 | use Bankiru\Api\Doctrine\Mapping\ApiMetadata; |
||
| 9 | use ScayTrase\Api\Rpc\RpcClientInterface; |
||
| 10 | |||
| 11 | final class ApiFactoryRegistryFactory implements ApiFactoryRegistryInterface |
||
| 12 | { |
||
| 13 | /** @var ApiFactoryInterface[] */ |
||
| 14 | private $factories = []; |
||
| 15 | |||
| 16 | /** {@inheritdoc} */ |
||
| 17 | View Code Duplication | public function create($alias, RpcClientInterface $client, ApiMetadata $metadata) |
|
|
0 ignored issues
–
show
|
|||
| 18 | { |
||
| 19 | if (!$this->has($alias)) { |
||
| 20 | throw MappingException::unknownApiFactory($alias); |
||
| 21 | } |
||
| 22 | |||
| 23 | return $this->factories[$alias]->createApi($client, $metadata); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** {@inheritdoc} */ |
||
| 27 | 19 | public function has($alias) |
|
| 28 | { |
||
| 29 | 19 | return array_key_exists($alias, $this->factories); |
|
| 30 | } |
||
| 31 | |||
| 32 | /** {@inheritdoc} */ |
||
| 33 | public function set($alias, ApiFactoryInterface $factory) |
||
| 34 | { |
||
| 35 | $this->factories[$alias] = $factory; |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.