Code Duplication    Length = 25-25 lines in 7 locations

src/Rules/Types/AsArray.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsArray extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_array($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_ARRAY);
52
    }
53
}
54

src/Rules/Types/AsBool.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsBool extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_bool($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_BOOL);
52
    }
53
}
54

src/Rules/Types/AsDateTime.php 1 location

@@ 30-54 (lines=25) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class AsDateTime extends BaseRule
31
{
32
    /**
33
     * @inheritdoc
34
     */
35
    public function toBlock(): ExecutionBlockInterface
36
    {
37
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
38
    }
39
40
    /**
41
     * @param mixed            $value
42
     * @param ContextInterface $context
43
     *
44
     * @return array
45
     *
46
     * @SuppressWarnings(PHPMD.StaticAccess)
47
     */
48
    public static function execute($value, ContextInterface $context): array
49
    {
50
        return $value instanceof DateTimeInterface ?
51
            BlockReplies::createSuccessReply($value) :
52
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_DATE_TIME);
53
    }
54
}
55

src/Rules/Types/AsFloat.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsFloat extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_float($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_FLOAT);
52
    }
53
}
54

src/Rules/Types/AsInt.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsInt extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_int($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_INT);
52
    }
53
}
54

src/Rules/Types/AsNumeric.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsNumeric extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_numeric($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_NUMERIC);
52
    }
53
}
54

src/Rules/Types/AsString.php 1 location

@@ 29-53 (lines=25) @@
26
/**
27
 * @package Limoncello\Validation
28
 */
29
final class AsString extends BaseRule
30
{
31
    /**
32
     * @inheritdoc
33
     */
34
    public function toBlock(): ExecutionBlockInterface
35
    {
36
        return (new ProcedureBlock([self::class, 'execute']))->setProperties($this->getStandardProperties());
37
    }
38
39
    /**
40
     * @param mixed            $value
41
     * @param ContextInterface $context
42
     *
43
     * @return array
44
     *
45
     * @SuppressWarnings(PHPMD.StaticAccess)
46
     */
47
    public static function execute($value, ContextInterface $context): array
48
    {
49
        return is_string($value) === true ?
50
            BlockReplies::createSuccessReply($value) :
51
            BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_STRING);
52
    }
53
}
54