Skip to content

Commit 308b41d

Browse files
committed
Pest, PhpStan and Pint
1 parent 2aec108 commit 308b41d

11 files changed

+338
-32
lines changed

.php-cs-fixer.php

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?php
2+
# PHPCS Fixer modified for Laravel Pint standards
3+
4+
declare(strict_types=1);
5+
6+
use PhpCsFixer\Config;
7+
use PhpCsFixer\Finder;
8+
9+
$rules = [
10+
'array_indentation' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'binary_operator_spaces' => [
13+
'default' => 'single_space',
14+
],
15+
'blank_line_after_namespace' => true,
16+
'blank_line_after_opening_tag' => true,
17+
'blank_line_before_statement' => [
18+
'statements' => [
19+
'continue',
20+
'return',
21+
],
22+
],
23+
'blank_line_between_import_groups' => true,
24+
'blank_lines_before_namespace' => true,
25+
'braces_position' => [
26+
'control_structures_opening_brace' => 'same_line',
27+
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
28+
'anonymous_functions_opening_brace' => 'same_line',
29+
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
30+
'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
31+
'allow_single_line_empty_anonymous_classes' => false,
32+
'allow_single_line_anonymous_functions' => false,
33+
],
34+
'cast_spaces' => true,
35+
'class_attributes_separation' => [
36+
'elements' => [
37+
'const' => 'one',
38+
'method' => 'one',
39+
'property' => 'one',
40+
'trait_import' => 'none',
41+
],
42+
],
43+
'class_definition' => [
44+
'multi_line_extends_each_single_line' => true,
45+
'single_item_single_line' => true,
46+
'single_line' => true,
47+
],
48+
'class_reference_name_casing' => true,
49+
'clean_namespace' => true,
50+
'compact_nullable_type_declaration' => true,
51+
'concat_space' => [
52+
'spacing' => 'none',
53+
],
54+
'constant_case' => ['case' => 'lower'],
55+
'control_structure_braces' => true,
56+
'control_structure_continuation_position' => [
57+
'position' => 'same_line',
58+
],
59+
'declare_equal_normalize' => true,
60+
'declare_parentheses' => true,
61+
'elseif' => true,
62+
'encoding' => true,
63+
'full_opening_tag' => true,
64+
'fully_qualified_strict_types' => false,
65+
'function_declaration' => true,
66+
'general_phpdoc_tag_rename' => true,
67+
'heredoc_to_nowdoc' => true,
68+
'include' => true,
69+
'increment_style' => ['style' => 'post'],
70+
'indentation_type' => true,
71+
'integer_literal_case' => true,
72+
'lambda_not_used_import' => true,
73+
'line_ending' => true,
74+
'linebreak_after_opening_tag' => true,
75+
'list_syntax' => true,
76+
'lowercase_cast' => true,
77+
'lowercase_keywords' => true,
78+
'lowercase_static_reference' => true,
79+
'magic_constant_casing' => true,
80+
'magic_method_casing' => true,
81+
'method_argument_space' => [
82+
'on_multiline' => 'ignore',
83+
],
84+
'method_chaining_indentation' => true,
85+
'multiline_whitespace_before_semicolons' => [
86+
'strategy' => 'no_multi_line',
87+
],
88+
'native_function_casing' => true,
89+
'native_type_declaration_casing' => true,
90+
'no_alias_functions' => true,
91+
'no_alias_language_construct_call' => true,
92+
'no_alternative_syntax' => true,
93+
'no_binary_string' => true,
94+
'no_blank_lines_after_class_opening' => true,
95+
'no_blank_lines_after_phpdoc' => true,
96+
'no_closing_tag' => true,
97+
'no_empty_phpdoc' => true,
98+
'no_empty_statement' => true,
99+
'no_extra_blank_lines' => [
100+
'tokens' => [
101+
'extra',
102+
'throw',
103+
'use',
104+
],
105+
],
106+
'no_leading_import_slash' => true,
107+
'no_leading_namespace_whitespace' => true,
108+
'no_mixed_echo_print' => [
109+
'use' => 'echo',
110+
],
111+
'no_multiline_whitespace_around_double_arrow' => true,
112+
'no_multiple_statements_per_line' => true,
113+
'no_short_bool_cast' => true,
114+
'no_singleline_whitespace_before_semicolons' => true,
115+
'no_space_around_double_colon' => true,
116+
'no_spaces_after_function_name' => true,
117+
'no_spaces_around_offset' => [
118+
'positions' => ['inside', 'outside'],
119+
],
120+
'no_superfluous_phpdoc_tags' => [
121+
'allow_mixed' => true,
122+
'allow_unused_params' => true,
123+
],
124+
'no_trailing_comma_in_singleline' => true,
125+
'no_trailing_whitespace' => true,
126+
'no_trailing_whitespace_in_comment' => true,
127+
'no_unneeded_control_parentheses' => [
128+
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
129+
],
130+
'no_unneeded_braces' => true,
131+
'no_unreachable_default_argument_value' => true,
132+
'no_unset_cast' => true,
133+
'no_unused_imports' => true,
134+
'no_useless_return' => true,
135+
'no_whitespace_before_comma_in_array' => true,
136+
'no_whitespace_in_blank_line' => true,
137+
'normalize_index_brace' => true,
138+
'not_operator_with_successor_space' => true,
139+
'nullable_type_declaration' => true,
140+
'nullable_type_declaration_for_default_null_value' => true,
141+
'object_operator_without_whitespace' => true,
142+
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['const', 'class', 'function']],
143+
'ordered_interfaces' => true,
144+
'ordered_traits' => true,
145+
'phpdoc_align' => [
146+
'align' => 'left',
147+
'spacing' => [
148+
'param' => 2,
149+
],
150+
],
151+
'phpdoc_indent' => true,
152+
'phpdoc_inline_tag_normalizer' => true,
153+
'phpdoc_no_access' => true,
154+
'phpdoc_no_package' => true,
155+
'phpdoc_no_useless_inheritdoc' => true,
156+
'phpdoc_order' => [
157+
'order' => ['param', 'return', 'throws'],
158+
],
159+
'phpdoc_scalar' => true,
160+
'phpdoc_separation' => [
161+
'groups' => [
162+
['deprecated', 'link', 'see', 'since'],
163+
['author', 'copyright', 'license'],
164+
['category', 'package', 'subpackage'],
165+
['property', 'property-read', 'property-write'],
166+
['param', 'return'],
167+
],
168+
],
169+
'phpdoc_single_line_var_spacing' => true,
170+
'phpdoc_summary' => false,
171+
'phpdoc_tag_type' => [
172+
'tags' => [
173+
'inheritdoc' => 'inline',
174+
],
175+
],
176+
'phpdoc_to_comment' => false,
177+
'phpdoc_trim' => true,
178+
'phpdoc_types' => true,
179+
'phpdoc_var_without_name' => true,
180+
'psr_autoloading' => false,
181+
'return_type_declaration' => ['space_before' => 'none'],
182+
'self_accessor' => false,
183+
'self_static_accessor' => true,
184+
'short_scalar_cast' => true,
185+
'simplified_null_return' => false,
186+
'single_blank_line_at_eof' => true,
187+
'single_class_element_per_statement' => [
188+
'elements' => ['const', 'property'],
189+
],
190+
'single_import_per_statement' => true,
191+
'single_line_after_imports' => true,
192+
'single_line_comment_style' => [
193+
'comment_types' => ['hash'],
194+
],
195+
'single_line_empty_body' => true,
196+
'single_quote' => true,
197+
'single_space_around_construct' => true,
198+
'space_after_semicolon' => true,
199+
'spaces_inside_parentheses' => true,
200+
'standardize_not_equals' => true,
201+
'statement_indentation' => true,
202+
'switch_case_semicolon_to_colon' => true,
203+
'switch_case_space' => true,
204+
'ternary_operator_spaces' => true,
205+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
206+
'trim_array_spaces' => true,
207+
'type_declaration_spaces' => true,
208+
'types_spaces' => true,
209+
'unary_operator_spaces' => true,
210+
'visibility_required' => [
211+
'elements' => ['method', 'property'],
212+
],
213+
'whitespace_after_comma_in_array' => true,
214+
'yoda_style' => [
215+
'always_move_variable' => false,
216+
'equal' => false,
217+
'identical' => false,
218+
'less_and_greater' => false,
219+
],
220+
'declare_strict_types' => true,
221+
'explicit_string_variable' => true,
222+
];
223+
224+
$finder = Finder::create()
225+
->in([
226+
__DIR__.'/src',
227+
__DIR__.'/tests',
228+
])
229+
->name('*.php')
230+
->notName('*.blade.php')
231+
->ignoreDotFiles(true)
232+
->ignoreVCS(true);
233+
234+
$config = new Config();
235+
236+
return $config->setFinder($finder)
237+
->setRules($rules)
238+
->setRiskyAllowed(true)
239+
->setUsingCache(true);

composer.json

+31-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"license": "MIT",
2020
"require": {
2121
"php": "^8.2",
22-
"illuminate/support": "^10.0|^11.0",
23-
"illuminate/container": "^10.0|^11.0",
24-
"illuminate/database": "^10.0|^11.0",
25-
"illuminate/events": "^10.0|^11.0",
26-
"opensearch-project/opensearch-php": "^2.4",
22+
"illuminate/container": "^10.0|^11|^12",
23+
"illuminate/database": "^10.30|^11|^12",
24+
"illuminate/events": "^10.0|^11|^12",
25+
"illuminate/support": "^10.0|^11|^12",
26+
"opensearch-project/opensearch-php": "2.3.1",
2727
"spatie/ignition": "^1.15"
2828
},
2929
"require-dev": {
@@ -64,5 +64,31 @@
6464
"dealerdirect/phpcodesniffer-composer-installer": true,
6565
"phpstan/extension-installer": true
6666
}
67+
},
68+
"scripts": {
69+
"post-autoload-dump": [
70+
"@clear",
71+
"@prepare"
72+
],
73+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
74+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
75+
"build": "@php vendor/bin/testbench workbench:build --ansi",
76+
"serve": [
77+
"Composer\\Config::disableProcessTimeout",
78+
"@build",
79+
"@php vendor/bin/testbench serve"
80+
],
81+
"lint": "pint -v",
82+
"types": "phpstan analyse --ansi --memory-limit=2G",
83+
"pest": "pest --colors=always",
84+
"test:lint": "pint --test -v",
85+
"test:types": "phpstan analyse --ansi",
86+
"test:unit": "pest --colors=always",
87+
"test": [
88+
"Composer\\Config::disableProcessTimeout",
89+
"@test:lint",
90+
"@test:types",
91+
"@test:unit"
92+
]
6793
}
6894
}

phpstan-baseline.neon

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:push\\(\\) invoked with 3 parameters, 0 required\\.$#"
5+
count: 2
6+
path: src/Relations/BelongsToMany.php
7+
8+
-
9+
message: "#^Method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:push\\(\\) invoked with 3 parameters, 0 required\\.$#"
10+
count: 6
11+
path: src/Relations/MorphToMany.php

phpstan.neon.dist

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 2
6+
7+
paths:
8+
- src
9+
10+
tmpDir: build/phpstan
11+
12+
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
13+
14+
ignoreErrors:
15+
- '#Unsafe usage of new static#'
16+
- identifier: class.nameCase
17+
- '#Call to an undefined method [a-zA-Z0-9\\_\<\>\(\)]+::[a-zA-Z]+\(\)#'
18+
19+
20+
universalObjectCratesClasses:
21+
- Illuminate\Support\Fluent
22+
23+
services:
24+
errorFormatter.sarif:
25+
class: PDPhilip\OpenSearch\Tests\PHPStan\SarifErrorFormatter
26+
arguments:
27+
relativePathHelper: @simpleRelativePathHelper
28+
currentWorkingDirectory: %currentWorkingDirectory%
29+
pretty: true

src/Connection.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
use function array_replace_recursive;
2828
use function is_array;
29-
use function strtolower;
3029

3130
/**
3231
* @mixin Client
@@ -128,7 +127,6 @@ private function sanitizeConfig(): void
128127
$this->config
129128
);
130129

131-
$this->config['auth_type'] = strtolower($this->config['auth_type']);
132130
}
133131

134132
public function setOptions(): void
@@ -233,7 +231,7 @@ public function disconnect(): void
233231
// ----------------------------------------------------------------------
234232
// Connection getters
235233
// ----------------------------------------------------------------------
236-
public function getClient(): ?Client
234+
public function getClient(): ?OpenClient
237235
{
238236
return $this->connection;
239237
}

src/Exceptions/QueryException.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace PDPhilip\OpenSearch\Exceptions;
66

77
use Exception;
8+
use OpenSearch\Common\Exceptions\ClientErrorResponseException;
9+
use OpenSearch\Common\Exceptions\Missing404Exception;
810

911
final class QueryException extends Exception
1012
{
@@ -38,8 +40,8 @@ private function formatMessage(Exception $result): string
3840
{
3941
// Clean that ish up.
4042
return match (get_class($result)) {
41-
MissingParameterException::class => $this->formatMissingParameterException($result),
42-
ClientResponseException::class => $this->routeClientResponseException($result),
43+
Missing404Exception::class => $this->formatMissingParameterException($result),
44+
ClientErrorResponseException::class => $this->routeClientResponseException($result),
4345
default => $result->getMessage(),
4446
};
4547
}

src/OpenClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function search(array $params = [])
2323

2424
public function count(array $params = []): int
2525
{
26-
return $this->client->count($params)->asArray()['count'] ?? 0;
26+
return $this->client->count($params)['count'] ?? 0;
2727
}
2828

2929
public function bulk(array $params = [])

0 commit comments

Comments
 (0)