Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
44 / 44
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationRequests
100.00% covered (success)
100.00%
44 / 44
100.00% covered (success)
100.00%
7 / 7
15
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getScope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDifferentScope
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 readDepartment
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 readCluster
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 readProcessListByDate
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
3
 readNextProcess
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsclient;
4
5use DateTimeInterface;
6use BO\Zmsentities\Workstation;
7use BO\Zmsentities\Cluster;
8use BO\Zmsentities\Department;
9use BO\Zmsentities\Scope;
10use BO\Zmsentities\Collection\ProcessList;
11
12class 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) {
45            $this->department = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/department/')
46                ->getEntity();
47        }
48        return $this->department ? $this->department : new Department();
49    }
50
51    public function readCluster(): Cluster
52    {
53        if (!$this->cluster) {
54            $this->cluster = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/cluster/')
55                ->getEntity();
56        }
57        return $this->cluster ? $this->cluster : new Cluster();
58    }
59
60    public function readProcessListByDate(
61        DateTimeInterface $selectedDate,
62        $gql = ""
63    ): ProcessList {
64        if ($this->workstation->isClusterEnabled()) {
65            $processList = $this->http
66                ->readGetResult(
67                    '/cluster/' . $this->readCluster()->id . '/process/' . $selectedDate->format('Y-m-d') . '/',
68                    [
69                        'gql' => $gql
70                    ]
71                )
72                ->getCollection();
73        } else {
74            $processList = $this->http
75                ->readGetResult(
76                    '/scope/' . $this->scope['id'] . '/process/' . $selectedDate->format('Y-m-d') . '/',
77                    [
78                        'gql' => $gql
79                    ]
80                )
81                ->getCollection();
82        }
83        return ($processList) ? $processList : new ProcessList();
84    }
85
86
87    /**
88     * @psalm-api
89     */
90    public function readNextProcess($excludedIds): \BO\Zmsentities\Schema\Entity|false|null
91    {
92        $exclude = is_array($excludedIds) ? implode(',', $excludedIds) : $excludedIds;
93        if ($this->workstation->isClusterEnabled()) {
94            $process = $this->http
95                ->readGetResult('/cluster/' . $this->cluster['id'] . '/queue/next/', ['exclude' => $exclude])
96                ->getEntity();
97        } else {
98            $process = $this->http
99                ->readGetResult(
100                    '/scope/' . $this->scope['id'] . '/queue/next/',
101                    ['exclude' => $exclude]
102                )
103                ->getEntity();
104        }
105        return $process;
106    }
107}