Passed
Pull Request — master (#314)
by Arman
03:09
created

Lists   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A containsList() 0 9 1
A doesntContainsList() 0 9 1
A contains() 0 6 1
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.8
13
 */
14
15
namespace Quantum\Libraries\Validation\Traits;
16
17
/**
18
 * Trait Lists
19
 * @package Quantum\Libraries\Validation\Rules
20
 */
21
trait Lists
22
{
23
24
    /**
25
     * Validates that the field value is contained within a given string.
26
     * @param string $field
27
     * @param string $value
28
     * @param string $haystack
29
     * @return bool
30
     */
31
    protected function contains(string $field, string $value, string $haystack): bool
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
    protected function contains(/** @scrutinizer ignore-unused */ string $field, string $value, string $haystack): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        $value = trim(strtolower($value));
34
        $haystack = trim(strtolower($haystack));
35
36
        return strpos($haystack, $value) !== false;
37
    }
38
39
    /**
40
     * Verifies that a value is contained within the pre-defined value set.
41
     * @param string $field
42
     * @param string $value
43
     * @param string ...$list
44
     * @return bool
45
     */
46
    protected function containsList(string $field, string $value, string ...$list): bool
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    protected function containsList(/** @scrutinizer ignore-unused */ string $field, string $value, string ...$list): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        $value = trim(strtolower($value));
49
50
        $list = array_map(function ($item) {
51
            return trim(strtolower($item));
52
        }, $list);
53
54
        return in_array($value, $list);
55
    }
56
57
    /**
58
     * Verifies that a value is not contained within the pre-defined value set.
59
     * @param string $field
60
     * @param string $value
61
     * @param string ...$list
62
     * @return bool
63
     */
64
    protected function doesntContainsList(string $field, string $value, string ...$list): bool
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
    protected function doesntContainsList(/** @scrutinizer ignore-unused */ string $field, string $value, string ...$list): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        $value = trim(strtolower($value));
67
68
        $list = array_map(function ($item) {
69
            return trim(strtolower($item));
70
        }, $list);
71
72
        return !in_array($value, $list);
73
    }
74
}