ScalarNotEquals   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 45.95 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 17
loc 37
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1
rs 10
ccs 13
cts 13
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A compare() 7 7 2
A isValidType() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Validation\Rules\Comparisons;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Validation\Contracts\Errors\ErrorCodes;
22
use Limoncello\Validation\Contracts\Execution\ContextInterface;
23
use Limoncello\Validation\I18n\Messages;
24
use function assert;
25
use function is_scalar;
26
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class ScalarNotEquals extends BaseOneValueComparision
31
{
32
    /**
33
     * @param mixed $value
34
     */
35 1 View Code Duplication
    public function __construct($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37 1
        assert(static::isValidType($value) === true);
0 ignored issues
show
Comprehensibility introduced by
Since Limoncello\Validation\Ru...arisons\ScalarNotEquals is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
38 1
        parent::__construct(
39 1
            $value,
40 1
            ErrorCodes::SCALAR_NOT_EQUALS,
41 1
            Messages::SCALAR_NOT_EQUALS,
42 1
            [$value]
43
        );
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 1 View Code Duplication
    public static function compare($value, ContextInterface $context): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51 1
        assert(static::isValidType($value) === true);
0 ignored issues
show
Comprehensibility introduced by
Since Limoncello\Validation\Ru...arisons\ScalarNotEquals is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
52 1
        $result = static::isValidType($value) === true && $value !== static::readValue($context);
0 ignored issues
show
Comprehensibility introduced by
Since Limoncello\Validation\Ru...arisons\ScalarNotEquals is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
53
54 1
        return $result;
55
    }
56
57
    /**
58
     * @param mixed $value
59
     *
60
     * @return bool
61
     */
62 1
    private static function isValidType($value): bool
63
    {
64 1
        return is_scalar($value) === true;
65
    }
66
}
67