wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/rest-api/src/Application/UseCases/GetLatestPropertyRevisionMetadata.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php declare( strict_types=1 );

namespace Wikibase\Repo\RestApi\Application\UseCases;

use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\Repo\RestApi\Domain\Services\PropertyRevisionMetadataRetriever;

/**
 * @license GPL-2.0-or-later
 */
class GetLatestPropertyRevisionMetadata {

    private PropertyRevisionMetadataRetriever $metadataRetriever;

    public function __construct( PropertyRevisionMetadataRetriever $metadataRetriever ) {
        $this->metadataRetriever = $metadataRetriever;
    }

    /**
     * @throws UseCaseError if the property does not exist
     *
     * @return array{int, string}
     */
    public function execute( NumericPropertyId $id ): array {
        $metaDataResult = $this->metadataRetriever->getLatestRevisionMetadata( $id );

        if ( !$metaDataResult->propertyExists() ) {
            throw UseCaseError::newResourceNotFound( 'property' );
        }

        return [ $metaDataResult->getRevisionId(), $metaDataResult->getRevisionTimestamp() ];
    }

}