Passed
Push — master ( 78328e...488bc1 )
by Nelson
03:01
created

ObjectTestProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 67
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A goodConstructorArgumentsProvider() 0 3 1
A badConstructorArgumentsProvider() 0 3 1
A getTargetClassName() 0 3 1
A compareMethodArraysProvider() 0 5 1
B compareMethodArgumentsProvider() 0 62 1
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Copyright © 2016-2019 Nelson Martell (http://nelson6e65.github.io)
6
 *
7
 * Licensed under The MIT License (MIT)
8
 * For full copyright and license information, please see the LICENSE
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright 2016-2019 Nelson Martell
12
 * @link      http://nelson6e65.github.io/php_nml/
13
 * @since     v0.6.0
14
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
15
 * */
16
17
namespace NelsonMartell\Test\DataProviders;
18
19
use stdClass;
20
21
use NelsonMartell\StrictObject;
22
use NelsonMartell\Test\DataProviders\ExampleClass\A;
23
24
use NelsonMartell\Test\Helpers\ConstructorMethodTester;
25
use NelsonMartell\Test\Helpers\ExporterPlugin;
26
use NelsonMartell\Test\Helpers\IComparerTester;
27
28
/**
29
 *
30
 * @author Nelson Martell <[email protected]>
31
 * @internal
32
 * */
33
trait ObjectTestProvider
34
{
35
    use ExporterPlugin;
36
    use ConstructorMethodTester;
37
    use IComparerTester;
38
39
    # ConstructorMethodTester
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
40
41
    public function getTargetClassName()
42
    {
43
        return StrictObject::class;
44
    }
45
46
    public function goodConstructorArgumentsProvider()
47
    {
48
        return [[]];
49
    }
50
51
52
    public function badConstructorArgumentsProvider()
53
    {
54
        return null;
55
    }
56
    #
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
57
58
59
    # IComparerTester
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
60
    public function compareMethodArgumentsProvider()
61
    {
62
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63
        $obj->one = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
64
        $obj->nine = 9;
65
66
        $args = [
67
            'integers: same value, +-'      => [1, 5, -5],
68
            'integers: same value, -+'      => [-1, -5, 5],
69
            'integers: same value, --'      => [0, -5, -5],
70
            'integers: same value, ++'      => [0, 5, 5],
71
            'integers: different value, +-' => [1, 90, -8],
72
            'integers: different value, -+' => [-1, -8, 90],
73
            'integers: different value, --' => [1, -8, -90],
74
            'integers: different value, ++' => [-1, 8, 90],
75
            'strings: same'                 => [0, 'world', 'world'],
76
            'strings: leading space, <'     => [-1, 'world', 'world '],
77
            'strings: leading space, >'     => [1, 'world ', 'world'],
78
            'strings: different chars, >'   => [1, 'hola', 'hello'],
79
            'strings: different chars, <'   => [-1, 'hello', 'hola'],
80
            'arrays: same'                  => [0, ['one' => 'world'], ['one' => 'world']],
81
            'arrays: different count, >'    => [1, ['hola', 'mundo'], ['hello']],
82
            'arrays: different count, <'    => [-1, ['hello'], ['hola', 'mundo']],
83
            'array > array (values)'        => [1, ['hola', 'mundo'], ['hello', 'world']],
84
            'array < array (values)'        => [-1, ['hello', 'world'], ['hola', 'mundo']],
85
            'array < array (keys)'          => [-1, ['hola', 'mundo'], ['one' => 'hello', 'two' => 'world']],
86
            'array < stdClass'              => [-1, [], new stdClass],
87
            'stdClass > array'              => [1, new stdClass, []],
88
            'array > null'                  => [1, [], null],
89
            'null < array'                  => [-1, null, []],
90
            'array > int'                   => [1, [], 1],
91
            'int < array'                   => [-1, 1, []],
92
            'array > string'                => [1, [], '1'],
93
            'string < array'                => [-1, '1', []],
94
            'same reference =='             => [0, $obj, $obj],
95
            'empty classes =='              => [0, new A(), new A()],
96
            'different class'               => [null, new A(), new stdClass],
97
            'stdClass (empty) < stdClass'   => [-1, new \stdClass, $obj],
98
            'stdClass > stdClass (empty)'   => [1, $obj, new \stdClass],
99
            'stdClass > integer'            => [1, $obj, 1234],
100
            'integer < stdClass'            => [-1, 1234, $obj],
101
            'stdClass > string'             => [1, $obj, "1234"],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 1234 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
102
            'string < stdClass'             => [-1, "1234", $obj],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 1234 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
103
            'stdClass > null'               => [1, $obj, null],
104
            'null < stdClass'               => [-1, null, $obj],
105
            'float > null'                  => [1, 1.23, null],
106
            'null < float'                  => [-1, null, 1.23],
107
            'null < float (negative)'       => [-1, null, -1.23],
108
            'float (negative) > null'       => [1, -1.23, null],
109
            'float == integer'              => [0, 1.00, 1],
110
            'float != integer'              => [1, 1.0000001, 1],
111
            'floats near to zero'           => [1, 0.00000000001, -0.00000000001],
112
            'float > integer'               => [1, 1.23, 1],
113
            'integer < float'               => [-1, 1, 1.23],
114
            'floats <'                      => [-1, 1.234, 1.2345],
115
            'bool cant integer'             => [null, false, 19],
116
            'integer cant bool'             => [null, 1, true],
117
            'boolean < boolean'             => [-1, false, true],
118
            'boolean > boolean'             => [1, true, false],
119
        ];
120
121
        return $args;
122
    }
123
124
    public function compareMethodArraysProvider()
125
    {
126
        return [
127
            'integer[]'           => [[-67, -9, 0, 4, 5, 6]],
128
            'string[]'            => [['a', 'b', 'c', 'd', 'z', 'z1']],
129
        ];
130
    }
131
    #
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
132
}
133