Skip to content

Commit

Permalink
Refactors lib/private/FullTextSearch.
Browse files Browse the repository at this point in the history
Mainly using PHP8's constructor property promotion.

Signed-off-by: Faraz Samapoor <[email protected]>
  • Loading branch information
Faraz Samapoor authored and fsamapoor committed Oct 3, 2023
1 parent 4d227c1 commit b920fb1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 501 deletions.
89 changes: 35 additions & 54 deletions lib/private/FullTextSearch/FullTextSearchManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,46 @@
* @package OC\FullTextSearch
*/
class FullTextSearchManager implements IFullTextSearchManager {
/** @var IProviderService */
private $providerService;
private ?IProviderService $providerService;

/** @var IIndexService */
private $indexService;

/** @var ISearchService */
private $searchService;
private ?IIndexService $indexService;

private ?ISearchService $searchService;

/**
* @since 15.0.0
*
* @param IProviderService $providerService
*/
public function registerProviderService(IProviderService $providerService) {
public function registerProviderService(IProviderService $providerService): void {
$this->providerService = $providerService;
}

/**
* @since 15.0.0
*
* @param IIndexService $indexService
*/
public function registerIndexService(IIndexService $indexService) {
public function registerIndexService(IIndexService $indexService): void {
$this->indexService = $indexService;
}

/**
* @since 15.0.0
*
* @param ISearchService $searchService
*/
public function registerSearchService(ISearchService $searchService) {
public function registerSearchService(ISearchService $searchService): void {
$this->searchService = $searchService;
}

/**
* @since 16.0.0
*
* @return bool
*/
public function isAvailable(): bool {
if ($this->indexService === null ||
$this->providerService === null ||
$this->searchService === null) {
if ($this->indexService === null) {
return false;
}

if ($this->providerService === null) {
return false;
}

if ($this->searchService === null) {
return false;
}

Expand All @@ -93,7 +87,6 @@ public function isAvailable(): bool {


/**
* @return IProviderService
* @throws FullTextSearchAppNotAvailableException
*/
private function getProviderService(): IProviderService {
Expand All @@ -106,7 +99,6 @@ private function getProviderService(): IProviderService {


/**
* @return IIndexService
* @throws FullTextSearchAppNotAvailableException
*/
private function getIndexService(): IIndexService {
Expand All @@ -119,7 +111,6 @@ private function getIndexService(): IIndexService {


/**
* @return ISearchService
* @throws FullTextSearchAppNotAvailableException
*/
private function getSearchService(): ISearchService {
Expand All @@ -134,15 +125,12 @@ private function getSearchService(): ISearchService {
/**
* @throws FullTextSearchAppNotAvailableException
*/
public function addJavascriptAPI() {
public function addJavascriptAPI(): void {
$this->getProviderService()->addJavascriptAPI();
}


/**
* @param string $providerId
*
* @return bool
* @throws FullTextSearchAppNotAvailableException
*/
public function isProviderIndexed(string $providerId): bool {
Expand All @@ -151,56 +139,52 @@ public function isProviderIndexed(string $providerId): bool {


/**
* @param string $providerId
* @param string $documentId
* @return IIndex
* @throws FullTextSearchAppNotAvailableException
*/
public function getIndex(string $providerId, string $documentId): IIndex {
return $this->getIndexService()->getIndex($providerId, $documentId);
}

/**
* @param string $providerId
* @param string $documentId
* @param string $userId
* @param int $status
*
* @see IIndex for available value for $status.
*
* @return IIndex
* @throws FullTextSearchAppNotAvailableException
*/
public function createIndex(string $providerId, string $documentId, string $userId, int $status = 0): IIndex {
public function createIndex(
string $providerId,
string $documentId,
string $userId,
int $status = 0,
): IIndex {
return $this->getIndexService()->createIndex($providerId, $documentId, $userId, $status);
}


/**
* @param string $providerId
* @param string $documentId
* @param int $status
* @param bool $reset
*
* @see IIndex for available value for $status.
*
* @throws FullTextSearchAppNotAvailableException
*/
public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false) {
public function updateIndexStatus(
string $providerId,
string $documentId,
int $status,
bool $reset = false,
): void {
$this->getIndexService()->updateIndexStatus($providerId, $documentId, $status, $reset);
}

/**
* @param string $providerId
* @param array $documentIds
* @param int $status
* @param bool $reset
*
* @see IIndex for available value for $status.
*
* @throws FullTextSearchAppNotAvailableException
*/
public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false) {
public function updateIndexesStatus(
string $providerId,
array $documentIds,
int $status,
bool $reset = false,
): void {
$this->getIndexService()->updateIndexesStatus($providerId, $documentIds, $status, $reset);
}

Expand All @@ -210,15 +194,12 @@ public function updateIndexesStatus(string $providerId, array $documentIds, int
*
* @throws FullTextSearchAppNotAvailableException
*/
public function updateIndexes(array $indexes) {
public function updateIndexes(array $indexes): void {
$this->getIndexService()->updateIndexes($indexes);
}


/**
* @param array $request
* @param string $userId
*
* @return ISearchResult[]
* @throws FullTextSearchAppNotAvailableException
*/
Expand Down
Loading

0 comments on commit b920fb1

Please sign in to comment.