Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Mapper methods to satisfy codestyle #368

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/Xhgui/Db/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ class Mapper
{
/**
* Convert request data keys into mongo values.
*
* @param array $options
* @return array
*/
public function convert($options)
public function convert(array $options): array
{
$result = [
'conditions' => [],
Expand All @@ -24,10 +21,10 @@ public function convert($options)
'perPage' => 25,
];
if (isset($options['conditions'])) {
$result['conditions'] = $this->_conditions($options['conditions']);
$result['conditions'] = $this->buildConditions($options['conditions']);
}
$result['direction'] = $this->_direction($options);
$result['sort'] = $this->_sort($options);
$result['direction'] = $this->buildDirection($options);
$result['sort'] = $this->buildSort($options);

if (isset($options['perPage'])) {
$result['perPage'] = $options['perPage'];
Expand All @@ -41,11 +38,8 @@ public function convert($options)
*
* Keeps the schema details out of the GET parameters.
* String casts are uses to prevent mongo operator injection.
*
* @param array $search
* @return array
*/
protected function _conditions($search)
private function buildConditions(array $search): array
{
if (!empty($search['limit_custom']) && $search['limit_custom'][0] === 'P') {
$search['limit'] = $search['limit_custom'];
Expand All @@ -63,10 +57,10 @@ protected function _conditions($search)
$conditions['meta.simple_url'] = (string)$search['simple_url'];
}
if (!empty($search['request_start'])) {
$conditions['meta.SERVER.REQUEST_TIME']['$gte'] = $this->_convertDate($search['request_start']);
$conditions['meta.SERVER.REQUEST_TIME']['$gte'] = $this->convertDate($search['request_start']);
}
if (!empty($search['request_end'])) {
$conditions['meta.SERVER.REQUEST_TIME']['$lte'] = $this->_convertDate($search['request_end']);
$conditions['meta.SERVER.REQUEST_TIME']['$lte'] = $this->convertDate($search['request_end']);
}

if (!empty($search['remote_addr'])) {
Expand Down Expand Up @@ -99,7 +93,7 @@ protected function _conditions($search)
return $conditions;
}

protected function _convertDate($dateString)
private function convertDate($dateString)
{
if (is_numeric($dateString)) {
return (float) $dateString;
Expand All @@ -112,7 +106,7 @@ protected function _convertDate($dateString)
return $date->getTimestamp();
}

protected function _direction($options)
private function buildDirection(array $options): string
{
if (empty($options['direction'])) {
return SearcherInterface::DEFAULT_DIRECTION;
Expand All @@ -133,7 +127,7 @@ protected function _direction($options)
* @param array $options pagination options including the sort key
* @return array sort field & direction
*/
protected function _sort($options)
private function buildSort(array $options): array
{
$direction = -1;
if (isset($options['direction']) && $options['direction'] === 'asc') {
Expand Down