Rearrange code to move magic methods to end?
I'm trying to get the Rearrange Code feature to sort all my class methods alphabetically, except put the magic methods at the end.
I created a Rules Alias for the name:
And then updated my settings like so:
I created a class for testing, but it is always sorted like so:
<?php
class Foo implements ArrayAccess
{
public const BAR = 3;
protected array $data = [];
protected int $size = 0;
public function __construct()
{
$this->clear();
}
private function clear(): void
{
$this->data = [];
$this->updateSize();
}
public function updateSize(): void
{
$this->size = count($this->data);
}
public static function abc(): void {}
public function __get(mixed $key): mixed
{
return $this->offsetGet($key);
}
public function __set(mixed $key, mixed $value): void
{
$this->offsetSet($key, $value);
}
public function offsetGet(mixed $offset): mixed
{
return $this->data[$offset] ?? null;
}
public function offsetSet(mixed $offset, mixed $value): void
{
$this->data[$offset] = $value;
$this->updateSize();
}
public function offsetExists(mixed $offset): bool
{
return array_key_exists($offset, $this->data);
}
public function offsetUnset(mixed $offset): void
{
unset($this->data[$offset]);
$this->updateSize();
}
}
I would've expected the methods to be ordered like so:
- __construct
- abc
- clear
- offsetExists
- offsetGet
- offsetSet
- offsetUnset
- updateSize
- __get
- __set
It appears that it's still doing some kind of grouping. Am I doing something wrong?
FWIW, I'm using PhpStorm 2024.1.4 (Build #JBC-241.18034.69, built on June 21, 2024) … and this project is using Remote Development via SSH.
Please sign in to leave a comment.