| Conditions | 4 |
| Paths | 2 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | public static function createForMonitorConfig(array $monitorConfiguration, array $filter = []) |
||
| 15 | { |
||
| 16 | $monitors = collect($monitorConfiguration); |
||
| 17 | |||
| 18 | if (count($filter) && !empty($filter[0])) { |
||
| 19 | $monitors = $monitors->only($filter); |
||
| 20 | } |
||
| 21 | |||
| 22 | $configured_monitors = collect(); |
||
| 23 | |||
| 24 | $monitors->map(function($monitorConfigs, $monitorName) { |
||
| 25 | if (file_exists(__DIR__.'/'.ucfirst($monitorName).'Monitor.php')) { |
||
| 26 | $className = '\\EricMakesStuff\\ServerMonitor\\Monitors\\'.ucfirst($monitorName).'Monitor'; |
||
| 27 | return collect($monitorConfigs)->map(function($monitorConfig) use ($className) { |
||
| 28 | return new $className($monitorConfig); |
||
| 29 | }); |
||
| 30 | } |
||
| 31 | |||
| 32 | throw InvalidConfiguration::cannotFindMonitor($monitorName); |
||
| 33 | })->each(function($monitor_group) use ($configured_monitors) { |
||
| 34 | $monitor_group->each(function($monitor) use ($configured_monitors) { |
||
| 35 | $configured_monitors->push($monitor); |
||
| 36 | }); |
||
| 37 | }); |
||
| 38 | |||
| 39 | return $configured_monitors; |
||
| 40 | } |
||
| 41 | } |
||
| 42 |