Skip to content

Commit 006e2ab

Browse files
authored
Bump minimum PHP version to 8.2; set PHPStan to level 8 (#184)
2 parents d182b0a + 92dc9f5 commit 006e2ab

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

.phpcs.xml.dist

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<!-- Strip the filepaths down to the relevant bit. -->
2525
<arg name="basepath" value="."/>
2626

27-
<!-- Check up to 8 files simultaneously. -->
28-
<arg name="parallel" value="8"/>
27+
<!-- Check up to 10 files simultaneously. -->
28+
<arg name="parallel" value="10"/>
2929

3030
<!--
3131
#############################################################################
@@ -55,19 +55,8 @@
5555
</rule>
5656

5757
<!-- Check code for cross-version PHP compatibility. -->
58-
<config name="testVersion" value="5.4-"/>
59-
<rule ref="PHPCompatibility">
60-
<!-- Exclude PHP constants back-filled by PHPCS. -->
61-
<exclude name="PHPCompatibility.Constants.NewConstants.t_finallyFound"/>
62-
<exclude name="PHPCompatibility.Constants.NewConstants.t_yieldFound"/>
63-
<exclude name="PHPCompatibility.Constants.NewConstants.t_ellipsisFound"/>
64-
<exclude name="PHPCompatibility.Constants.NewConstants.t_powFound"/>
65-
<exclude name="PHPCompatibility.Constants.NewConstants.t_pow_equalFound"/>
66-
<exclude name="PHPCompatibility.Constants.NewConstants.t_spaceshipFound"/>
67-
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesceFound"/>
68-
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesce_equalFound"/>
69-
<exclude name="PHPCompatibility.Constants.NewConstants.t_yield_fromFound"/>
70-
</rule>
58+
<config name="testVersion" value="7.2-"/>
59+
<rule ref="PHPCompatibility"/>
7160

7261
<!-- Enforce PSR1 compatible namespaces. -->
7362
<rule ref="PSR1.Classes.ClassDeclaration"/>

BigBite/Sniffs/Files/FileNameSniff.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ final class FileNameSniff extends Sniff {
129129
/**
130130
* Returns an array of tokens this test wants to listen for.
131131
*
132-
* @return array<int,int>
132+
* @return array<int|string,int|string>
133133
*/
134134
public function register() {
135135
if ( \defined( '\PHP_CODESNIFFER_IN_TESTS' ) ) {
@@ -302,9 +302,14 @@ protected function check_filename_is_hyphenated( $file_name ) {
302302
* @return bool
303303
*/
304304
protected function check_filename_has_class_prefix( $class_ptr, $file_name ) {
305-
$extension = strrchr( $file_name, '.' );
306-
$class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr );
307-
$properties = ObjectDeclarations::getClassProperties( $this->phpcsFile, $class_ptr );
305+
$extension = strrchr( $file_name, '.' );
306+
$class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr );
307+
$properties = ObjectDeclarations::getClassProperties( $this->phpcsFile, $class_ptr );
308+
309+
if ( null === $class_name ) {
310+
return true;
311+
}
312+
308313
$expected = 'class-' . $this->kebab( $class_name ) . $extension;
309314
$err_message = 'Class file names should be based on the class name with "class-" prepended. Expected %s, but found %s.';
310315

@@ -332,8 +337,13 @@ protected function check_filename_has_class_prefix( $class_ptr, $file_name ) {
332337
* @return bool
333338
*/
334339
protected function check_filename_has_trait_prefix( $trait_ptr, $file_name ) {
335-
$extension = strrchr( $file_name, '.' );
336-
$trait_name = ObjectDeclarations::getName( $this->phpcsFile, $trait_ptr );
340+
$extension = strrchr( $file_name, '.' );
341+
$trait_name = ObjectDeclarations::getName( $this->phpcsFile, $trait_ptr );
342+
343+
if ( null === $trait_name ) {
344+
return true;
345+
}
346+
337347
$expected = 'trait-' . $this->kebab( $trait_name ) . $extension;
338348
$err_message = 'Trait file names should be based on the trait name with "trait-" prepended. Expected %s, but found %s.';
339349

@@ -358,8 +368,13 @@ protected function check_filename_has_trait_prefix( $trait_ptr, $file_name ) {
358368
protected function check_filename_has_interface_prefix( $interface_ptr, $file_name ) {
359369
$extension = strrchr( $file_name, '.' );
360370
$interface_name = ObjectDeclarations::getName( $this->phpcsFile, $interface_ptr );
361-
$expected = 'interface-' . $this->kebab( $interface_name ) . $extension;
362-
$err_message = 'Interface file names should be based on the interface name with "interface-" prepended. Expected %s, but found %s.';
371+
372+
if ( null === $interface_name ) {
373+
return true;
374+
}
375+
376+
$expected = 'interface-' . $this->kebab( $interface_name ) . $extension;
377+
$err_message = 'Interface file names should be based on the interface name with "interface-" prepended. Expected %s, but found %s.';
363378

364379
if ( $file_name === $expected ) {
365380
return true;
@@ -380,8 +395,13 @@ protected function check_filename_has_interface_prefix( $interface_ptr, $file_na
380395
* @return bool
381396
*/
382397
protected function check_filename_has_enum_prefix( $enum_ptr, $file_name ) {
383-
$extension = strrchr( $file_name, '.' );
384-
$enum_name = ObjectDeclarations::getName( $this->phpcsFile, $enum_ptr );
398+
$extension = strrchr( $file_name, '.' );
399+
$enum_name = ObjectDeclarations::getName( $this->phpcsFile, $enum_ptr );
400+
401+
if ( null === $enum_name ) {
402+
return true;
403+
}
404+
385405
$expected = 'enum-' . $this->kebab( $enum_name ) . $extension;
386406
$err_message = 'Enum file names should be based on the enum name with "enum-" prepended. Expected %s, but found %s.';
387407

@@ -404,6 +424,11 @@ protected function check_filename_has_enum_prefix( $enum_ptr, $file_name ) {
404424
protected function kebab( $filename = '' ) {
405425
$kebab = preg_replace( '`[[:punct:]]`', '-', $filename );
406426
$kebab = preg_replace( '/(?>(?!^[A-Z]))([a-z])([A-Z])/', '$1-$2', $filename );
427+
428+
if ( null === $kebab ) {
429+
$kebab = $filename;
430+
}
431+
407432
$kebab = strtolower( $kebab );
408433
$kebab = str_replace( '_', '-', $kebab );
409434

BigBite/ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="BigBite" namespace="BigBiteCS\BigBite" xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd">
33
<config name="encoding" value="utf-8" />
4-
<config name="testVersion" value="7.4-" />
4+
<config name="testVersion" value="8.2-" />
55

66
<arg name="extensions" value="php" />
77
<arg name="parallel" value="75" />

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 7
2+
level: 8
33
paths:
44
- BigBite
55
bootstrapFiles:

0 commit comments

Comments
 (0)