coding-standard
coding-standard copied to clipboard
ClassStructureSniff individual methods configuration
Hello. I'd like to have my PHPUnit protected function setUp method placed before public test methods. But it looks like it is not possible to configure something like an exception or a custom group or something like that. Do you want to support such a feature? I made them public as a workaround.
Thanks
How would this be implemented? The ability to match several methods via regexp into a custom group, that one can then order in between the builtin groups?
If someone could draft a configuration, I would give it a try to implement
I'd also like something like this, could a (phpdoc) attribute like #[SlevomatCodingStandard\ClassStructure\Group('myCustomGroupName')] (and/or comparable PHPdoc tag) work to (optionally) override the automatically-determined group?
Something like (taken from a hypothetical datetime-library):
#[SlevomatCodingStandard\ClassStructure\Group('iso8601')]
public function toIso8601(): string
{
//should sort with other 'iso8601' tagged functions iff the 'iso8601' group is in the configuration, otherwise it should sort with the 'public methods'
}
#[SlevomatCodingStandard\ClassStructure\Group('iso8601')]
public static function fromIso8601(string $timestamp): DateTime
{
//should sort with other 'iso8601' tagged functions iff the 'iso8601' group is in the configuration, otherwise it should sort with the 'public static constructors'
}
It would also be good to be able to order/group methods by a specified PhpDoc tag (e.g. @api).
We face same issue.
class MyClass {
public function __construct() {
$this->boot();
}
private function boot() {}
}
OR
class MyClass {
public function __construct() {
$this->init();
}
private function init() {}
}
Either of these cases, I would like my boot() or init() to show up after __construct() but ClassStructureSniff moves it below other functions, sometimes at bottom of classes, which is not ideal. makes it hard to navigate the class.
would be nice if I could do something like:
<element value="constructor"/>
<element value="custom_boot"/>
or
<element value="custom_init"/>