An error occurred while loading the file. Please try again.
-
Lückemeyer authored348d8bed
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
class DtaResult {
public $packageName;
public $className;
public $name;
/**
* State is defined like below
*
* 0 UNKNOWN
* 1 SUCCESS
* 2 FAILURE
* 3 COMPILATIONERROR
*/
public $state;
public $failureType;
public $failureReason;
public $stacktrace;
public $columnNumber;
public $lineNumber;
public $position;
/**
* @return name of state like defined
*/
public static function getStateName(int $state): string {
if ($state == 1) {
return "success";
} else if ($state == 2) {
return "failed";
} else if ($state == 3) {
return "compilation error";
} else {
return "unknown";
}
}
}
class DtaResultSummary {
public $timestamp;
public $globalStacktrace;
public $successfulTestCompetencyProfile;
public $overallTestCompetencyProfile;
public $results;
/**
* @param string $jsonString jsonString containing DtaResultSummary
* @return DtaResultSummary
*/
public static function decodeJson($jsonString): DtaResultSummary {
$response = json_decode($jsonString);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
$summary = new DtaResultSummary();
$summary->timestamp = $response->timestamp;
$summary->globalStacktrace = $response->globalStacktrace;
$summary->successfulTestCompetencyProfile = $response->successfulTestCompetencyProfile;
$summary->overallTestCompetencyProfile = $response->overallTestCompetencyProfile;
$summary->results = self::decodeJsonResultArray($response->results);
return $summary;
}
private static function decodeJsonCompetencyArray($jsonArray): array {
$ret = array();
foreach ($jsonArray as $entry) {
$ret[] = $entry;
}
return $ret;
}
/**
* @param array $jsonArray decoded json array of results array
* @return array of DtaResult
*/
private static function decodeJsonResultArray($jsonArray): array {
$ret = array();
foreach ($jsonArray as $entry) {
$value = new DtaResult();
$value->packageName = $entry->packageName;
$value->className = $entry->className;
$value->name = $entry->name;
$value->state = $entry->state;
$value->failureType = $entry->failureType;
$value->failureReason = $entry->failureReason;
$value->stacktrace = $entry->stacktrace;
$value->columnNumber = $entry->columnNumber;
$value->lineNumber = $entry->lineNumber;
$value->position = $entry->position;
$ret[] = $value;
}
return $ret;
}
/**
* @param int $state state ordinal number
* @return int count of occurences provided state has
*/
public function stateOccurenceCount(int $state): int {
$num = 0;
foreach($this->results as $r) {
if ($r->state == $state) {
$num++;
}
}
return $num;
}
public function compilationErrorCount(): int {
return $this->stateOccurenceCount(3);
}
public function failedCount(): int {
return $this->stateOccurenceCount(2);
}