Lines
100.00%
26 / 26
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProviderHandler | 100.00% | 26 / 26 | 100.00% | 4 / 4 | 6 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| readProviderList | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| readProviderAssigned | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | |||||
| readProviderNotAssigned | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | * | |
| 7 | */ | |
| 8 | ||
| 9 | namespace BO\Zmsadmin\Helper; | |
| 10 | ||
| 11 | use BO\Zmsadmin\BaseController; | |
| 12 | use BO\Zmsentities\Collection\ProviderList; | |
| 13 | use Psr\Http\Message\RequestInterface; | |
| 14 | use Psr\Http\Message\ResponseInterface; | |
| 15 | ||
| 16 | class ProviderHandler extends BaseController | |
| 17 | { | |
| 18 | /** | |
| 19 | * @SuppressWarnings(UnusedFormalParameter) | |
| 20 | * @return ResponseInterface | |
| 21 | */ | |
| 22 | #[\Override] | |
| 23 | public function readResponse( | |
| 24 | RequestInterface $request, | |
| 25 | ResponseInterface $response, | |
| 26 | array $args | |
| 27 | ): ResponseInterface { | |
| 28 | return \BO\Slim\Render::withJson( | |
| 29 | $response, | |
| 30 | static::readProviderList($args['source']) | |
| 31 | ); | |
| 32 | } | |
| 33 | ||
| 34 | /** | |
| 35 | * @return (mixed|string)[][] | |
| 36 | * | |
| 37 | */ | |
| 38 | public static function readProviderList($source): array | |
| 39 | { | |
| 40 | return [ | |
| 41 | ['name' => 'assigned', 'items' => static::readProviderAssigned($source)], | |
| 42 | ['name' => 'notAssigned', 'items' => static::readProviderNotAssigned($source)] | |
| 43 | ]; | |
| 44 | } | |
| 45 | ||
| 46 | protected static function readProviderAssigned($source) | |
| 47 | { | |
| 48 | $providerAssigned = \App::$http->readGetResult( | |
| 49 | '/provider/' . $source . '/', | |
| 50 | array( | |
| 51 | 'isAssigned' => true | |
| 52 | ) | |
| 53 | )->getCollection(); | |
| 54 | return ($providerAssigned) ? | |
| 55 | $providerAssigned->withUniqueProvider()->sortByName() : | |
| 56 | new ProviderList(); | |
| 57 | } | |
| 58 | ||
| 59 | protected static function readProviderNotAssigned($source) | |
| 60 | { | |
| 61 | $providerNotAssigned = \App::$http->readGetResult( | |
| 62 | '/provider/' . $source . '/', | |
| 63 | array( | |
| 64 | 'isAssigned' => false | |
| 65 | ) | |
| 66 | )->getCollection(); | |
| 67 | return ($providerNotAssigned) ? | |
| 68 | $providerNotAssigned->withUniqueProvider()->sortByName() : | |
| 69 | new ProviderList(); | |
| 70 | } | |
| 71 | } |