-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I get the following error when I try to use latest strauss in a new project:
[error] Syntax error, unexpected T_NAME_QUALIFIED, expecting T_STRING on line 20 Script php bin/strauss.phar handling the namespace-dependencies event returned with error code 1 Script @namespace-dependencies was called via post-install-cmd
I run it through PHPStorm AI and it said it might be due to PHP 8.0+ syntax that strauss can't handle currently?
Strauss uses nikic/PHP-Parser to parse and modify PHP code. If Strauss is using an older version of PHP-Parser, it can't understand PHP 8.0+ syntax tokens like T_NAME_QUALIFIED.
Here's my composer.json:
{
"scripts": {
"lint" : "mkdir -p logs; vendor/bin/phpcs -s > ./logs/log.txt",
"compat" : "vendor/bin/phpcs -d memory_limit=1024M -s -p includes --standard=PHPCompatibility --runtime-set php_version 8.2 --runtime-set testVersion 8.2",
"format": "vendor/bin/phpcbf -p",
"dist": "sh bin/dist.sh",
"namespace-dependencies": [
"sh -c 'test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/latest/download/strauss.phar'",
"php bin/strauss.phar",
"composer dump-autoload"
],
"post-install-cmd": [
"@namespace-dependencies"
],
"post-update-cmd": [
"@namespace-dependencies",
"composer dumpautoload"
]
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/SoaringLeads/wp-reusables"
}
],
"require": {
"php": ">=8.1.0",
"cybersource/rest-client-php": "*",
"soaringleads/wp-reusables": "dev-main"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"wp-coding-standards/wpcs": "^3.0",
"phpcompatibility/php-compatibility": "^9.0"
},
"autoload":{
"psr-4": {
"SoaringLeads\\Lefan\\" : "includes/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "8.1"
}
},
"extra": {
"strauss": {
"target_directory": "vendor-prefixed",
"namespace_prefix": "SoaringLeads\\Lefan\\",
"classmap_prefix": "SoaringLeads\\Lefan_",
"constant_prefix": "SOARINGLEADS_LEFAN_",
"packages": [
],
"update_call_sites": false,
"override_autoload": {
},
"exclude_from_copy": {
"packages": [
"cybersource/rest-client-php",
"soaringleads/wp-reusables"
],
"namespaces": [
],
"file_patterns": [
]
},
"exclude_from_prefix": {
"packages": [
"cybersource/rest-client-php",
"soaringleads/wp-reusables"
],
"namespaces": [
],
"file_patterns": [
]
},
"namespace_replacement_patterns" : {
},
"delete_vendor_packages": true,
"delete_vendor_files": false
}
}
}
Here I'm actually excluding both of the packages im requiring as an attempt to fix the issue but it seem to not make a difference. The soaringleads/wp-reusables is a simple library with currently one class that looks like this:
<?php
namespace SoaringLeads\WpReusables\Helpers;
class UtilitiesHelper
{
/**
* Helper function to sanitize text.
*
* @param array|int|string $text
*
* @return array|string|int
* @since 1.0.0
*/
public static function sanitizeText( array|string|int $text ): array|string|int {
return is_array( $text ) ? array_map( 'sanitize_text_field', stripslashes_deep( $text ) ) : sanitize_text_field( stripslashes_deep( $text ) );
}
/**
* Format a phone number to be consistent.
*
* @param string $phone_number
* @return string
* @since 1.0.0
*/
public static function formatPhoneNumber( string $phone_number ): string {
if ( empty( $phone_number ) ) {
return '';
}
// Remove all non-digit characters.
$phone_number = preg_replace( '/\D/', '', $phone_number );
if ( str_starts_with( $phone_number, '1' ) ) {
$phone_number = substr( $phone_number, 1 );
}
// Determine the area code.
if ( strlen( $phone_number ) > 11 ) {
return ''; // Invalid phone number.
} elseif ( strlen( $phone_number ) === 10 ) {
$area_code = substr( $phone_number, 0, 3 );
$phone_number = substr( $phone_number, 3 );
} else {
$area_code = '758';
}
// Format the phone number.
return '(' . $area_code . ') ' . substr( $phone_number, 0, 3 ) . '-' . substr( $phone_number, 3 );
}
}
I tried removing the union type from the package and bringing it down again but strauss still failed during the "performing replacements" step.
Any idea whats going on?