Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#58 - Registry docblocks collection return types #60

Merged
merged 11 commits into from
Apr 16, 2024
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 1
level: 2
paths:
- src
- tests
2 changes: 1 addition & 1 deletion src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected static function generatePasswordFromCharacterLists(int $length, array
*
* @param string[] $parts Fragments of a URL as returned from SPL function parse_url(), which can include any or all
* of: `scheme`, `user`, `pass`, `host`, `port`, `path`, `query`, `fragment`.
* @param string[] $partWhitelist List of parts to use when building the URL (all by default)
* @param string[] $whitelist List of parts to use when building the URL (all by default)
*
* @link https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues
*
Expand Down
3 changes: 2 additions & 1 deletion src/Laravel/Html/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public function createField(string $name, array $rules): FormField
if (Str::startsWith($rule, ['min:', 'max:'])) {
[$attribute, $value] = explode(':', $rule, 2);

$attributes[$attribute] = $value + 0; //convert string to integer|float
//convert string to integer|float, depending if it contains a dot.
$attributes[$attribute] = str_contains($value, '.') ? (float) $value : (int) $value;
}

//determine field type from rule
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/Html/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static function typeIsNumeric($type): bool
/**
* Determine whether the given field type needs an array of options.
*
* @param string
* @param string $type
*
* @return bool
*/
Expand Down
1 change: 1 addition & 0 deletions src/Laravel/ValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private function manualCheckPhones($value): bool
}

/**
* @return \Illuminate\Validation\Factory
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
private function getValidatorFactory(): Factory
Expand Down
1 change: 1 addition & 0 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use RuntimeException;
use Upmind\ProvisionBase\Exception\InvalidProviderJob;
use Upmind\ProvisionBase\Provider\Contract\ProviderInterface;
use Upmind\ProvisionBase\Provider\DataSet\DataSet;
use Upmind\ProvisionBase\Registry\Data\ProviderRegister;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/BaseCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function okResult($message, $data = [], $debug = []): ResultData
*
* @param string $message A user-friendly error message
* @param mixed[] $data JSONable data to be passed back to the System Client
* @param mixed[] $debugData JSONable debug data
* @param mixed[] $debug JSONable debug data
* @param Throwable $previous Previous exception, if any
*
* @throws ProvisionFunctionError
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/DataSet/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class DataSet implements ArrayAccess, JsonSerializable, Arrayable, Json
*
* @link https://laravel.com/docs/5.8/validation#available-validation-rules
*
* @return Rules<array<string[]>>
* @return Rules
*/
abstract public static function rules(): Rules;

Expand Down Expand Up @@ -367,7 +367,7 @@ protected function castValue(string $key, $value)
/**
* Cast the given value to the given DataSet.
*
* @param array|DataSet $value Raw data
* @param array|DataSet $data Raw data
* @param string $dataSetClass DataSet class
*
* @return DataSet
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DataSet/RuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RuleParser
* Parse the given data set rules, expanding nested references to other data
* sets.
*
* @param array<string[]> $rules Raw data set rules
* @param array<string[]> $rawRules Raw data set rules
* @param string|null $parentField Name/key of the parent field, if any
*
* @return array<string[]> Fully expanded data set rules
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DataSet/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function offsetUnset($offset): void
}

/**
* @return Form<FormElement>
* @return Form
*/
public function toHtmlForm(): Form
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DataSet/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
* Split nested rules + data under the given fieldName into an "after" validator,
* then return a new rule set for the main validator.
*
* @param \Illuminate\Contracts\Translation\Translator $translator
* @param string $fieldName
* @param array $data
* @param array $rules
* @param array $messages
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/Helper/Api/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public function getBody(): object
*
* Optionally returns the given index of the array.
*
* @param string [$index] The index of the array to return
* @param mixed [$default] The default value to return if $index is invalid
* @param string $index The index of the array to return
* @param mixed $default The default value to return if $index is invalid
*
* @return array|mixed
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Registry/Data/CategoryRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getAbout(): AboutData
/**
* Return the child provider registers.
*
* @return Collection<ProviderRegister>|ProviderRegister[]
* @return Collection<array-key, ProviderRegister>
*/
public function getProviders(): Collection
{
Expand All @@ -91,7 +91,7 @@ public function getProvider($provider): ?ProviderRegister
* @param string $identifier Provider unique identifier
* @param string $class Provider fully-namespaced class name
*
* @return self $this
* @return ProviderRegister
*/
public function addProvider(string $identifier, string $class): ProviderRegister
{
Expand All @@ -113,7 +113,7 @@ public function hasProvider($provider): bool
/**
* Get this category's provision functions.
*
* @return Collection<FunctionRegister>|FunctionRegister[]
* @return Collection<array-key, FunctionRegister>
*/
public function getFunctions(): Collection
{
Expand All @@ -122,9 +122,9 @@ public function getFunctions(): Collection
->map(function (ReflectionMethod $method) {
return new FunctionRegister(
$method->getName(),
$this,
$this->getMethodParameterDataSetClass($method),
$this->getMethodReturnDataSetClass($method),
$this
$this->getMethodReturnDataSetClass($method)
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Registry/Data/ClassRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ final public function hasParent(?ClassRegister $parent = null): bool
}

/**
* @return Collection<ClassRegister>|ClassRegister[]
* @return Collection<array-key, ClassRegister>
*/
final public function getChildren(): Collection
{
Expand Down
4 changes: 2 additions & 2 deletions src/Registry/Data/FunctionRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ final class FunctionRegister implements RegisterInterface
*/
public function __construct(
string $name,
ClassRegister $parent,
?string $parameterDataSetClass = null,
?string $returnDataSetClass = null,
ClassRegister $parent
?string $returnDataSetClass = null
) {
$this->name = $name;
$this->parent = $parent;
Expand Down
4 changes: 2 additions & 2 deletions src/Registry/Data/ProviderRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getConstructor(): FunctionRegister
$dataSetClass = $this->getMethodParameterDataSetClass($constructor);
}

$this->constructor = new FunctionRegister($constructor->getName(), $dataSetClass ?? null, null, $this);
$this->constructor = new FunctionRegister($constructor->getName(), $this, $dataSetClass ?? null, null);
}

return $this->constructor;
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getCategory(): CategoryRegister
/**
* Return the available provision functions.
*
* @return Collection<FunctionRegister>|FunctionRegister[]
* @return Collection<array-key, FunctionRegister>
*/
public function getFunctions(): Collection
{
Expand Down
4 changes: 2 additions & 2 deletions src/Registry/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function getProvider($category, $provider): ?ProviderRegister
/**
* Get all categories from the registry.
*
* @return Collection<CategoryRegister>|CategoryRegister[]
* @return Collection<array-key, CategoryRegister>
*/
public function getCategories(): Collection
{
Expand Down Expand Up @@ -258,7 +258,7 @@ public function enumerateData(): void
/**
* Get all buffered register calls.
*
* @return Collection<BufferedRegister>|BufferedRegister[]
* @return Collection<array-key, BufferedRegister>
*/
public function getBuffer(): Collection
{
Expand Down
6 changes: 3 additions & 3 deletions src/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Result implements ResultInterface
/**
* @param string $status Status of the result (ok or error)
* @param string|null $message User-friendly message to explain the status
* @param array|null [$data] Result data
* @param array|null [$debug] Debug data
* @param array|null $data Result data
* @param array|null $debug Debug data
*/
public function __construct(string $status, ?string $message = null, ?array $data = null, ?array $debug = null)
{
Expand All @@ -63,7 +63,7 @@ public function __construct(string $status, ?string $message = null, ?array $dat
* Create a Result instance for an encountered error
*
* @param string $errorMessage
* @param array|null [$errorData]
* @param array|null $errorData
* @param string|null $error_id
*
* @return static
Expand Down