Lines
100.00%
30 / 30
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 27 / 27 | 100.00% | 1 / 1 | 5 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 13 | class WarehousePeriodGet extends \BO\Zmsbackend\Api\BaseController | |
| 14 | { | |
| 15 | /** | |
| 16 | * @SuppressWarnings(Param) | |
| 17 | * @return \Psr\Http\Message\ResponseInterface | |
| 18 | */ | |
| 19 | #[\Override] | |
| 20 | public function readResponse( | |
| 21 | \Psr\Http\Message\RequestInterface $request, | |
| 22 | \Psr\Http\Message\ResponseInterface $response, | |
| 23 | array $args | |
| 24 | ) { | |
| 25 | $workstation = \BO\Zmsbackend\Helper\User::readStatisticWorkstation($request); | |
| 26 | $subject = Validator::value($args['subject'])->isString()->getValue(); | |
| 27 | $subjectId = Validator::value($args['subjectId'])->isString()->getValue(); | |
| 28 | $period = Validator::value($args['period'])->isString()->isBiggerThan(2)->setDefault('_')->getValue(); | |
| 29 | $validator = $request->getAttribute('validator'); | |
| 30 | $groupby = $validator->getParameter('groupby')->isString()->isBiggerThan(2)->getValue(); | |
| 31 | $fromDate = $validator->getParameter('fromDate')->isString()->getValue(); | |
| 32 | $toDate = $validator->getParameter('toDate')->isString()->getValue(); | |
| 33 | ||
| 34 | $exchangeClass = '\BO\Zmsbackend\Exchange\Service\Exchange' . ucfirst($subject ?? ''); | |
| 35 | if (! class_exists($exchangeClass)) { | |
| 36 | throw new \BO\Zmsbackend\Warehouse\Exception\UnknownReportType(); | |
| 37 | } | |
| 38 | ||
| 39 | $periodHelper = new \BO\Zmsbackend\Helper\ExchangePeriod($period); | |
| 40 | $start = $periodHelper->getStartDateTime(); | |
| 41 | $end = $periodHelper->getEndDateTime(); | |
| 42 | ||
| 43 | $subjectPeriod = (new $exchangeClass())->readEntity( | |
| 44 | $subjectId, | |
| 45 | $fromDate ? new \DateTime($fromDate) : $start, | |
| 46 | $toDate ? new \DateTime($toDate) : $end, | |
| 47 | $periodHelper->getPeriodIdentifier($groupby) | |
| 48 | ); | |
| 49 | if (0 == count($subjectPeriod['data'])) { | |
| 50 | throw new \BO\Zmsbackend\Warehouse\Exception\ReportNotFound(); | |
| 51 | } | |
| 52 | ||
| 53 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 54 | $message->data = (new \BO\Zmsbackend\Helper\ExchangeAccessFilter($subjectPeriod, $workstation))->getFilteredEntity(); | |
| 55 | ||
| 56 | $response = Render::withLastModified($response, time(), '0'); | |
| 57 | $response = Render::withJson($response, $message, $message->getStatuscode()); | |
| 58 | return $response; | |
| 59 | } | |
| 60 | } |
Inherited from BO\Zmsbackend\Api\BaseController
| 20 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 21 | { | |
| 22 | $request = $this->initRequest($request); | |
| 23 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 24 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 25 | } |