coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

ClassStructureSniff individual methods configuration

Open maryo opened this issue 5 years ago • 4 comments

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

maryo avatar Oct 12 '20 13:10 maryo

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

pscheit-lillydoo avatar Mar 03 '21 19:03 pscheit-lillydoo

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'
}

nederdirk avatar Jun 29 '21 12:06 nederdirk

It would also be good to be able to order/group methods by a specified PhpDoc tag (e.g. @api).

vhenzl avatar Oct 01 '21 10:10 vhenzl

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"/>

saas786 avatar Feb 17 '22 10:02 saas786