Refactor PuQI from musdb to move logic into this lib

See museum-digital/musdb#947
This commit is contained in:
Joshua Ramon Enslin 2023-07-18 13:29:12 +02:00
parent 6bf7ae36c8
commit abeeb5a185
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
4 changed files with 1292 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
<?PHP
/**
* Represents a section of object data that is checked by Puqi.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a section of object data that is checked by Puqi.
*/
enum MDPuqiCheckSection implements JsonSerializable {
case objectName;
case objectType;
case objectDescription;
case objectMaterialTechnique;
case objectMeasurements;
case events;
case tags;
case collectionCount;
case literatureCount;
case hyperlinkCount;
case documentCount;
case linkedObjectCount;
case seriesCount;
case exhibitionCount;
case translationCount;
case transcriptCount;
case objectHasReceptionCount;
case objectIsReferenceCount;
case markingCount;
case imageCount;
case publicInscription;
case publicDetailedDescription;
case publicComparableObjects;
case metadataLicense;
case imageMissing;
case imageSizes;
case imageLicenses;
/**
* Lists all available names.
*
* @return array<string>
*/
public static function caseNames():array {
$output = [];
$cases = self::cases();
foreach ($cases as $case) {
$output[] = $case->name;
}
return $output;
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}

53
src/MDPuqiMessage.php Normal file
View File

@ -0,0 +1,53 @@
<?PHP
/**
* Describes a PuQI message.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Describes a PuQI message.
*/
final class MDPuqiMessage implements JsonSerializable {
public readonly MDPuqiCheckSection $section; // Section of object data that is described by the message.
public readonly MDPuqiMessageStatus $status;
public readonly string $message; // Text message.
public readonly int $score;
/**
* Provides the option to serialize as a string during json_encode().
*
* @return array{section: MDPuqiCheckSection, status: MDPuqiMessageStatus, message: string, score: integer}
*/
public function jsonSerialize():array {
return [
'section' => $this->section,
'status' => $this->status,
'message' => $this->message,
'score' => $this->score
];
}
/**
* Constructor.
*
* @param MDPuqiCheckSection $section Section described by this message.
* @param MDPuqiMessageStatus $status Status.
* @param string $message Message.
* @param integer $score Score impact of the message.
*
* @return void
*/
public function __construct(MDPuqiCheckSection $section, MDPuqiMessageStatus $status, string $message, int $score) {
$this->section = $section;
$this->status = $status;
$this->message = $message;
$this->score = $score;
}
}

View File

@ -0,0 +1,46 @@
<?PHP
/**
* Represents a warning / praise status of a message.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a warning / praise status of a message.
*/
enum MDPuqiMessageStatus implements JsonSerializable {
case warning;
case neutral;
case praise;
/**
* Lists all available names.
*
* @return array<string>
*/
public static function caseNames():array {
$output = [];
$cases = self::cases();
foreach ($cases as $case) {
$output[] = $case->name;
}
return $output;
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}