| Total Complexity | 6 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Factory |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $instances = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Add a provider instance |
||
| 23 | * |
||
| 24 | * @param \App\Provider\ProviderInterface |
||
| 25 | * @author Ronan Chilvers <[email protected]> |
||
| 26 | */ |
||
| 27 | public function addProvider(ProviderInterface $instance) |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Get a suitable instance for a given project |
||
| 34 | * |
||
| 35 | * @param \App\Model\Project $project |
||
| 36 | * @return \App\Provider\ProviderInterface |
||
| 37 | * @throws RuntimeException If a suitable provider is not found |
||
| 38 | * @author Ronan Chilvers <[email protected]> |
||
| 39 | */ |
||
| 40 | public function forProject(Project $project) |
||
| 41 | { |
||
| 42 | foreach ($this->instances as $instance) { |
||
| 43 | if ($instance->handles($project)) { |
||
| 44 | return $instance; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | throw new RuntimeException('No suitable instance found for project provider ' . $project->provider); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get the project provider options as an array |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | * @author Ronan Chilvers <[email protected]> |
||
| 56 | */ |
||
| 57 | public function getOptions() |
||
| 66 | } |
||
| 67 | } |
||
| 68 |