Skip to content

Commit

Permalink
change CS.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed May 29, 2021
1 parent 61b84e9 commit bc35736
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function validateColumnName(?string $column): bool
return false;
}

if (! \preg_match(self::VALID_COLUMN_NAME_REGEX, $column)) {
if (! preg_match(self::VALID_COLUMN_NAME_REGEX, $column)) {
return false;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Field extends Column implements FieldContract
public static function make($name)
{
if ($name instanceof static) {
return \tap(new static($name), static function ($field) use ($name) {
return tap(new static($name), static function ($field) use ($name) {
$field->wildcardSearching = $name->wildcardSearching;
});
}
Expand All @@ -53,7 +53,7 @@ public function validate(): bool
*/
protected function validateRelationColumn(): bool
{
[, $field] = \explode('.', $this->name, 2);
[, $field] = explode('.', $this->name, 2);

return Column::make($field)->validate();
}
Expand All @@ -63,38 +63,38 @@ protected function validateRelationColumn(): bool
*/
protected function validateJsonPath(): bool
{
$parts = \explode('->', $this->name, 2);
$parts = explode('->', $this->name, 2);

$field = $parts[0];
$path = \count($parts) > 1 ? $this->wrapJsonPath($parts[1], '->') : '';

return Column::make($field)->validate() && Column::make(\str_replace('.', '', $path))->validate();
return Column::make($field)->validate() && Column::make(str_replace('.', '', $path))->validate();
}

/**
* Is relation selector.
*/
public function isRelationSelector(): bool
{
return \strpos($this->name, '.') !== false;
return strpos($this->name, '.') !== false;
}

/**
* Is JSON path selector.
*/
public function isJsonPathSelector(): bool
{
return \strpos($this->name, '->') !== false;
return strpos($this->name, '->') !== false;
}

/**
* Wrap the given JSON path.
*/
protected function wrapJsonPath(string $value, string $delimiter = '->'): string
{
$value = \preg_replace("/([\\\\]+)?\\'/", "\\'", $value);
$value = preg_replace("/([\\\\]+)?\\'/", "\\'", $value);

return \str_replace($delimiter, '.', $value);
return str_replace($delimiter, '.', $value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/FieldSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function apply($query, array $keywords, string $likeOperator, string $whe
? $query->qualifyColumn((string) $this->column)
: $this->column;

if (count($keywords) > 1) {
if (\count($keywords) > 1) {
return $query->{$whereOperator}(static function ($query) use ($column, $keywords, $likeOperator) {
foreach ($keywords as $keyword) {
$query->orWhere((string) $column, $likeOperator, $keyword);
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/PrimaryKeySearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(?int $maxPrimaryKeySize = null)
*/
public function apply($query, array $keywords, string $likeOperator, ?string $whereOperator = null)
{
if ($this->canSearchPrimaryKey($model = $query->getModel(), $search = \head($keywords))) {
if ($this->canSearchPrimaryKey($model = $query->getModel(), $search = head($keywords))) {
$query->orWhere($model->getQualifiedKeyName(), $search);
}

Expand All @@ -47,7 +47,7 @@ public function apply($query, array $keywords, string $likeOperator, ?string $wh
*/
protected function canSearchPrimaryKey(Model $model, $search): bool
{
return \ctype_digit($search)
return ctype_digit($search)
&& \in_array($model->getKeyType(), ['int', 'integer'])
&& ($model->getConnection()->getDriverName() != 'pgsql' || $search <= $this->maxPrimaryKeySize);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public static function searchable(string $text, ?string $wildcard = '*', ?string
return [];
} elseif (\is_null($replacement)) {
return [$text];
} elseif (! Str::contains($text, \array_filter([$wildcard, $replacement])) && $wildcardSearching === true) {
} elseif (! Str::contains($text, array_filter([$wildcard, $replacement])) && $wildcardSearching === true) {
return Collection::make(static::$defaultSearchVariations)
->map(static function ($string) use ($text) {
return Str::replaceFirst('{keyword}', $text, $string);
})->all();
}

return [
\str_replace($wildcard, $replacement, $text),
str_replace($wildcard, $replacement, $text),
];
}

Expand All @@ -119,9 +119,9 @@ public static function searchable(string $text, ?string $wildcard = '*', ?string
*/
public static function sanitize(string $keyword): string
{
$words = \preg_replace('/[^\w\*\s]/iu', '', $keyword);
$words = preg_replace('/[^\w\*\s]/iu', '', $keyword);

if (empty(\trim($words))) {
if (empty(trim($words))) {
return '';
} elseif (\strlen($words) > 3 && \strlen($words) < (\strlen($keyword) * 0.5)) {
return $words;
Expand Down
10 changes: 5 additions & 5 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Searchable
public function __construct(?string $keyword, array $fields = [])
{
$this->keyword = $keyword ?? '';
$this->fields = \array_filter($fields);
$this->fields = array_filter($fields);
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ protected function queryOnColumnUsing(
return $this->queryOnJsonColumnUsing($query, $field, $likeOperator, 'orWhere');
}

\tap($this->getFieldSearchFilter($field), function ($filter) use ($field, $query, $likeOperator, $whereOperator) {
tap($this->getFieldSearchFilter($field), function ($filter) use ($field, $query, $likeOperator, $whereOperator) {
$filter->validate($query)->apply(
$query,
$this->searchKeyword()
Expand Down Expand Up @@ -153,7 +153,7 @@ protected function queryOnJsonColumnUsing(
string $likeOperator,
string $whereOperator = 'where'
) {
\tap($this->getJsonFieldSearchFilter($field), function ($filter) use ($field, $query, $likeOperator, $whereOperator) {
tap($this->getJsonFieldSearchFilter($field), function ($filter) use ($field, $query, $likeOperator, $whereOperator) {
$filter->validate($query)->apply(
$query,
$this->searchKeyword()
Expand All @@ -177,7 +177,7 @@ protected function queryOnColumnUsingRelation(
Field $field,
string $likeOperator
): EloquentQueryBuilder {
\tap($this->getRelationSearchFilter($field), function ($filter) use ($field, $query, $likeOperator) {
tap($this->getRelationSearchFilter($field), function ($filter) use ($field, $query, $likeOperator) {
$filter->validate($query)->apply(
$query,
$this->searchKeyword()
Expand Down Expand Up @@ -220,7 +220,7 @@ protected function getJsonFieldSearchFilter(Field $field): Contracts\Filter\Filt
*/
protected function getRelationSearchFilter(Field $field): Contracts\Filter\Filter
{
[$relation, $column] = \explode('.', $field->getOriginalValue(), 2);
[$relation, $column] = explode('.', $field->getOriginalValue(), 2);

return new Filters\RelationSearch($relation, $column);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class Taxonomy
*/
public function __construct(?string $terms, array $rules = [], array $fields = [])
{
$this->rules = \array_filter($rules);
$this->rules = array_filter($rules);
$this->fields = $fields;

$this->terms = Terms::parse($terms ?? '', \array_keys($this->rules));
$this->terms = Terms::parse($terms ?? '', array_keys($this->rules));
}

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function matchTaggedConditions($query): void
}

foreach ($this->rules as $term => $callback) {
if (\strpos($term, ':*') !== false || \strpos($term, ':[]') !== false) {
if (strpos($term, ':*') !== false || strpos($term, ':[]') !== false) {
$value = $this->terms->where($term);

$query->unless(empty($value), static function ($query) use ($callback, $value) {
Expand Down
20 changes: 10 additions & 10 deletions src/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ public static function parse(string $term, array $rules)

$tags = Collection::make($rules)
->map(static function ($value) {
[$tag, ] = \explode(':', $value, 2);
[$tag, ] = explode(':', $value, 2);

return "{$tag}:";
})->all();

if (\preg_match_all('/([\w]+:\"[\w\s]*\"|[\w]+:[\w\S]+|[\w\S]+)\s?/', $term, $terms)) {
if (preg_match_all('/([\w]+:\"[\w\s]*\"|[\w]+:[\w\S]+|[\w\S]+)\s?/', $term, $terms)) {
foreach ($terms[1] as $index => $term) {
if (! Str::startsWith($term, $tags)) {
\array_push($basic, $term);
array_push($basic, $term);
} else {
\array_push($tagged, $term);
array_push($tagged, $term);
}
}
}

return new static(
\implode(' ', $basic),
implode(' ', $basic),
$tagged
);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public function is(string $term): bool
*/
public function where(string $term)
{
[$tag, $type] = \explode(':', $term, 2);
[$tag, $type] = explode(':', $term, 2);

$results = Collection::make($this->tagged())
->filter(static function ($value) use ($tag) {
Expand All @@ -115,15 +115,15 @@ public function where(string $term)
}

if ($type === '*') {
[, $value] = \explode(':', $results[0] ?? null, 2);
[, $value] = explode(':', $results[0] ?? null, 2);

return \trim($value, '"');
return trim($value, '"');
}

return $results->map(static function ($text) {
[, $value] = \explode(':', $text, 2);
[, $value] = explode(':', $text, 2);

return \trim($value, '"');
return trim($value, '"');
})->filter(static function ($text) {
return ! empty($text);
})->values()->all();
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function validColumnNameDataProvider()
return [
[new Expression('users.fullname')],
['fullname'],
[\str_pad('email', 64, 'x')],
[str_pad('email', 64, 'x')],
];
}

Expand All @@ -49,7 +49,7 @@ public function invalidColumnNameDataProvider()
{
return [
['email->"%27))%23injectedSQL'],
[\str_pad('email', 65, 'x')],
[str_pad('email', 65, 'x')],
[''],
[null],
];
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function validFieldNameDataProvider()
return [
[new Expression('users.fullname')],
['fullname'],
[\str_pad('email', 64, 'x')],
[str_pad('email', 64, 'x')],
];
}

Expand All @@ -48,7 +48,7 @@ public function validFieldNameDataProvider()
public function invalidFieldNameDataProvider()
{
return [
[\str_pad('email', 65, 'x')],
[str_pad('email', 65, 'x')],
[''],
[null],
];
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/OrderableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function invalidColumnNameDataProvider()
{
return [
['email->"%27))%23injectedSQL'],
[\str_pad('email', 65, 'x')],
[str_pad('email', 65, 'x')],
[''],
[null],
];
Expand Down

0 comments on commit bc35736

Please sign in to comment.