Completed
Push — master ( d6446f...d11253 )
by Nelson
05:36
created

VersionComponentTestProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 215
Duplicated Lines 13.02 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
dl 28
loc 215
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 8

12 Methods

Rating   Name   Duplication   Size   Complexity  
A goodConstructorArgumentsProvider() 0 11 1
A badConstructorArgumentsProvider() 0 10 1
A objectInstanceProvider() 0 4 1
A readOnlyPropertiesProvider() 0 9 1
B IComparableCompareToMethodArgumentsProvider() 0 43 1
A compareMethodArgumentsProvider() 0 13 1
B compareMethodArraysProvider() 0 33 1
A goodVersionComponentParseMethodArgumentsProvider() 0 15 1
A badVersionComponentParseMethodArgumentsProvider() 0 10 1
A IEquatableMethodArgumentsProvider() 0 15 1
A versionComponentToStringMethodArgumentsProvider() 14 14 1
A nullOrDefaultStatesProvider() 14 14 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
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Trait definition.
7
 *
8
 * Copyright © 2016-2017 Nelson Martell (http://nelson6e65.github.io)
9
 *
10
 * Licensed under The MIT License (MIT)
11
 * For full copyright and license information, please see the LICENSE
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright 2016-2017 Nelson Martell
15
 * @link      http://nelson6e65.github.io/php_nml/
16
 * @since     v0.6.0
17
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
18
 * */
19
20
namespace NelsonMartell\Test\DataProviders;
21
22
use NelsonMartell\VersionComponent;
23
use NelsonMartell\Test\Helpers\ExporterPlugin;
24
use NelsonMartell\Test\Helpers\ConstructorMethodTester;
25
use NelsonMartell\Test\Helpers\IComparableTester;
26
use NelsonMartell\Test\Helpers\IComparerTester;
27
use NelsonMartell\Test\Helpers\IEquatableTester;
28
use NelsonMartell\Test\Helpers\ImplementsIStrictPropertiesContainer;
29
use NelsonMartell\Test\Helpers\HasReadOnlyProperties;
30
31
/**
32
 * Data providers for NelsonMartell\Test\VersionComponent.
33
 *
34
 * @author Nelson Martell <[email protected]>
35
 * @internal
36
 * */
37
trait VersionComponentTestProvider
38
{
39
    use ExporterPlugin;
40
    use ConstructorMethodTester;
41
    use IComparableTester;
42
    use IComparerTester;
43
    use IEquatableTester;
44
    use ImplementsIStrictPropertiesContainer;
45
    use HasReadOnlyProperties;
46
47
    public function goodConstructorArgumentsProvider()
48
    {
49
        return [
50
            'No args'           => [],
51
            'null values'       => [null, null],
52
            'Only integer part' => [1, null],
53
            'Only string part'  => [null, '-alpha'],
54
            'All arguments'     => [5, '-beta'],
55
            'Git describe'      => [19, '-g7575872'],
56
        ];
57
    }
58
59
    public function badConstructorArgumentsProvider()
60
    {
61
        return [
62
            'Negative integer part'        => [-1, null],
63
            'Invalid string value part'    => [0, 'erróneo'],
64
            'Invalid type (float) for string part'  => [0, 23.912],
65
            'Invalid type (object) for string part'  => [0, new \stdClass],
66
            'Invalid type (array) for string part'  => [0, ['no']],
67
        ];
68
    }
69
70
    public function objectInstanceProvider()
71
    {
72
        return [[new VersionComponent(1, '-beta')]];
73
    }
74
75
    public function readOnlyPropertiesProvider()
76
    {
77
        $obj = new VersionComponent(1, '-beta');
78
79
        return [
80
            [$obj, 'intValue', 1],
81
            [$obj, 'stringValue', '-beta'],
82
        ];
83
    }
84
85
    public function IComparableCompareToMethodArgumentsProvider()
86
    {
87
        $v = new VersionComponent(1, '-alpha');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 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...
88
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 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...
89
        $obj->intValue = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
90
        $obj->stringValue = '-alpha';
91
92
        $args = [
93
            'Equals by reference' => [0, $v, $v],
94
            'Equals by value'     => [
95
                0,
96
                new VersionComponent(1, '-alpha'),
97
                VersionComponent::parse('1-alpha')
98
            ],
99
            'VersionComponent: >' => [
100
                1,
101
                new VersionComponent(1, '-beta'),
102
                VersionComponent::parse('1-alpha')
103
            ],
104
            'VersionComponent: <' => [
105
                -1,
106
                new VersionComponent(1, '-alpha'),
107
                VersionComponent::parse('1-beta')
108
            ],
109
            'VersionComponent | stdClass: null' => [
110
                null,
111
                $v,
112
                $obj
113
            ],
114
            'VersionComponent | null' => [
115
                1,
116
                $v,
117
                null
118
            ],
119
            'VersionComponent | VersionComponent (null)' => [
120
                -1,
121
                new VersionComponent(),
122
                new VersionComponent(1)
123
            ],
124
        ];
125
126
        return $args;
127
    }
128
129
130
    public function compareMethodArgumentsProvider()
131
    {
132
        $v = new VersionComponent(1, '-alpha');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 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...
133
        $obj = new \stdClass();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 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...
134
        $obj->intValue = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
135
        $obj->stringValue = '-alpha';
136
137
        return [
138
            [-1, 'array', $v],
139
            [null, $v, $obj],
140
            [-1, [], $v],
141
        ];
142
    }
143
144
    public function compareMethodArraysProvider()
145
    {
146
        return [
147
            'VersionComponent[]' => [[
148
                VersionComponent::parse("0-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 0-4-g 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...
149
                VersionComponent::parse("1-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 1-4-g 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...
150
                VersionComponent::parse("2-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-3-g 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...
151
                VersionComponent::parse("2-3-g726356"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-3-g726356 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...
152
                VersionComponent::parse("2-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 2-4-g 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...
153
                VersionComponent::parse("4-3-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-g 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...
154
                VersionComponent::parse("4-3-gsh4hajk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-gsh4hajk7 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...
155
                VersionComponent::parse("4-3-gsh4hbjk7"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 4-3-gsh4hbjk7 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...
156
                VersionComponent::parse("11-4-g"),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 11-4-g 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...
157
            ]],
158
            'VersionComponent[] + integer[]' => [[
159
                1,
160
                new VersionComponent(2, '-alpha'),
161
            ]],
162
            'VersionComponent[] + string[]'  => [[
163
                new VersionComponent(1, '-alpha'),
164
                '1-beta',
165
            ]],
166
            'VersionComponent[] + string[] (non parseable)'  => [[
167
                '----------',
168
                new VersionComponent(),
169
            ]],
170
            'VersionComponent[] + array[]'   => [[
171
                [],
172
                [0, 1, 0],
173
                new VersionComponent(1, '-alpha'),
174
            ]],
175
        ];
176
    }
177
178
    public function goodVersionComponentParseMethodArgumentsProvider()
179
    {
180
        return [
181
            [new VersionComponent(1, 'a0'), '1a0'],
182
            [new VersionComponent(2, '-3-g726351'), '2-3-g726351'],
183
            [new VersionComponent(3, '-beta'), '3-beta'],
184
            [new VersionComponent(0, '-alpha'), '0-alpha'],
185
            [new VersionComponent(0, '-beta2'), '0-beta2'],
186
            'string | empty'        => [new VersionComponent(), '      '], // Maybe should throw exception?
187
            'string | only spaces'  => [new VersionComponent(), ''], // Maybe should throw exception?
188
            'null'                  => [new VersionComponent(), null], // Maybe should throw exception?
189
            'integer'               => [new VersionComponent(7), 7],
190
            'VersionComponent'      => [new VersionComponent(999), new VersionComponent(999)],
191
        ];
192
    }
193
194
    public function badVersionComponentParseMethodArgumentsProvider()
195
    {
196
        return [
197
            'string | consecutive "-"'          => ['1a--0'],
198
            'string | invalid char: ó'          => ['1-erróneo'],
199
            'string | not starting in number'   => ['beta0'],
200
            'integer | < 0'                     => [-13],
201
            'stdClass'                          => [new \stdClass],
202
        ];
203
    }
204
205
    public function IEquatableMethodArgumentsProvider()
206
    {
207
        return [
208
            [true, new VersionComponent(1, '-alpha'), new VersionComponent(1, '-alpha')],
209
            [false, new VersionComponent(1, '-beta'), new VersionComponent(1, '-bet')],
210
            [false, new VersionComponent(3, '-dev'), new VersionComponent(1, '-dev')],
211
            [false, new VersionComponent(), null],
212
            [false, new VersionComponent(0), 0],
213
            [false, new VersionComponent(2), 2],
214
            [false, new VersionComponent(23), 2345654675675675673453],
215
            [false, new VersionComponent(0, '-dev'), '0-dev'],
216
            [false, new VersionComponent(1, '-alpha'), [1, '-alpha']],
217
            [false, new VersionComponent(), new \stdClass],
218
        ];
219
    }
220
221 View Code Duplication
    public function versionComponentToStringMethodArgumentsProvider()
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...
222
    {
223
        return [
224
            ['0', new VersionComponent(0)],
225
            ['', new VersionComponent()],
226
            ['', new VersionComponent(null, '')],
227
            ['', new VersionComponent(null, '  ')],
228
            ['', new VersionComponent(null)],
229
            ['', new VersionComponent(null, null)],
230
            ['1a', new VersionComponent(1, 'a')],
231
            ['1-beta', new VersionComponent(1, '-beta')],
232
            ['2-rc1-20-g8c5b85c', new VersionComponent(2, "-rc1-20-g8c5b85c")],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal -rc1-20-g8c5b85c 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...
233
        ];
234
    }
235
236
237 View Code Duplication
    public function nullOrDefaultStatesProvider()
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...
238
    {
239
        return [
240
            ['default', new VersionComponent(0)],
241
            ['null', new VersionComponent()],
242
            ['null', new VersionComponent(null, '')],
243
            ['null', new VersionComponent(null, '  ')],
244
            ['null', new VersionComponent(null)],
245
            ['null', new VersionComponent(null, null)],
246
            ['defined', new VersionComponent(1, 'a')],
247
            ['defined', new VersionComponent(1, '-beta')],
248
            ['defined', new VersionComponent(2, "-rc1-20-g8c5b85c")],
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal -rc1-20-g8c5b85c 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...
249
        ];
250
    }
251
}
252