Lines
98.03%
50 / 51
Methods
85.71%
6 / 7
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| getScope | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| setDifferentScope | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| readDepartment | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| readCluster | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| readProcessListByDate | 95.00% | 19 / 20 | 0.00% | 0 / 1 | 3 | ||
| readNextProcess | 100.00% | 15 / 15 | 100.00% | 1 / 1 | 3 | ||
| 12 | class WorkstationRequests | |
| 13 | { | |
| 14 | protected Http $http; | |
| 15 | protected Workstation $workstation; | |
| 16 | protected ?Cluster $cluster = null; | |
| 17 | protected ?Department $department = null; | |
| 18 | protected Scope $scope; | |
| 19 | ||
| 20 | public function __construct( | |
| 21 | Http $http, | |
| 22 | Workstation $workstation | |
| 23 | ) { | |
| 24 | $this->http = $http; | |
| 25 | $this->workstation = $workstation; | |
| 26 | $this->scope = $workstation->getScope(); | |
| 27 | } | |
| 28 | ||
| 29 | /** @psalm-api */ | |
| 30 | public function getScope(): Scope | |
| 31 | { | |
| 32 | return $this->scope; | |
| 33 | } | |
| 34 | ||
| 35 | /** @psalm-api */ | |
| 36 | public function setDifferentScope(Scope $scope): self | |
| 37 | { | |
| 38 | $this->scope = $scope; | |
| 39 | return $this; | |
| 40 | } | |
| 41 | ||
| 42 | public function readDepartment(): Department | |
| 43 | { | |
| 44 | if (!$this->department instanceof Department) { | |
| 45 | $entity = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/department/') | |
| 46 | ->getEntity(); | |
| 47 | $this->department = $entity instanceof Department ? $entity : new Department(); | |
| 48 | } | |
| 49 | return $this->department; | |
| 50 | } | |
| 51 | ||
| 52 | public function readCluster(): Cluster | |
| 53 | { | |
| 54 | if (!$this->cluster instanceof Cluster) { | |
| 55 | $entity = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/cluster/') | |
| 56 | ->getEntity(); | |
| 57 | $this->cluster = $entity instanceof Cluster ? $entity : new Cluster(); | |
| 58 | } | |
| 59 | return $this->cluster; | |
| 60 | } | |
| 61 | ||
| 62 | public function readProcessListByDate( | |
| 63 | DateTimeInterface $selectedDate, | |
| 64 | string $gql = "" | |
| 65 | ): ProcessList { | |
| 66 | $processList = $this->workstation->isClusterEnabled() | |
| 67 | ? $this->http | |
| 68 | ->readGetResult( | |
| 69 | '/cluster/' . $this->readCluster()['id'] . '/process/' . $selectedDate->format('Y-m-d') . '/', | |
| 70 | [ | |
| 71 | 'gql' => $gql | |
| 72 | ] | |
| 73 | ) | |
| 74 | ->getCollection() | |
| 75 | : $this->http | |
| 76 | ->readGetResult( | |
| 77 | '/scope/' . $this->scope['id'] . '/process/' . $selectedDate->format('Y-m-d') . '/', | |
| 78 | [ | |
| 79 | 'gql' => $gql | |
| 80 | ] | |
| 81 | ) | |
| 82 | ->getCollection(); | |
| 83 | if ($processList instanceof ProcessList) { | |
| 84 | return $processList; | |
| 85 | } | |
| 86 | return new ProcessList(); | |
| 87 | } | |
| 88 | ||
| 89 | ||
| 90 | /** | |
| 91 | * @psalm-api | |
| 92 | */ | |
| 93 | public function readNextProcess(mixed $excludedIds): \BO\Zmsentities\Schema\Entity|false|null | |
| 94 | { | |
| 95 | $exclude = is_array($excludedIds) ? implode(',', $excludedIds) : $excludedIds; | |
| 96 | if ($this->workstation->isClusterEnabled()) { | |
| 97 | $process = $this->http | |
| 98 | ->readGetResult( | |
| 99 | '/cluster/' . $this->readCluster()['id'] . '/queue/next/', | |
| 100 | ['exclude' => $exclude] | |
| 101 | ) | |
| 102 | ->getEntity(); | |
| 103 | } else { | |
| 104 | $process = $this->http | |
| 105 | ->readGetResult( | |
| 106 | '/scope/' . $this->scope['id'] . '/queue/next/', | |
| 107 | ['exclude' => $exclude] | |
| 108 | ) | |
| 109 | ->getEntity(); | |
| 110 | } | |
| 111 | return $process; | |
| 112 | } | |
| 113 | } |