Skip to content

Commit

Permalink
Added more phpstan typings
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Jan 8, 2024
1 parent 97ea3c2 commit 2cc2656
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Manager/SettingsHydratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ interface SettingsHydratorInterface
{
/**
* Hydrate the given settings object with the values from the storage provider.
* @template T of object
* @param object $settings The settings object to hydrate
* @phpstan-param T $settings
* @param SettingsSchema $schema The schema of the settings object to use
* @phpstan-param SettingsSchema<T> $schema
* @return object The hydrated settings object
* @phpstan-return T
*/
public function hydrate(object $settings, SettingsSchema $schema): object;

/**
* Persist the given settings object to the storage provider.
* @template T of object
* @param object $settings The settings object to persist
* @phpstan-param T $settings
* @param SettingsSchema $schema The schema of the settings object to use
* @phpstan-param SettingsSchema<T> $schema
* @return object The persisted settings object
* @phpstan-return T
*/
public function persist(object $settings, SettingsSchema $schema): object;
}
4 changes: 4 additions & 0 deletions src/Manager/SettingsResetterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ interface SettingsResetterInterface
/**
* Resets the settings instance to their default values.
* The instance is returned.
* @template T of object
* @param object $settings
* @phpstan-param T $settings
* @param SettingsSchema $schema The schema, that should be used to reset the settings
* @phpstan-param SettingsSchema<T> $schema
* @return object
* @phpstan-return T
*/
public function resetSettings(object $settings, SettingsSchema $schema): object;
}
4 changes: 4 additions & 0 deletions src/Schema/SchemaManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ interface SchemaManagerInterface
/**
* Checks if the given class is a config class.
* @param string|object $className The configuration class, to check. This can either be a class string, the short name, or an instance of the class.
* @phpstan-param class-string|object $className
* @return bool
*/
public function isSettingsClass(string|object $className): bool;

/**
* Returns the configuration schema of the given class, which contains all metadata about the configuration class.
* @template T of object
* @param string|object $className The configuration class, to get the schema for. This can either be a class string, the short name, or an instance of the class.
* @phpstan-param class-string<T>|T $className
* @return SettingsSchema
* @phpstan-return SettingsSchema<T>
*/
public function getSchema(string|object $className): SettingsSchema;
}
15 changes: 13 additions & 2 deletions src/Schema/SettingsSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@

/**
* This class represents the schema (structure) of a settings class
* @template T of object
*/
class SettingsSchema
{
private readonly array $parametersByPropertyNames;
private readonly array $parametersByName;

/**
* Create a new settings schema
* @param string $className The class name of the settings class.
* @phpstan-param class-string<T> $className
* @param ParameterSchema[] $parameterSchemas The parameter schemas of the settings class.
* @param string $storageAdapter The storage adapter, which should be used to store the settings of this class.
* @phpstan-param class-string<StorageAdapterInterface> $storageAdapter
* @param string $name The (short) name of the settings class.
*/
public function __construct(
private readonly string $className,
array $parameterSchemas,
private readonly string $storageAdapter,
private readonly string|null $name = null,
private readonly string $name,
)
{
//Sort the parameters by their property names and names
Expand All @@ -60,6 +70,7 @@ public function __construct(
/**
* Returns the class name of the configuration class, which is managed by this schema.
* @return string
* @phpstan-return class-string<T>
*/
public function getClassName(): string
{
Expand All @@ -68,7 +79,7 @@ public function getClassName(): string

public function getName(): string
{
return $this->name ?? $this->className;
return $this->name;
}

/**
Expand Down

0 comments on commit 2cc2656

Please sign in to comment.