Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
43 / 43
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationRequests
100.00% covered (success)
100.00%
43 / 43
100.00% covered (success)
100.00%
7 / 7
14
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%
11 / 11
100.00% covered (success)
100.00%
1 / 1
2
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    public function getScope(): Scope
30    {
31        return $this->scope;
32    }
33
34    public function setDifferentScope(Scope $scope): self
35    {
36        $this->scope = $scope;
37        return $this;
38    }
39
40    public function readDepartment(): Department
41    {
42        if (!$this->department) {
43            $this->department = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/department/')
44                ->getEntity();
45        }
46        return $this->department ? $this->department : new Department();
47    }
48
49    public function readCluster(): Cluster
50    {
51        if (!$this->cluster) {
52            $this->cluster = $this->http->readGetResult('/scope/' . $this->scope['id'] . '/cluster/')
53                ->getEntity();
54        }
55        return $this->cluster ? $this->cluster : new Cluster();
56    }
57
58    public function readProcessListByDate(
59        DateTimeInterface $selectedDate,
60        $gql = ""
61    ): ProcessList {
62        if ($this->workstation->isClusterEnabled()) {
63            $processList = $this->http
64                ->readGetResult(
65                    '/cluster/' . $this->readCluster()->id . '/process/' . $selectedDate->format('Y-m-d') . '/',
66                    [
67                        'gql' => $gql
68                    ]
69                )
70                ->getCollection();
71        } else {
72            $processList = $this->http
73                ->readGetResult(
74                    '/scope/' . $this->scope['id'] . '/process/' . $selectedDate->format('Y-m-d') . '/',
75                    [
76                        'gql' => $gql
77                    ]
78                )
79                ->getCollection();
80        }
81        return ($processList) ? $processList : new ProcessList();
82    }
83
84
85    public function readNextProcess($excludedIds)
86    {
87        if ($this->workstation->isClusterEnabled()) {
88            $process = $this->http
89                ->readGetResult('/cluster/' . $this->cluster['id'] . '/queue/next/', ['exclude' => $excludedIds])
90                ->getEntity();
91        } else {
92            $process = $this->http
93                ->readGetResult(
94                    '/scope/' . $this->scope['id'] . '/queue/next/',
95                    ['exclude' => $excludedIds]
96                )
97                ->getEntity();
98        }
99        return $process;
100    }
101}