Description
What needs to be done?
Implement a method removeClassAttribute(string $className, string $attributeName) which processes a PHP source file containing a class definition and removes all attributes with the given attribute name from the class declaration.
- The method must locate the class by
$className. - If the class is not found, the method should show an error and leave the file unchanged.
- If the class has multiple attributes with the same name, all must be removed.
- If the class has multiple attributes with the same name, in different places (with the class and it's methods), only class-related attributes must be removed.
- Support standard PHP 8 attribute syntax with possible multiple attributes in one
#[...] block separated by commas. - If the class does not have the specified attribute, exit without error and file changes.
- Examples: to remove
Fillable attribute on class User declared as #[Fillable([...])] or multiple attributes like #[MyAttribute(1234), MyAttribute(5678)].
Expected Outcome
What is the expected result?
- The PHP source code file is updated with all occurrences of the specified attribute removed from the class declaration of the given class name.
- If no matching class is in the file, report error and no change.
- No errors if attribute is not present, and file remains unchanged.
- Multiple attributes in one attribute block are correctly handled, removing only the named attributes but keeping others.
- The syntax and structure of other code remains intact.
Verification Scenarios
How can this be tested?
- Run
removeClassAttribute on a PHP file with a single class having one attribute: verify the attribute is removed. - Run on a class with multiple attributes including multiple instances of the target attribute: all instances removed, others remain.
- Run on a file without the specified class: verify error reported, file unchanged.
- Run on a class with no matching attribute: verify no error and no file change.
- Run on a class with sevaral same name attributes of the class and method: verify only class-related attributes removed.
- Test attributes declared with multiple attributes per block.
- Ensure output is valid PHP syntax after attribute removal.
- Confirm no debug information or errors in the output.
Resources
Materials (Screenshots, Figma Links, References)
Description
What needs to be done?
Implement a method
removeClassAttribute(string $className, string $attributeName)which processes a PHP source file containing a class definition and removes all attributes with the given attribute name from the class declaration.$className.#[...]block separated by commas.Fillableattribute on classUserdeclared as#[Fillable([...])]or multiple attributes like#[MyAttribute(1234), MyAttribute(5678)].Expected Outcome
What is the expected result?
Verification Scenarios
How can this be tested?
removeClassAttributeon a PHP file with a single class having one attribute: verify the attribute is removed.Resources
Materials (Screenshots, Figma Links, References)
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
data-testid="icon"