Skip to content

Commit d94d6b3

Browse files
committed
Fix static analytics errors.
1 parent 16ba3a1 commit d94d6b3

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/Core/Analytics.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public function save(string $query, int $results): void
3535
Lock::stopTransaction($cacheKey);
3636
} catch (\Throwable $e) {
3737
Lock::stopTransaction($cacheKey);
38-
if ($logger !== null) {
39-
$logger->critical($e->getMessage(), ['exception' => $e]);
40-
}
38+
$logger?->critical($e->getMessage(), ['exception' => $e]);
4139
return;
4240
}
4341

@@ -163,15 +161,19 @@ private function getSearchQuery(string $query, int $results): SearchQuery
163161
*/
164162
private function selectSearchQuery(string $query): SearchQuery
165163
{
166-
return (new EntityRepository(
164+
$repository = new EntityRepository(
167165
$this->entityManager,
168166
$this->entityManager->getClassMetadata(SearchQuery::class),
169-
))
167+
);
168+
$return = $repository
170169
->createQueryBuilder('searchQuery')
171170
->where('searchQuery.query = :query')
172171
->setParameter('query', $query)
173172
->setMaxResults(1)
174173
->getQuery()
175174
->getSingleResult();
175+
assert($return instanceof SearchQuery);
176+
177+
return $return;
176178
}
177179
}

src/Core/Core.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public function processCandidateSearch(string $query, string $entity, array $col
9898
$propertyRef->setAccessible(true);
9999
$columnDatabaseValue = $propertyRef->getValue($candidateResult);
100100
} catch (\ReflectionException $e) {
101-
throw new \RuntimeException('Can not read property "' . $column . '" from "' . $candidateResultClass . '": ' . $e->getMessage(), (int) $e->getCode(), $e);
101+
throw new \RuntimeException(sprintf('Can not read property "%s" from "%s": %s', $column, $candidateResultClass, $e->getMessage()), $e->getCode(), $e);
102102
}
103103
} elseif (isset($methodRef)) { // Call native method when contain only optional parameters
104104
try {
105105
$columnDatabaseValue = $methodRef->invoke($candidateResult);
106106
} catch (\ReflectionException $e) {
107-
throw new \LogicException($e->getMessage(), (int) $e->getCode(), $e);
107+
throw new \LogicException($e->getMessage(), $e->getCode(), $e);
108108
}
109109
} else {
110110
throw new \LogicException('Method "' . $getter . '" can not be called on "' . $candidateResultClass . '".');
@@ -113,7 +113,7 @@ public function processCandidateSearch(string $query, string $entity, array $col
113113
$rawColumnValue = $this->hydrateColumnValue($columnDatabaseValue);
114114
} catch (\InvalidArgumentException $e) {
115115
throw new \InvalidArgumentException(
116-
'Column "' . ($getterColumn ?? $column) . '" of entity "' . $entity . '" '
116+
sprintf('Column "%s" of entity "%s" ', $getterColumn, $entity)
117117
. 'can not be converted to string because the value is not scalar type.' . "\n"
118118
. 'Advance info: ' . $e->getMessage(),
119119
);
@@ -202,7 +202,6 @@ private function getColumnGetters(array $columns): array
202202

203203
private function getValueByRelation(string $column, ?object $candidateEntity = null): string
204204
{
205-
$getterValue = null;
206205
$return = null;
207206
$columnsIterator = 0;
208207
$columns = explode('.', $column);

src/Core/SelectorBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function addColumn(string $column, ?string $entity = null, ?string $forma
134134
}
135135
if (isset($this->map[$entity][$column]) === false) {
136136
assert(isset($this->map[$entity]));
137-
$this->map[$entity][$column] = $format;
137+
$this->map[$entity][$column] = $format ?? '';
138138
}
139139

140140
return $this;

src/Entity/SearchQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SearchQuery
2020
#[ORM\Column(type: 'uuid', unique: true)]
2121
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
2222
#[ORM\CustomIdGenerator(class: AnalyticsUuidGenerator::class)]
23-
private string $id;
23+
protected string $id;
2424

2525
#[ORM\Column(type: 'string', unique: true)]
2626
private string $query;
@@ -44,7 +44,7 @@ class SearchQuery
4444
public function __construct(string $query, int $results, int $score = 0)
4545
{
4646
$this->query = trim($query);
47-
$this->results = $results < 0 ? 0 : $results;
47+
$this->results = max($results, 0);
4848
$this->setScore($score);
4949
$this->insertedDate = new \DateTimeImmutable('now');
5050
}

0 commit comments

Comments
 (0)