Skip to content

Commit 77cc01d

Browse files
committed
Support Nova 5
1 parent cddf535 commit 77cc01d

File tree

4 files changed

+166
-8
lines changed

4 files changed

+166
-8
lines changed

.php-cs-fixer.php

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @see https://mlocati.github.io/php-cs-fixer-configurator/
7+
*/
8+
$finder = \PhpCsFixer\Finder::create()
9+
->in(__DIR__)
10+
->exclude(
11+
[
12+
'vendor',
13+
]
14+
)
15+
->name('*.php')
16+
->ignoreDotFiles(false)
17+
->ignoreVCS(true)
18+
->ignoreVCSIgnored(true);
19+
20+
return (new \PhpCsFixer\Config())
21+
->setUsingCache(true)
22+
->setRiskyAllowed(true)
23+
->setIndent(' ')
24+
->setLineEnding("\n")
25+
->setRules([
26+
// Basic PER Coding Style 2.0 ruleset plus our "fixes" for it
27+
'@PER-CS2.0' => true, // https://www.php-fig.org/per/coding-style/}
28+
// 'concat_space' => ['spacing' => 'none'], // make strings shorter "'hello' . $name . '!'" => "'hello'.$name.'!'"
29+
// 'blank_line_after_opening_tag' => false, // it makes "<?php declare(strict_types=1);" multiline (and more verbose)
30+
'function_declaration' => false, // It makes "fn ()" into "fn()" and conflicts with our PHPCS ruleset
31+
'single_line_empty_body' => false, // It has conflict with PSR2.Classes.ClassDeclaration.OpenBraceNewLine
32+
// 'unary_operator_spaces' => false, // It has conflict with PHPCS ruleset
33+
34+
// Additional rules on the top of PER-CS2
35+
// Please keep these rules alphabetically
36+
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'],
37+
'array_indentation' => true,
38+
'assign_null_coalescing_to_coalesce_equal' => true,
39+
'binary_operator_spaces' => ['default' => 'single_space'],
40+
'cast_spaces' => ['space' => 'single'],
41+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
42+
'declare_strict_types' => true,
43+
'explicit_string_variable' => true,
44+
// 'final_public_method_for_abstract_class' => true, // @todo enable it
45+
'general_phpdoc_annotation_remove' => [
46+
'annotations' => [
47+
'api',
48+
'access',
49+
'author',
50+
'category',
51+
'copyright',
52+
'created',
53+
'license',
54+
'link',
55+
'package',
56+
'since',
57+
'subpackage',
58+
'version',
59+
],
60+
],
61+
'modernize_types_casting' => true,
62+
'no_alias_functions' => true,
63+
'no_binary_string' => true,
64+
'no_empty_comment' => true,
65+
'no_empty_phpdoc' => true,
66+
'no_empty_statement' => true,
67+
'no_extra_blank_lines' => ['tokens' => ['extra', 'curly_brace_block']],
68+
'no_homoglyph_names' => true,
69+
'no_leading_namespace_whitespace' => true,
70+
'no_mixed_echo_print' => true,
71+
'no_short_bool_cast' => true,
72+
'no_singleline_whitespace_before_semicolons' => true,
73+
'no_spaces_around_offset' => true,
74+
'no_trailing_comma_in_singleline' => false, // it's a good marker that there are more elements in an array
75+
'no_unneeded_braces' => true,
76+
'no_unneeded_control_parentheses' => true,
77+
'no_unneeded_final_method' => true,
78+
'no_unreachable_default_argument_value' => true,
79+
'no_unused_imports' => true,
80+
'no_useless_concat_operator' => true,
81+
'no_useless_return' => true,
82+
'no_whitespace_before_comma_in_array' => true,
83+
'normalize_index_brace' => true,
84+
'nullable_type_declaration' => ['syntax' => 'question_mark'],
85+
'object_operator_without_whitespace' => true,
86+
/*
87+
* @see https://github.com/slevomat/coding-standard/issues/1620#issuecomment-1758006718
88+
* 'ordered_class_elements' => [
89+
'order' => [
90+
'use_trait',
91+
'constant',
92+
'case', // for enums only
93+
'property',
94+
'method',
95+
]
96+
],*/
97+
'php_unit_construct' => true,
98+
'php_unit_dedicate_assert' => ['target' => 'newest'],
99+
'php_unit_expectation' => true,
100+
'php_unit_fqcn_annotation' => true,
101+
'php_unit_method_casing' => ['case' => 'snake_case'],
102+
'php_unit_no_expectation_annotation' => true,
103+
'php_unit_set_up_tear_down_visibility' => true,
104+
'php_unit_strict' => true,
105+
'php_unit_test_annotation' => ['style' => 'annotation'],
106+
'php_unit_test_class_requires_covers' => true,
107+
'phpdoc_align' => ['align' => 'left'],
108+
'phpdoc_indent' => true,
109+
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
110+
'phpdoc_param_order' => true,
111+
'phpdoc_scalar' => true,
112+
'phpdoc_single_line_var_spacing' => true,
113+
'phpdoc_tag_casing' => true,
114+
'phpdoc_types' => true,
115+
'protected_to_private' => true,
116+
'psr_autoloading' => true,
117+
'self_accessor' => true,
118+
'self_static_accessor' => true,
119+
'single_line_comment_spacing' => true,
120+
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']],
121+
'space_after_semicolon' => true,
122+
'standardize_not_equals' => true,
123+
'strict_param' => true,
124+
'ternary_to_null_coalescing' => true,
125+
'trim_array_spaces' => true,
126+
'trailing_comma_in_multiline' => true,
127+
'type_declaration_spaces' => true,
128+
'types_spaces' => ['space' => 'single'],
129+
'whitespace_after_comma_in_array' => true,
130+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
131+
])
132+
->setFinder($finder);

composer.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"require": {
1212
"php": "^8.2",
1313
"ext-json": "*",
14-
"laravel/nova": "^4.25"
14+
"laravel/nova": "^4.25 || ^5.0"
1515
},
1616
"require-dev": {
17-
"orchestra/testbench": "^8.0 || ^9.0",
17+
"interaction-design-foundation/coding-standard": "^0.3.0",
18+
"orchestra/testbench-core": "^8.0 || ^9.0",
1819
"phpunit/phpunit": "^10.5 || ^11.0"
1920
},
2021
"repositories": [
@@ -36,7 +37,11 @@
3637
}
3738
},
3839
"config": {
39-
"sort-packages": true
40+
"sort-packages": true,
41+
"allow-plugins": {
42+
"dealerdirect/phpcodesniffer-composer-installer": true,
43+
"thecodingmachine/discovery": true
44+
}
4045
},
4146
"extra": {
4247
"laravel": {
@@ -46,6 +51,9 @@
4651
}
4752
},
4853
"scripts": {
54+
"cs": "@cs:fix",
55+
"cs:check": "phpcs -p -s --colors --report-full --report-summary",
56+
"cs:fix": "phpcbf -p --colors",
4957
"test": "phpunit --colors=always"
5058
}
5159
}

phpcs.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="IxDF Package Standard">
3+
<!-- Include all rules from the IxDF Coding Standard -->
4+
<rule ref="IxDFCodingStandard">
5+
<exclude ref="IxDFCodingStandard.Files.BemCasedFilename.InvalidCharacters"/>
6+
<exclude ref="SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal"/>
7+
<exclude ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName"/>
8+
</rule>
9+
10+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
11+
<exclude-pattern>./tests*</exclude-pattern>
12+
</rule>
13+
14+
<rule ref="Generic.Files.LineLength.TooLong">
15+
<severity>1</severity><!-- Temp hide the warn -->
16+
</rule>
17+
18+
<!-- Paths to check -->
19+
<file>src</file>
20+
<file>tests</file>
21+
</ruleset>

src/HtmlCode.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use Laravel\Nova\Fields\Textarea;
66

7-
/**
8-
* @phpcs:disable SlevomatCodingStandard.Classes.RequireAbstractOrFinal
9-
* @noRector \Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector
10-
*/
7+
/** @phpcs:disable SlevomatCodingStandard.Classes.RequireAbstractOrFinal */
118
class HtmlCode extends Textarea
129
{
1310
/**
@@ -40,7 +37,7 @@ public function previewTemplate($template): self
4037
$template = $template();
4138
}
4239

43-
if (strpos($template, '%CODE%') === false) {
40+
if (!str_contains($template, '%CODE%')) {
4441
throw new \InvalidArgumentException('%CODE% placeholder is not found in your template. Please add it.');
4542
}
4643

0 commit comments

Comments
 (0)