Skip to content

Commit

Permalink
Merge pull request #814 from fezfez/doctrine-coding-standard-12
Browse files Browse the repository at this point in the history
doctrine/coding-standard:^12.0.0
  • Loading branch information
TomHAnderson committed Jul 25, 2023
2 parents d02db3d + d1ccc75 commit 52221d4
Show file tree
Hide file tree
Showing 60 changed files with 274 additions and 373 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"symfony/console": "^5.4.16 || ^6.2.1"
},
"require-dev": {
"doctrine/coding-standard": "^9.0.2",
"doctrine/coding-standard": "^12.0.0",
"doctrine/mongodb-odm": "^2.5.0",
"doctrine/orm": "^2.13.4",
"jangregor/phpstan-prophecy": "^1.0.0",
Expand Down
18 changes: 8 additions & 10 deletions src/Authentication/Adapter/ObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ObjectRepository extends AbstractAdapter
*
* @var mixed[]
*/
protected ?array $authenticationResultInfo = null;
protected array|null $authenticationResultInfo = null;

protected Inflector $inflector;

Expand All @@ -37,15 +37,13 @@ class ObjectRepository extends AbstractAdapter
*
* @param mixed[]|AuthenticationOptions $options
*/
public function __construct(array|AuthenticationOptions $options = [], ?Inflector $inflector = null)
public function __construct(array|AuthenticationOptions $options = [], Inflector|null $inflector = null)
{
$this->setOptions($options);
$this->inflector = $inflector ?? InflectorFactory::create()->build();
}

/**
* @param mixed[]|AuthenticationOptions $options
*/
/** @param mixed[]|AuthenticationOptions $options */
public function setOptions(array|AuthenticationOptions $options): self
{
if (! $options instanceof AuthenticationOptions) {
Expand Down Expand Up @@ -103,8 +101,8 @@ protected function validateIdentity(object $identity): AuthenticationResult
$credentialProperty,
$identity::class,
$identity::class,
$getter
)
$getter,
),
);
}

Expand Down Expand Up @@ -141,14 +139,14 @@ protected function setup(): void
if ($this->identity === null) {
throw new Exception\RuntimeException(
'A value for the identity was not provided prior to authentication with ObjectRepository '
. 'authentication adapter'
. 'authentication adapter',
);
}

if ($this->credential === null) {
throw new Exception\RuntimeException(
'A credential value was not provided prior to authentication with ObjectRepository'
. ' authentication adapter'
. ' authentication adapter',
);
}

Expand All @@ -168,7 +166,7 @@ protected function createAuthenticationResult(): AuthenticationResult
return new AuthenticationResult(
$this->authenticationResultInfo['code'],
$this->authenticationResultInfo['identity'],
$this->authenticationResultInfo['messages']
$this->authenticationResultInfo['messages'],
);
}
}
6 changes: 2 additions & 4 deletions src/Authentication/Storage/ObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class ObjectRepository implements StorageInterface
{
protected AuthenticationOptions $options;

/**
* @param mixed[]|AuthenticationOptions $options
*/
/** @param mixed[]|AuthenticationOptions $options */
public function setOptions(array|AuthenticationOptions $options): ObjectRepository
{
if (! $options instanceof AuthenticationOptions) {
Expand Down Expand Up @@ -47,7 +45,7 @@ public function isEmpty(): bool
* This function assumes that the storage only contains identifier values (which is the case if
* the ObjectRepository authentication adapter is used).
*/
public function read(): ?object
public function read(): object|null
{
$identity = $this->options->getStorage()->read();
if ($identity) {
Expand Down
12 changes: 3 additions & 9 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
final class ConfigProvider
{
/**
* @return array<non-empty-string, mixed[]>
*/
/** @return array<non-empty-string, mixed[]> */
public function __invoke(): array
{
return [
Expand Down Expand Up @@ -93,9 +91,7 @@ public function getDoctrineFactoryConfig(): array
];
}

/**
* @return array<non-empty-string, mixed[]>
*/
/** @return array<non-empty-string, mixed[]> */
public function getValidatorConfig(): array
{
return [
Expand All @@ -112,9 +108,7 @@ public function getValidatorConfig(): array
];
}

/**
* @return array<non-empty-string, array{adapter: string, options?: mixed[], plugins?: mixed[]}>
*/
/** @return array<non-empty-string, array{adapter: string, options?: mixed[], plugins?: mixed[]}> */
public function getCachesConfig(): array
{
$defaultOptions = ['namespace' => 'DoctrineModule'];
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Element/GetProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait GetProxy
{
protected ?Proxy $proxy = null;
protected Proxy|null $proxy = null;

public function getProxy(): Proxy
{
Expand Down
4 changes: 1 addition & 3 deletions src/Form/Element/ObjectMultiCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public function setOptions(iterable $options): self
return parent::setOptions($options);
}

/**
* @return $this
*/
/** @return $this */
public function setOption(string $key, mixed $value): self
{
$this->getProxy()->setOptions([$key => $value]);
Expand Down
4 changes: 1 addition & 3 deletions src/Form/Element/ObjectRadio.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public function setOptions(iterable $options): self
return parent::setOptions($options);
}

/**
* @return $this
*/
/** @return $this */
public function setOption(string $key, mixed $value): self
{
$this->getProxy()->setOptions([$key => $value]);
Expand Down
4 changes: 1 addition & 3 deletions src/Form/Element/ObjectSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public function setOptions(iterable $options): self
return parent::setOptions($options);
}

/**
* @return $this
*/
/** @return $this */
public function setOption(string $key, mixed $value): self
{
$this->getProxy()->setOptions([$key => $value]);
Expand Down
68 changes: 30 additions & 38 deletions src/Form/Element/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Proxy implements ObjectManagerAwareInterface
use ArrayOrTraversableGuardTrait;

/** @var iterable<object>|null */
protected ?iterable $objects = null;
protected iterable|null $objects = null;

protected ?string $targetClass = null;
protected string|null $targetClass = null;

/** @var mixed[] */
protected array $valueOptions = [];
Expand All @@ -55,28 +55,26 @@ class Proxy implements ObjectManagerAwareInterface
/** @var callable $labelGenerator A callable used to create a label based on an item in the collection an Entity */
protected $labelGenerator;

protected ?bool $isMethod = null;
protected bool|null $isMethod = null;

protected ?ObjectManager $objectManager = null;
protected ObjectManager|null $objectManager = null;

protected bool $displayEmptyItem = false;

protected string $emptyItemLabel = '';

protected ?string $optgroupIdentifier = null;
protected string|null $optgroupIdentifier = null;

protected ?string $optgroupDefault = null;
protected string|null $optgroupDefault = null;

protected Inflector $inflector;

public function __construct(?Inflector $inflector = null)
public function __construct(Inflector|null $inflector = null)
{
$this->inflector = $inflector ?? InflectorFactory::create()->build();
}

/**
* @param iterable<mixed> $options
*/
/** @param iterable<mixed> $options */
public function setOptions(iterable $options): void
{
if ($options instanceof Traversable) {
Expand Down Expand Up @@ -161,17 +159,13 @@ public function getEmptyItemLabel(): string
return $this->emptyItemLabel;
}

/**
* @return mixed[]
*/
/** @return mixed[] */
public function getOptionAttributes(): array
{
return $this->optionAttributes;
}

/**
* @param mixed[] $optionAttributes
*/
/** @param mixed[] $optionAttributes */
public function setOptionAttributes(array $optionAttributes): void
{
$this->optionAttributes = $optionAttributes;
Expand Down Expand Up @@ -261,12 +255,12 @@ public function setLabelGenerator(callable $callable): void
$this->labelGenerator = $callable;
}

public function getLabelGenerator(): ?callable
public function getLabelGenerator(): callable|null
{
return $this->labelGenerator;
}

public function getOptgroupIdentifier(): ?string
public function getOptgroupIdentifier(): string|null
{
return $this->optgroupIdentifier;
}
Expand All @@ -276,7 +270,7 @@ public function setOptgroupIdentifier(string $optgroupIdentifier): void
$this->optgroupIdentifier = $optgroupIdentifier;
}

public function getOptgroupDefault(): ?string
public function getOptgroupDefault(): string|null
{
return $this->optgroupDefault;
}
Expand All @@ -296,7 +290,7 @@ public function setIsMethod(bool $method): Proxy
return $this;
}

public function getIsMethod(): ?bool
public function getIsMethod(): bool|null
{
return $this->isMethod;
}
Expand All @@ -322,7 +316,7 @@ public function getFindMethod(): array
return $this->findMethod;
}

protected function generateLabel(mixed $targetEntity): ?string
protected function generateLabel(mixed $targetEntity): string|null
{
if ($this->getLabelGenerator() === null) {
return null;
Expand All @@ -331,9 +325,7 @@ protected function generateLabel(mixed $targetEntity): ?string
return call_user_func($this->getLabelGenerator(), $targetEntity);
}

/**
* @throws RuntimeException
*/
/** @throws RuntimeException */
public function getValue(mixed $value): mixed
{
$metadata = $this->getObjectManager()->getClassMetadata($this->getTargetClass());
Expand All @@ -356,7 +348,7 @@ public function getValue(mixed $value): mixed
// Handling composite (multiple) identifiers is not yet supported
throw new BadMethodCallException(sprintf(
'Composite identiers are not yet supported in %s.',
self::class
self::class,
));
}

Expand Down Expand Up @@ -399,8 +391,8 @@ protected function loadObjects(): void
sprintf(
'Method "%s" could not be found in repository "%s"',
$findMethodName,
$repository::class
)
$repository::class,
),
);
}

Expand All @@ -419,8 +411,8 @@ protected function loadObjects(): void
. ' was not provided',
$param->getName(),
$findMethodName,
$repository::class
)
$repository::class,
),
);
}
}
Expand All @@ -431,7 +423,7 @@ protected function loadObjects(): void
$this->guardForArrayOrTraversable(
$objects,
sprintf('%s::%s() return value', $repository::class, $findMethodName),
InvalidRepositoryResultException::class
InvalidRepositoryResultException::class,
);

$this->objects = $objects;
Expand Down Expand Up @@ -468,16 +460,16 @@ protected function loadValueOptions(): void
sprintf(
'Property "%s" could not be found in object "%s"',
$property,
$this->getTargetClass()
)
$this->getTargetClass(),
),
);
}

$getter = 'get' . $this->inflector->classify($property);

if (! is_callable([$object, $getter])) {
throw new RuntimeException(
sprintf('Method "%s::%s" is not callable', $this->targetClass, $getter)
sprintf('Method "%s::%s" is not callable', $this->targetClass, $getter),
);
}

Expand All @@ -488,8 +480,8 @@ protected function loadValueOptions(): void
sprintf(
'%s must have a "__toString()" method defined if you have not set a property'
. ' or method to use.',
$this->getTargetClass()
)
$this->getTargetClass(),
),
);
}

Expand Down Expand Up @@ -520,8 +512,8 @@ protected function loadValueOptions(): void
sprintf(
'Parameter "option_attributes" expects an array of key => value where value is of type'
. '"string" or "callable". Value of type "%s" found.',
gettype($optionValue)
)
gettype($optionValue),
),
);
}

Expand All @@ -537,7 +529,7 @@ protected function loadValueOptions(): void

if (! is_callable([$object, $optgroupGetter])) {
throw new RuntimeException(
sprintf('Method "%s::%s" is not callable', $this->targetClass, $optgroupGetter)
sprintf('Method "%s::%s" is not callable', $this->targetClass, $optgroupGetter),
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/
final class Module implements ConfigProviderInterface
{
/**
* @return array<string, mixed>
*/
/** @return array<string, mixed> */
public function getConfig(): array
{
$provider = new ConfigProvider();
Expand Down

0 comments on commit 52221d4

Please sign in to comment.