diff --git a/ecs.php b/ecs.php index e8514ef0..94c025c6 100644 --- a/ecs.php +++ b/ecs.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer; use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer; @@ -17,4 +19,37 @@ BlankLineAfterStrictTypesFixer::class, BlankLineAfterOpeningTagFixer::class, NoUnusedImportsFixer::class, - ]); + ]) + ->withConfiguredRule( + OrderedClassElementsFixer::class, + [ + 'order' => [ + 'use_trait', + 'case', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + ], + 'sort_algorithm' => 'none', + ], + ) + ->withConfiguredRule( + ClassAttributesSeparationFixer::class, + [ + 'elements' => [ + 'const' => 'one', + 'property' => 'one', + 'method' => 'one', + ], + ], + ); diff --git a/src/FreeDSx/Ldap/ClientOptions.php b/src/FreeDSx/Ldap/ClientOptions.php index ab3d1b0d..53f4f995 100644 --- a/src/FreeDSx/Ldap/ClientOptions.php +++ b/src/FreeDSx/Ldap/ClientOptions.php @@ -202,7 +202,6 @@ public function getSslCaCert(): ?string return $this->sslCaCert; } - public function setSslCaCert(?string $sslCaCert): self { $this->sslCaCert = $sslCaCert; diff --git a/src/FreeDSx/Ldap/Container.php b/src/FreeDSx/Ldap/Container.php index c796e0ee..00829c7a 100644 --- a/src/FreeDSx/Ldap/Container.php +++ b/src/FreeDSx/Ldap/Container.php @@ -59,11 +59,6 @@ class Container { - /** - * @var array - */ - private array $instanceFactory = []; - /** * These are classes that should never cache an instance when retrieved from the container. */ @@ -72,6 +67,11 @@ class Container ServerAuthorization::class, ]; + /** + * @var array + */ + private array $instanceFactory = []; + /** * @var array */ diff --git a/src/FreeDSx/Ldap/Control/Control.php b/src/FreeDSx/Ldap/Control/Control.php index 6a840832..b2de37df 100644 --- a/src/FreeDSx/Ldap/Control/Control.php +++ b/src/FreeDSx/Ldap/Control/Control.php @@ -100,6 +100,11 @@ public function __construct( protected AbstractType|ProtocolElementInterface|string|null $controlValue = null, ) {} + public function __toString(): string + { + return $this->controlType; + } + public function setTypeOid(string $oid): static { $this->controlType = $oid; @@ -164,11 +169,6 @@ public function toAsn1(): SequenceType return $asn1; } - public function __toString(): string - { - return $this->controlType; - } - /** * {@inheritDoc} * diff --git a/src/FreeDSx/Ldap/Controls.php b/src/FreeDSx/Ldap/Controls.php index a509374d..f4c13fd5 100644 --- a/src/FreeDSx/Ldap/Controls.php +++ b/src/FreeDSx/Ldap/Controls.php @@ -124,7 +124,6 @@ public static function manageDsaIt(): Control ); } - /** * Create a paging control with a specific size. */ diff --git a/src/FreeDSx/Ldap/Entry/Attribute.php b/src/FreeDSx/Ldap/Entry/Attribute.php index e68c0857..8ab89e83 100644 --- a/src/FreeDSx/Ldap/Entry/Attribute.php +++ b/src/FreeDSx/Ldap/Entry/Attribute.php @@ -76,6 +76,11 @@ public function __clone() } } + public function __toString(): string + { + return implode(', ', $this->values); + } + /** * @param string[] $values */ @@ -299,11 +304,6 @@ public function equals( return $nameMatches; } - public function __toString(): string - { - return implode(', ', $this->values); - } - /** * Escape an attribute value for a filter. */ diff --git a/src/FreeDSx/Ldap/Entry/Dn.php b/src/FreeDSx/Ldap/Entry/Dn.php index 473dcb6f..1521c5f4 100644 --- a/src/FreeDSx/Ldap/Entry/Dn.php +++ b/src/FreeDSx/Ldap/Entry/Dn.php @@ -43,6 +43,11 @@ class Dn implements IteratorAggregate, Countable, Stringable public function __construct(private readonly string $dn) {} + public function __toString(): string + { + return $this->dn; + } + /** * @throws UnexpectedValueException */ @@ -102,11 +107,6 @@ public function count(): int return count((array) $this->pieces); } - public function __toString(): string - { - return $this->dn; - } - /** * @return Rdn[] * @throws UnexpectedValueException diff --git a/src/FreeDSx/Ldap/Entry/Entry.php b/src/FreeDSx/Ldap/Entry/Entry.php index 9f115938..1325aaa0 100644 --- a/src/FreeDSx/Ldap/Entry/Entry.php +++ b/src/FreeDSx/Ldap/Entry/Entry.php @@ -51,6 +51,39 @@ public function __construct( $this->changes = new Changes(); } + public function __toString(): string + { + return $this->dn->toString(); + } + + public function __get(string $name): ?Attribute + { + return $this->get($name); + } + + /** + * @param Stringable|string|array $value + */ + public function __set( + string $name, + Stringable|string|array $value, + ): void { + $this->set( + $name, + ...(is_array($value) ? $value : [(string) $value]), + ); + } + + public function __isset(string $name): bool + { + return $this->has($name); + } + + public function __unset(string $name): void + { + $this->reset($name); + } + /** * @internal * @param Attribute[] $attributes @@ -281,39 +314,6 @@ public function count(): int return count($this->attributes); } - public function __toString(): string - { - return $this->dn->toString(); - } - - public function __get(string $name): ?Attribute - { - return $this->get($name); - } - - /** - * @param Stringable|string|array $value - */ - public function __set( - string $name, - Stringable|string|array $value, - ): void { - $this->set( - $name, - ...(is_array($value) ? $value : [(string) $value]), - ); - } - - public function __isset(string $name): bool - { - return $this->has($name); - } - - public function __unset(string $name): void - { - $this->reset($name); - } - /** * An alias of fromArray(). * diff --git a/src/FreeDSx/Ldap/Entry/Option.php b/src/FreeDSx/Ldap/Entry/Option.php index f6394c73..90c42791 100644 --- a/src/FreeDSx/Ldap/Entry/Option.php +++ b/src/FreeDSx/Ldap/Entry/Option.php @@ -34,6 +34,11 @@ class Option implements Stringable public function __construct(private readonly string $option) {} + public function __toString(): string + { + return $this->option; + } + public function isLanguageTag(): bool { return $this->startsWith('lang-'); @@ -115,11 +120,6 @@ public function toString(bool $lowercase = false): string return $this->option; } - public function __toString(): string - { - return $this->option; - } - /** * Convenience factory method for creating a range option. * diff --git a/src/FreeDSx/Ldap/Entry/Options.php b/src/FreeDSx/Ldap/Entry/Options.php index 8f432c84..c124a819 100644 --- a/src/FreeDSx/Ldap/Entry/Options.php +++ b/src/FreeDSx/Ldap/Entry/Options.php @@ -42,6 +42,11 @@ public function __construct(string|Option ...$options) $this->set(...$options); } + public function __toString(): string + { + return $this->toString(); + } + public function add(string|Option ...$options): self { foreach ($options as $option) { @@ -139,11 +144,6 @@ public function toArray(): array return $this->options; } - public function __toString(): string - { - return $this->toString(); - } - /** * @inheritDoc * @return Traversable