diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist
index 3cdab48..d8f8f34 100644
--- a/.phpcs.xml.dist
+++ b/.phpcs.xml.dist
@@ -24,8 +24,8 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/BigBite/Sniffs/Files/FileNameSniff.php b/BigBite/Sniffs/Files/FileNameSniff.php
index ad0ad44..e742e6b 100644
--- a/BigBite/Sniffs/Files/FileNameSniff.php
+++ b/BigBite/Sniffs/Files/FileNameSniff.php
@@ -129,7 +129,7 @@ final class FileNameSniff extends Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
- * @return array
+ * @return array
*/
public function register() {
if ( \defined( '\PHP_CODESNIFFER_IN_TESTS' ) ) {
@@ -302,9 +302,14 @@ protected function check_filename_is_hyphenated( $file_name ) {
* @return bool
*/
protected function check_filename_has_class_prefix( $class_ptr, $file_name ) {
- $extension = strrchr( $file_name, '.' );
- $class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr );
- $properties = ObjectDeclarations::getClassProperties( $this->phpcsFile, $class_ptr );
+ $extension = strrchr( $file_name, '.' );
+ $class_name = ObjectDeclarations::getName( $this->phpcsFile, $class_ptr );
+ $properties = ObjectDeclarations::getClassProperties( $this->phpcsFile, $class_ptr );
+
+ if ( null === $class_name ) {
+ return true;
+ }
+
$expected = 'class-' . $this->kebab( $class_name ) . $extension;
$err_message = 'Class file names should be based on the class name with "class-" prepended. Expected %s, but found %s.';
@@ -332,8 +337,13 @@ protected function check_filename_has_class_prefix( $class_ptr, $file_name ) {
* @return bool
*/
protected function check_filename_has_trait_prefix( $trait_ptr, $file_name ) {
- $extension = strrchr( $file_name, '.' );
- $trait_name = ObjectDeclarations::getName( $this->phpcsFile, $trait_ptr );
+ $extension = strrchr( $file_name, '.' );
+ $trait_name = ObjectDeclarations::getName( $this->phpcsFile, $trait_ptr );
+
+ if ( null === $trait_name ) {
+ return true;
+ }
+
$expected = 'trait-' . $this->kebab( $trait_name ) . $extension;
$err_message = 'Trait file names should be based on the trait name with "trait-" prepended. Expected %s, but found %s.';
@@ -358,8 +368,13 @@ protected function check_filename_has_trait_prefix( $trait_ptr, $file_name ) {
protected function check_filename_has_interface_prefix( $interface_ptr, $file_name ) {
$extension = strrchr( $file_name, '.' );
$interface_name = ObjectDeclarations::getName( $this->phpcsFile, $interface_ptr );
- $expected = 'interface-' . $this->kebab( $interface_name ) . $extension;
- $err_message = 'Interface file names should be based on the interface name with "interface-" prepended. Expected %s, but found %s.';
+
+ if ( null === $interface_name ) {
+ return true;
+ }
+
+ $expected = 'interface-' . $this->kebab( $interface_name ) . $extension;
+ $err_message = 'Interface file names should be based on the interface name with "interface-" prepended. Expected %s, but found %s.';
if ( $file_name === $expected ) {
return true;
@@ -380,8 +395,13 @@ protected function check_filename_has_interface_prefix( $interface_ptr, $file_na
* @return bool
*/
protected function check_filename_has_enum_prefix( $enum_ptr, $file_name ) {
- $extension = strrchr( $file_name, '.' );
- $enum_name = ObjectDeclarations::getName( $this->phpcsFile, $enum_ptr );
+ $extension = strrchr( $file_name, '.' );
+ $enum_name = ObjectDeclarations::getName( $this->phpcsFile, $enum_ptr );
+
+ if ( null === $enum_name ) {
+ return true;
+ }
+
$expected = 'enum-' . $this->kebab( $enum_name ) . $extension;
$err_message = 'Enum file names should be based on the enum name with "enum-" prepended. Expected %s, but found %s.';
@@ -404,6 +424,11 @@ protected function check_filename_has_enum_prefix( $enum_ptr, $file_name ) {
protected function kebab( $filename = '' ) {
$kebab = preg_replace( '`[[:punct:]]`', '-', $filename );
$kebab = preg_replace( '/(?>(?!^[A-Z]))([a-z])([A-Z])/', '$1-$2', $filename );
+
+ if ( null === $kebab ) {
+ $kebab = $filename;
+ }
+
$kebab = strtolower( $kebab );
$kebab = str_replace( '_', '-', $kebab );
diff --git a/BigBite/ruleset.xml b/BigBite/ruleset.xml
index 38f2403..aa5bd0d 100644
--- a/BigBite/ruleset.xml
+++ b/BigBite/ruleset.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/phpstan.neon b/phpstan.neon
index 08c5fc4..7b1eb26 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,5 +1,5 @@
parameters:
- level: 7
+ level: 8
paths:
- BigBite
bootstrapFiles: