Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
- attach_workspace:
at: .
- run:
name: PHP CS Fixer
command: |
mkdir -p ./logs/phpcsfixer
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run --format=junit > logs/phpcsfixer/junit.xml
name: Pint
command: |
mkdir -p ./logs/pint
vendor/bin/pint --test --format=junit > logs/pint/junit.xml
Comment on lines 35 to +39

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanius ⬆️ ?

- run:
name: PHPCS
command: |
Expand Down
34 changes: 0 additions & 34 deletions .php-cs-fixer.php

This file was deleted.

3 changes: 1 addition & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
preset: laravel

enabled:
- length_ordered_imports
- concat_with_spaces

disabled:
- alpha_ordered_imports
- class_definition
- concat_without_spaces
- laravel_braces
- laravel_phpdoc_alignment
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"friendsofphp/php-cs-fixer": "^3.7",
"squizlabs/php_codesniffer": "^3.6",
"orchestra/testbench": "^9.0|^10.0"
"orchestra/testbench": "^9.0|^10.0",
"laravel/pint": "^1.30"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion database/factories/TicketFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TestMonitor\Searchable\Database\Factories;

use TestMonitor\Searchable\Test\Models\Ticket;
use Illuminate\Database\Eloquent\Factories\Factory;
use TestMonitor\Searchable\Test\Models\Ticket;

class TicketFactory extends Factory
{
Expand Down
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TestMonitor\Searchable\Database\Factories;

use TestMonitor\Searchable\Test\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use TestMonitor\Searchable\Test\Models\User;

class UserFactory extends Factory
{
Expand Down
99 changes: 14 additions & 85 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,89 +1,18 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>The coding standard for PHP_CodeSniffer itself.</description>

<!--<file>app</file>-->

<exclude-pattern>*/Standards/*/Tests/*.(inc|css|js)</exclude-pattern>
<ruleset name="eloquent-revisable">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS is not in the title?

<file>src/</file>

<arg name="basepath" value="."/>
<arg name="colors" />
<arg name="parallel" value="75" />
<arg value="np"/>

<!-- Don't hide tokenizer exceptions -->
<rule ref="Internal.Tokenizer.Exception">
<type>error</type>
<arg name="colors"/>
<arg name="parallel" value="75"/>

<rule ref="PSR12">
<!-- Allow new ClassName without parentheses -->
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
<!-- Allow empty constructor body on one line: public function __construct(...) {} -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
<!-- Allow multiple arguments per line in a multi-line function call -->
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments"/>
</rule>

<!-- Include the whole PSR1 standard -->
<rule ref="PSR1"/>

<!-- Include the whole PSR2 standard -->
<rule ref="PSR2"/>

<!-- Include the PEAR standard, with a few exceptions -->
<rule ref="PEAR">
<exclude name="PEAR.Commenting.ClassComment" />
<exclude name="PEAR.Commenting.FileComment" />
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn" />
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag" />
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment" />
<exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParamType" />
<exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParamName" />
<exclude name="PEAR.Files.IncludingFile" />
<exclude name="PEAR.Functions.FunctionCallSignature" />
<exclude name="PEAR.NamingConventions.ValidFunctionName" />
<exclude name="PEAR.NamingConventions.ValidVariableName" />
<exclude name="PEAR.WhiteSpace.ObjectOperatorIndent" />
</rule>

<!-- Include some sniffs from other standards that don't conflict with PEAR -->
<rule ref="Squiz.Commenting.DocCommentAlignment" />
<rule ref="Squiz.Commenting.EmptyCatchComment" />
<rule ref="Squiz.Commenting.PostStatementComment" />
<rule ref="Squiz.Commenting.VariableComment" />
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing" />

<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>

<rule ref="Zend.Files.ClosingTag"/>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.Commenting.BlockComment">
<exclude name="Squiz.Commenting.BlockComment.LineIndent" />
<exclude name="Squiz.Commenting.BlockComment.FirstLineIndent" />
</rule>

<rule ref="Squiz.Formatting.OperatorBracket">
<exclude name="Squiz.Formatting.OperatorBracket.MissingBrackets" />
</rule>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.NamingConventions.ValidVariableName">
<exclude name="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
</rule>

<!-- Only one argument per line in multi-line function calls -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>

<!-- Only one argument per line in multi-line function calls -->
<rule ref="Generic.Commenting.DocComment">
<exclude name="Generic.Commenting.DocComment.TagValueIndent" />
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="Generic.Commenting.DocComment.NonParamGroup" />
</rule>

</ruleset>
</ruleset>
11 changes: 11 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"preset": "laravel",
"rules": {
"concat_space": {
"spacing": "one"
},
"phpdoc_align": {
"align": "left"
}
}
}
31 changes: 2 additions & 29 deletions src/Aspects/SearchAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,23 @@

namespace TestMonitor\Searchable\Aspects;

use TestMonitor\Searchable\Weights;
use Illuminate\Database\Eloquent\Builder;
use TestMonitor\Searchable\Contracts\Search;
use TestMonitor\Searchable\Weights;

class SearchAspect
{
/**
* @param string $name
* @param \TestMonitor\Searchable\Contracts\Search $searchClass
* @param int $weight
*/
public function __construct(protected string $name, protected Search $searchClass, protected int $weight = 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually add a newline for each argument?

{
//
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \TestMonitor\Searchable\Weights $weights
* @param string $term
*/
public function search(Builder $query, Weights $weights, string $term): void
{
($this->searchClass)($query, $weights, $this->name, $term, $this->weight);
}

/**
* @param string $name
* @param int $weight
* @return \App\Models\Search\SearchAspect
*/
Comment on lines 21 to 23
public static function exact(string $name, int $weight = 1): self
Expand All @@ -38,8 +27,6 @@ public static function exact(string $name, int $weight = 1): self
}

/**
* @param string $name
* @param int $weight
* @return \App\Models\Search\SearchAspect
*/
public static function partial(string $name, int $weight = 1): self
Expand All @@ -48,10 +35,6 @@ public static function partial(string $name, int $weight = 1): self
}

/**
* @param string $name
* @param string $prefix
* @param bool $exact
* @param int $weight
* @return \App\Models\Search\SearchAspect
*/
public static function prefix(string $name, string $prefix, bool $exact = false, int $weight = 1): self
Expand All @@ -60,8 +43,6 @@ public static function prefix(string $name, string $prefix, bool $exact = false,
}

/**
* @param string $name
* @param int $weight
* @return \App\Models\Search\SearchAspect
*/
public static function json(string $name, int $weight = 1): self
Expand All @@ -70,26 +51,18 @@ public static function json(string $name, int $weight = 1): self
}

/**
* @param string $name
* @param \TestMonitor\Searchable\Contracts\Search $searchClass
* @return \App\Models\Search\SearchAspect
*/
public static function custom(string $name, Search $searchClass): self
{
return new self($name, $searchClass);
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @return int
*/
public function getWeight(): int
{
return $this->weight;
Expand Down
32 changes: 7 additions & 25 deletions src/Aspects/SearchExact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace TestMonitor\Searchable\Aspects;

use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use TestMonitor\Searchable\Weights;
use Illuminate\Database\Eloquent\Builder;
use TestMonitor\Searchable\Contracts\Search;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use TestMonitor\Searchable\Concerns\ExtractsQuotedPhrases;
use TestMonitor\Searchable\Contracts\Search;
use TestMonitor\Searchable\Weights;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
Expand All @@ -19,21 +20,13 @@ class SearchExact implements Search
{
use ExtractsQuotedPhrases;

/**
* @var array
*/
protected array $relationConstraints = [];

/**
* @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query
* @param \TestMonitor\Searchable\Weights $weights
* @param string $property
* @param string $term
* @param int $weight
* @param Builder<Model> $query
* @return mixed
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
Comment thread
thijskok marked this conversation as resolved.
public function __invoke(Builder $query, Weights $weights, string $property, string $term, int $weight = 1): void
{
Expand All @@ -48,11 +41,6 @@ public function __invoke(Builder $query, Weights $weights, string $property, str
$weights->registerIf(empty($this->relationConstraints), $query, $weight);
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $property
* @return bool
*/
protected function isRelationProperty(Builder $query, string $property): bool
{
if (! Str::contains($property, '.')) {
Expand All @@ -69,12 +57,6 @@ protected function isRelationProperty(Builder $query, string $property): bool
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \TestMonitor\Searchable\Weights $weights
* @param string $property
* @param string $term
* @param int $weight
*
* @throws \RuntimeException
*/
protected function withRelationConstraint(
Expand Down
Loading