From 4f50900ec4711202653109200c9ea27834e33500 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 15:57:15 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Db/CoreRequestBuilder.php | 67 +++++++++++++++++++++++++++++++--------- lib/Db/IndexesRequest.php | 59 ++++++++++++++++++++++++++--------- lib/Db/IndexesRequestBuilder.php | 38 ++++++++++------------- lib/Db/TickRequest.php | 21 +++++++++---- lib/Db/TickRequestBuilder.php | 36 ++++++++++----------- 5 files changed, 144 insertions(+), 77 deletions(-) (limited to 'lib') diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index d1223e4..d90054c 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -1,4 +1,7 @@ limitToDBField($qb, 'id', $id); + protected function limitToId(IQueryBuilder &$qb, int $id) { + $this->limitToDBFieldInt($qb, 'id', $id); } @@ -92,18 +102,18 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $userId */ - protected function limitToOwnerId(IQueryBuilder &$qb, $userId) { + protected function limitToOwnerId(IQueryBuilder &$qb, string $userId) { $this->limitToDBField($qb, 'owner_id', $userId); } /** - * Limit to the type + * Limit to the providerId * * @param IQueryBuilder $qb * @param string $providerId */ - protected function limitToProviderId(IQueryBuilder &$qb, $providerId) { + protected function limitToProviderId(IQueryBuilder &$qb, string $providerId) { $this->limitToDBField($qb, 'provider_id', $providerId); } @@ -114,13 +124,13 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $documentId */ - protected function limitToDocumentId(IQueryBuilder &$qb, $documentId) { + protected function limitToDocumentId(IQueryBuilder &$qb, string $documentId) { $this->limitToDBField($qb, 'document_id', $documentId); } /** - * Limit to the documentId + * Limit to the entry with at least one Error * * @param IQueryBuilder $qb */ @@ -131,7 +141,7 @@ class CoreRequestBuilder { /** - * Limit to the documentId + * Limit to the entry with no error * * @param IQueryBuilder $qb */ @@ -147,39 +157,66 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param array $documentIds */ - protected function limitToDocumentIds(IQueryBuilder &$qb, $documentIds) { - $this->limitToDBField($qb, 'document_id', $documentIds); + protected function limitToDocumentIds(IQueryBuilder &$qb, array $documentIds) { + $this->limitToDBFieldArray($qb, 'document_id', $documentIds); } /** - * Limit the request to the Source + * Limit the request to source * * @param IQueryBuilder $qb * @param string $source */ - protected function limitToSource(IQueryBuilder &$qb, $source) { + protected function limitToSource(IQueryBuilder &$qb, string $source) { $this->limitToDBField($qb, 'id', $source); } /** - * Limit the request to the Source + * Limit the request to status * * @param IQueryBuilder $qb * @param string $status */ - protected function limitToStatus(IQueryBuilder &$qb, $status) { + protected function limitToStatus(IQueryBuilder &$qb, string $status) { $this->limitToDBField($qb, 'status', $status); } + /** + * @param IQueryBuilder $qb + * @param string $field + * @param string $value + */ + private function limitToDBField(IQueryBuilder &$qb, string $field, string $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + /** + * @param IQueryBuilder $qb + * @param string $field + * @param int $value + */ + private function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + /** * @param IQueryBuilder $qb * @param string $field * @param string|integer|array $values */ - private function limitToDBField(IQueryBuilder &$qb, $field, $values) { + private function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) { $expr = $qb->expr(); $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; $field = $pf . $field; diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php index 2eb225c..4b5b45f 100644 --- a/lib/Db/IndexesRequest.php +++ b/lib/Db/IndexesRequest.php @@ -1,4 +1,7 @@ getIndexesInsertSql(); @@ -69,7 +78,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function resetError(Index $index) { + public function resetError(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -105,7 +114,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @return Index[] */ - public function getErrorIndexes() { + public function getErrorIndexes(): array { $qb = $this->getIndexesSelectSql(); $this->limitToErr($qb); @@ -126,7 +135,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function update(Index $index) { + public function update(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -159,12 +168,32 @@ class IndexesRequest extends IndexesRequestBuilder { } - public function updateStatus($providerId, $indexes, $status) { + /** + * @param string $providerId + * @param string $documentId + * @param int $status + */ + public function updateStatus(string $providerId, string $documentId, int $status) { + $qb = $this->getIndexesUpdateSql(); + $qb->set('status', $qb->createNamedParameter($status)); + + $this->limitToProviderId($qb, $providerId); + $this->limitToDocumentId($qb, $documentId); + + $qb->execute(); + } + + /** + * @param string $providerId + * @param array $indexes + * @param int $status + */ + public function updateStatuses(string $providerId, array $indexes, int $status) { $qb = $this->getIndexesUpdateSql(); $qb->set('status', $qb->createNamedParameter($status)); $this->limitToProviderId($qb, $providerId); - $this->limitToDocumentId($qb, $indexes); + $this->limitToDocumentIds($qb, $indexes); $qb->execute(); } @@ -185,7 +214,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @param string $providerId */ - public function deleteFromProviderId($providerId) { + public function deleteFromProviderId(string $providerId) { $qb = $this->getIndexesDeleteSql(); $this->limitToProviderId($qb, $providerId); @@ -207,12 +236,12 @@ class IndexesRequest extends IndexesRequestBuilder { * return index. * * @param string $providerId - * @param string|int $documentId + * @param string $documentId * * @return Index * @throws IndexDoesNotExistException */ - public function getIndex($providerId, $documentId): Index { + public function getIndex(string $providerId, string $documentId): Index { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentId($qb, $documentId); @@ -238,7 +267,7 @@ class IndexesRequest extends IndexesRequestBuilder { * @return Index[] * @throws IndexDoesNotExistException */ - public function getIndexes($providerId, $documentIds) { + public function getIndexes(string $providerId, array $documentIds): array { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentIds($qb, $documentIds); @@ -263,7 +292,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return Index[] */ - public function getQueuedIndexes($all = false) { + public function getQueuedIndexes(bool $all = false): array { $qb = $this->getIndexesSelectSql(); $this->limitToQueuedIndexes($qb); if ($all === false) { @@ -284,13 +313,13 @@ class IndexesRequest extends IndexesRequestBuilder { /** * return list of last indexes from a providerId. * - * @param IFullTextSearchProvider $provider + * @param string $providerId * * @return Index[] */ - public function getIndexesFromProvider(IFullTextSearchProvider $provider) { + public function getIndexesFromProvider(string $providerId): array { $qb = $this->getIndexesSelectSql(); - $this->limitToProviderId($qb, $provider->getId()); + $this->limitToProviderId($qb, $providerId); $indexes = []; $cursor = $qb->execute(); diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php index 0eb47c2..0eb72ce 100644 --- a/lib/Db/IndexesRequestBuilder.php +++ b/lib/Db/IndexesRequestBuilder.php @@ -1,4 +1,7 @@ dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_INDEXES); @@ -68,7 +61,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesUpdateSql() { + protected function getIndexesUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_INDEXES); @@ -81,7 +74,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesSelectSql() { + protected function getIndexesSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -102,7 +95,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesDeleteSql() { + protected function getIndexesDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -115,7 +108,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return Index */ - protected function parseIndexesSelectSql($data) { + protected function parseIndexesSelectSql(array $data): Index { $index = new Index($data['provider_id'], $data['document_id']); $index->setStatus($data['status']) ->setSource($data['source']) @@ -129,3 +122,4 @@ class IndexesRequestBuilder extends CoreRequestBuilder { } } + diff --git a/lib/Db/TickRequest.php b/lib/Db/TickRequest.php index 4338450..6e50678 100644 --- a/lib/Db/TickRequest.php +++ b/lib/Db/TickRequest.php @@ -1,4 +1,7 @@ getTickInsertSql(); @@ -65,7 +74,7 @@ class TickRequest extends TickRequestBuilder { * * @return bool */ - public function update(Tick $tick) { + public function update(Tick $tick): bool { try { $this->getTickById($tick->getId()); @@ -117,7 +126,7 @@ class TickRequest extends TickRequestBuilder { * @return Tick * @throws TickDoesNotExistException */ - public function getTickById($id) { + public function getTickById(int $id): Tick { $qb = $this->getTickSelectSql(); $this->limitToId($qb, $id); @@ -134,13 +143,13 @@ class TickRequest extends TickRequestBuilder { /** - * return tick. + * return ticks. * * @param string $status * * @return Tick[] */ - public function getTickByStatus($status) { + public function getTicksByStatus(string $status): array { $ticks = []; @@ -162,7 +171,7 @@ class TickRequest extends TickRequestBuilder { * * @return Tick[] */ - public function getTickBySource($source) { + public function getTicksBySource(string $source): array { $qb = $this->getTickSelectSql(); $this->limitToSource($qb, $source); diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index cd3cf09..e19ca84 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -1,4 +1,7 @@ dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_TICKS); @@ -67,7 +65,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickUpdateSql() { + protected function getTickUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_TICKS); @@ -80,7 +78,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickSelectSql() { + protected function getTickSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -100,7 +98,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickDeleteSql() { + protected function getTickDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -113,12 +111,12 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return Tick */ - protected function parseTickSelectSql($data) { + protected function parseTickSelectSql(array $data): Tick { $tick = new Tick($data['source'], $data['id']); $tick->setData(json_decode($data['data'], true)) ->setTick($data['tick']) - ->setFirstTick($data['first_tick']) - ->setStatus($data['status']) + ->setFirstTick($data['first_tick']) + ->setStatus($data['status']) ->setAction($data['action']); return $tick; -- cgit v1.2.3