Skip to content

Commit 85b4b5f

Browse files
authored
Merge pull request #2 from DutchCodingCompany/upgrade/modernize
Modernize
2 parents 5337704 + bd95f65 commit 85b4b5f

File tree

13 files changed

+362
-108
lines changed

13 files changed

+362
-108
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
vendor
22
composer.lock
3-
.php_cs
4-
.php_cs.cache
3+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
6+
7+
$rules = [
8+
'array_indentation' => true,
9+
'array_syntax' => ['syntax' => 'short'],
10+
'binary_operator_spaces' => [
11+
'default' => 'single_space',
12+
],
13+
'blank_line_after_namespace' => true,
14+
'blank_line_after_opening_tag' => true,
15+
'blank_line_before_statement' => [
16+
'statements' => ['return'],
17+
],
18+
'braces' => true,
19+
'cast_spaces' => true,
20+
'class_attributes_separation' => [
21+
'elements' => [
22+
'const' => 'only_if_meta',
23+
'method' => 'one',
24+
'property' => 'one',
25+
'trait_import' => 'none',
26+
],
27+
],
28+
'class_definition' => [
29+
'multi_line_extends_each_single_line' => true,
30+
'single_item_single_line' => true,
31+
'single_line' => true,
32+
],
33+
'concat_space' => [
34+
'spacing' => 'none',
35+
],
36+
'constant_case' => ['case' => 'lower'],
37+
'declare_equal_normalize' => true,
38+
'elseif' => true,
39+
'encoding' => true,
40+
'full_opening_tag' => true,
41+
'fully_qualified_strict_types' => false,
42+
// added by Shift
43+
'function_declaration' => true,
44+
'function_typehint_space' => true,
45+
'general_phpdoc_tag_rename' => true,
46+
'heredoc_to_nowdoc' => true,
47+
'include' => true,
48+
'increment_style' => ['style' => 'post'],
49+
'indentation_type' => true,
50+
'linebreak_after_opening_tag' => true,
51+
'line_ending' => true,
52+
'lowercase_cast' => true,
53+
'lowercase_keywords' => true,
54+
'lowercase_static_reference' => true,
55+
'magic_method_casing' => true,
56+
'magic_constant_casing' => true,
57+
'method_argument_space' => [
58+
'on_multiline' => 'ignore',
59+
],
60+
'multiline_whitespace_before_semicolons' => [
61+
'strategy' => 'no_multi_line',
62+
],
63+
'native_function_casing' => true,
64+
'no_alias_functions' => true,
65+
'no_extra_blank_lines' => [
66+
'tokens' => [
67+
'extra',
68+
'throw',
69+
'use',
70+
'switch',
71+
'case',
72+
'default',
73+
],
74+
],
75+
'no_blank_lines_after_class_opening' => true,
76+
'no_blank_lines_after_phpdoc' => true,
77+
'no_closing_tag' => true,
78+
'no_empty_phpdoc' => true,
79+
'no_empty_statement' => true,
80+
'no_leading_import_slash' => true,
81+
'no_leading_namespace_whitespace' => true,
82+
'no_mixed_echo_print' => [
83+
'use' => 'echo',
84+
],
85+
'no_multiline_whitespace_around_double_arrow' => true,
86+
'no_short_bool_cast' => true,
87+
'no_singleline_whitespace_before_semicolons' => true,
88+
'no_spaces_after_function_name' => true,
89+
'no_spaces_around_offset' => [
90+
'positions' => [
91+
'inside',
92+
'outside',
93+
],
94+
],
95+
'no_spaces_inside_parenthesis' => true,
96+
'no_trailing_comma_in_list_call' => true,
97+
'no_trailing_comma_in_singleline_array' => true,
98+
'no_trailing_whitespace' => true,
99+
'no_trailing_whitespace_in_comment' => true,
100+
'no_unneeded_control_parentheses' => [
101+
'statements' => [
102+
'break',
103+
'clone',
104+
'continue',
105+
'echo_print',
106+
'return',
107+
'switch_case',
108+
'yield',
109+
],
110+
],
111+
'no_unreachable_default_argument_value' => true,
112+
'no_useless_return' => true,
113+
'no_whitespace_before_comma_in_array' => true,
114+
'no_whitespace_in_blank_line' => true,
115+
'normalize_index_brace' => true,
116+
'not_operator_with_successor_space' => true,
117+
'object_operator_without_whitespace' => true,
118+
'ordered_imports' => [
119+
'sort_algorithm' => 'alpha',
120+
'imports_order' => [
121+
'class',
122+
'function',
123+
'const',
124+
],
125+
],
126+
'psr_autoloading' => true,
127+
'phpdoc_indent' => true,
128+
'phpdoc_inline_tag_normalizer' => true,
129+
'phpdoc_no_access' => true,
130+
'phpdoc_no_package' => true,
131+
'phpdoc_no_useless_inheritdoc' => true,
132+
'phpdoc_scalar' => true,
133+
'phpdoc_single_line_var_spacing' => true,
134+
'phpdoc_summary' => false,
135+
'phpdoc_to_comment' => false,
136+
// override to preserve user preference
137+
'phpdoc_tag_type' => true,
138+
'phpdoc_trim' => true,
139+
'phpdoc_types' => true,
140+
'phpdoc_var_without_name' => true,
141+
'self_accessor' => true,
142+
'short_scalar_cast' => true,
143+
'simplified_null_return' => false,
144+
'single_blank_line_at_eof' => true,
145+
'single_blank_line_before_namespace' => true,
146+
'single_class_element_per_statement' => [
147+
'elements' => [
148+
'const',
149+
'property',
150+
],
151+
],
152+
'single_import_per_statement' => true,
153+
'single_line_after_imports' => true,
154+
'single_line_comment_style' => [
155+
'comment_types' => ['hash'],
156+
],
157+
'single_quote' => true,
158+
'space_after_semicolon' => true,
159+
'standardize_not_equals' => true,
160+
'switch_case_semicolon_to_colon' => true,
161+
'switch_case_space' => true,
162+
'ternary_operator_spaces' => true,
163+
'trailing_comma_in_multiline' => [
164+
'elements' => [
165+
'arrays',
166+
'parameters',
167+
],
168+
],
169+
'trim_array_spaces' => true,
170+
'types_spaces' => [
171+
'space' => 'single',
172+
],
173+
'unary_operator_spaces' => true,
174+
'visibility_required' => [
175+
'elements' => [
176+
'method',
177+
'property',
178+
'const',
179+
],
180+
],
181+
'whitespace_after_comma_in_array' => true,
182+
'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
183+
'simplified_if_return' => true,
184+
'method_chaining_indentation' => true,
185+
186+
'AdamWojs/phpdoc_force_fqcn_fixer' => true,
187+
];
188+
189+
$finder = Finder::create()
190+
->in([
191+
__DIR__.'/config',
192+
__DIR__.'/src',
193+
])
194+
->name('*.php')
195+
->notName('*.blade.php')
196+
->ignoreDotFiles(true)
197+
->ignoreVCS(true);
198+
199+
/** @var \PhpCsFixer\ConfigInterface&\PhpCsFixer\ParallelAwareConfigInterface $config */
200+
$config = (new Config)
201+
->setFinder($finder)
202+
->setRules($rules)
203+
->setRiskyAllowed(true)
204+
->setUsingCache(true)
205+
->registerCustomFixers([
206+
new \AdamWojs\PhpCsFixerPhpdocForceFQCN\Fixer\Phpdoc\ForceFQCNFixer(),
207+
]);
208+
209+
if (php_uname('s') === 'Darwin' && php_uname('m') === 'arm64') {
210+
// Probably running apple m1/m2, in which parallel is bugged.
211+
return $config;
212+
}
213+
214+
return $config->setParallelConfig(ParallelConfigFactory::detect());

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
"schema"
1010
],
1111
"require": {
12-
"php" : "^8.0",
13-
"laravel/framework": "^10.0 | ^11.0 | ^12.0",
12+
"php" : "^8.2",
13+
"laravel/framework": "^11.0 | ^12.0",
1414
"swaggest/json-schema": "^0.12.33"
1515
},
16+
"require-dev": {
17+
"adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0",
18+
"friendsofphp/php-cs-fixer": "^3.85",
19+
"phpstan/phpstan": "^2.1"
20+
},
1621
"autoload": {
1722
"psr-4": {
1823
"DutchCodingCompany\\LaravelJsonSchema\\": "src/"

config/json-schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
'schema-name' => '$1', // what part is used as schema name
2828
'recursive' => false,
2929
],
30-
];
30+
];

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src

resources/lang/en/validation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'error-message' => 'JSON validaton failed for :attribute.',
5+
'detailed-error-message' => 'JSON validation failed for :attribute. :details',
6+
];

src/Contracts/JsonSchemaValidationResult.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
namespace DutchCodingCompany\LaravelJsonSchema\Contracts;
44

5-
use Throwable;
65
use Swaggest\JsonSchema\SchemaContract;
6+
use Throwable;
77

88
interface JsonSchemaValidationResult
99
{
1010
public function passed(): bool;
11+
1112
public function failed(): bool;
1213

1314
public function getMessage(): ?string;
14-
public function getException(): ?Throwable;
1515

16-
public function withContext(string $schemaName, SchemaContract $schema, $data = null): JsonSchemaValidationResult;
16+
public function getException(): ?Throwable;
1717

1818
public function getSchemaName(): ?string;
19+
1920
public function getSchema(): ?SchemaContract;
20-
public function getData();
21-
}
21+
22+
public function getData(): ?string;
23+
}

src/Contracts/JsonSchemaValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface JsonSchemaValidator
66
{
7-
public function validate(string $schemaName, $data): JsonSchemaValidationResult;
8-
}
7+
public function validate(string $schemaName, string $data): JsonSchemaValidationResult;
8+
}

0 commit comments

Comments
 (0)