Skip to content

Commit

Permalink
Adjust doc-blocks and finalize classes (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamwin committed Dec 7, 2021
1 parent 2ef518e commit e93bed2
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 33 deletions.
12 changes: 8 additions & 4 deletions src/DataSetInterface.php
Expand Up @@ -7,19 +7,23 @@
use Yiisoft\Validator\Exception\MissingAttributeException;

/**
* DataSetInterface represents a key-value data set
* DataSetInterface represents a key-value data set.
*/
interface DataSetInterface
{
/**
* Get specified attribute value
* Get specified attribute value.
*
* @throws MissingAttributeException if there is no such value
* @throws MissingAttributeException If there is no such value.
*
* @return mixed
*/
public function getAttributeValue(string $attribute);

/**
* If there is such attribute in the set
* If there is such attribute in the set.
*
* @param string $attribute
*
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion src/FormattableRuleInterface.php
Expand Up @@ -6,7 +6,7 @@

/**
* The interface marks a rule that gets error messages by formatting based on a pattern and a set of parameters.
* The interface allows to set formatter to be used.
* The interface allows setting formatter to be used.
*/
interface FormattableRuleInterface extends RuleInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter.php
Expand Up @@ -8,7 +8,7 @@
use function is_object;
use function is_resource;

class Formatter implements FormatterInterface
final class Formatter implements FormatterInterface
{
public function format(string $message, array $parameters = []): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/ParametrizedRuleInterface.php
Expand Up @@ -12,7 +12,7 @@ interface ParametrizedRuleInterface extends RuleInterface
{
/**
* Get name of the rule to be used when rule is converted to array.
* By default it returns base name of the class, first letter in lowercase.
* By default, it returns base name of the class, first letter in lowercase.
*
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PostValidationHookInterface.php
Expand Up @@ -5,7 +5,7 @@
namespace Yiisoft\Validator;

/**
* Allows to implement post-validation processing in the data set object itself.
* Allows implementing post-validation processing in the data set object itself.
*
* @see \Yiisoft\Form\FormModel::processValidationResult
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Rule.php
Expand Up @@ -106,7 +106,7 @@ protected function formatMessage(string $message, array $parameters = []): strin

/**
* Add a PHP callable whose return value determines whether this rule should be applied.
* By default rule will be always applied.
* By default, rule will always be applied.
*
* The signature of the callable should be `function ($value, ValidationContext $context): bool`,
* where `$value` and `$context` refer to the value validated and the validation context.
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/AtLeast.php
Expand Up @@ -12,7 +12,7 @@
/**
* AtLeastValidator checks if at least $min of many attributes are filled.
*/
class AtLeast extends Rule
final class AtLeast extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Boolean.php
Expand Up @@ -12,7 +12,7 @@
/**
* BooleanValidator checks if the attribute value is a boolean value or a value corresponding to it.
*/
class Boolean extends Rule
final class Boolean extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Callback.php
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Validator\Rule;
use Yiisoft\Validator\ValidationContext;

class Callback extends Rule
final class Callback extends Rule
{
/**
* @var callable
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/CompareTo.php
Expand Up @@ -22,7 +22,7 @@
* are compared byte by byte. When comparing numbers, make sure to call the {@see CompareTo::asNumber()}
* to enable numeric comparison.
*/
class CompareTo extends Rule
final class CompareTo extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Each.php
Expand Up @@ -13,7 +13,7 @@
/**
* Each validator validates an array by checking each of its elements against a set of rules
*/
class Each extends Rule
final class Each extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Email.php
Expand Up @@ -16,7 +16,7 @@
/**
* EmailValidator validates that the attribute value is a valid email address.
*/
class Email extends Rule
final class Email extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/HasLength.php
Expand Up @@ -16,7 +16,7 @@
*
* Note, this validator should only be used with string-typed attributes.
*/
class HasLength extends Rule
final class HasLength extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/InRange.php
Expand Up @@ -17,7 +17,7 @@
* If the {@see InRange::not()} is called, the validator will ensure the attribute value
* is NOT among the specified range.
*/
class InRange extends Rule
final class InRange extends Rule
{
use HasValidationErrorMessage;

Expand Down
10 changes: 5 additions & 5 deletions src/Rule/Ip.php
Expand Up @@ -34,7 +34,7 @@
* @property array $ranges The IPv4 or IPv6 ranges that are allowed or forbidden. See {@see Ip::ranges()} for
* detailed description.
*/
class Ip extends Rule
final class Ip extends Rule
{
/**
* Negation char.
Expand Down Expand Up @@ -417,8 +417,8 @@ private function isAllowed(string $ip): bool
*/
private function parseNegatedRange($string): array
{
$isNegated = strpos($string, static::NEGATION_CHAR) === 0;
return [$isNegated, $isNegated ? substr($string, strlen(static::NEGATION_CHAR)) : $string];
$isNegated = strpos($string, self::NEGATION_CHAR) === 0;
return [$isNegated, $isNegated ? substr($string, strlen(self::NEGATION_CHAR)) : $string];
}

/**
Expand All @@ -442,7 +442,7 @@ private function prepareRanges(array $ranges): array
$replacements = $this->prepareRanges($this->networks[$range]);
foreach ($replacements as &$replacement) {
[$isReplacementNegated, $replacement] = $this->parseNegatedRange($replacement);
$result[] = ($isRangeNegated && !$isReplacementNegated ? static::NEGATION_CHAR : '') . $replacement;
$result[] = ($isRangeNegated && !$isReplacementNegated ? self::NEGATION_CHAR : '') . $replacement;
}
} else {
$result[] = $string;
Expand All @@ -460,7 +460,7 @@ private function prepareRanges(array $ranges): array
public function getIpParsePattern(): string
{
return '/^(?<not>' . preg_quote(
static::NEGATION_CHAR,
self::NEGATION_CHAR,
'/'
) . ')?(?<ipCidr>(?<ip>(?:' . IpHelper::IPV4_PATTERN . ')|(?:' . IpHelper::IPV6_PATTERN . '))(?:\/(?<cidr>-?\d+))?)$/';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Json.php
Expand Up @@ -14,7 +14,7 @@
/**
* JsonValidator validates that the attribute value is a valid json
*/
class Json extends Rule
final class Json extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/MatchRegularExpression.php
Expand Up @@ -17,7 +17,7 @@
* If the {@see MatchRegularExpression::not()} is used, the validator will ensure the attribute value do NOT match
* the pattern.
*/
class MatchRegularExpression extends Rule
final class MatchRegularExpression extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Nested.php
Expand Up @@ -43,7 +43,7 @@
* ]);
* ```
*/
class Nested extends Rule
final class Nested extends Rule
{
/**
* @var Rule[][]
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Number.php
Expand Up @@ -16,7 +16,7 @@
* or {@see Number::$numberPattern}. Optionally, you may configure the {@see Number::max()} and {@see Number::min()}
* to ensure the number is within certain range.
*/
class Number extends Rule
final class Number extends Rule
{
/**
* @var bool whether the attribute value can only be an integer. Defaults to false.
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Required.php
Expand Up @@ -14,7 +14,7 @@
/**
* RequiredValidator validates that the specified attribute does not have null or empty value.
*/
class Required extends Rule
final class Required extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Subset.php
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Validator\Rule;
use Yiisoft\Validator\ValidationContext;

class Subset extends Rule
final class Subset extends Rule
{
/**
* @var iterable
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Url.php
Expand Up @@ -18,7 +18,7 @@
* Note that this validator only checks if the URL scheme and host part are correct.
* It does not check the remaining parts of a URL.
*/
class Url extends Rule
final class Url extends Rule
{
use HasValidationErrorMessage;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules.php
Expand Up @@ -9,7 +9,7 @@
use function is_callable;

/**
* Rules represents multiple rules for a single value
* Rules represents multiple rules for a single value.
*/
final class Rules
{
Expand Down
4 changes: 2 additions & 2 deletions src/ValidationContext.php
Expand Up @@ -12,8 +12,8 @@
final class ValidationContext
{
private ?DataSetInterface $dataSet;
private ?string $attribute = null;
private array $parameters = [];
private ?string $attribute;
private array $parameters;

/**
* @param DataSetInterface|null $dataSet Data set the attribute belongs to. Null if a single value is validated.
Expand Down
1 change: 0 additions & 1 deletion src/Validator.php
Expand Up @@ -32,7 +32,6 @@ public function validate($data, iterable $rules = []): ResultSet
{
$data = $this->normalizeDataSet($data);
if ($data instanceof RulesProviderInterface) {
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
$rules = $data->getRules();
}

Expand Down

0 comments on commit e93bed2

Please sign in to comment.