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

HasWriteOnlyProperties   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
testImplementsIStrictPropertiesContainerInterface() 0 1 ?
writeonlyPropertiesProvider() 0 1 ?
A testWriteonlyPropertiesAreWritables() 0 7 1
A testWriteonlyPropertiesAreNotReadables() 0 8 1
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Trait definition
7
 *
8
 * Copyright © 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 2017 Nelson Martell
15
 * @link      http://nelson6e65.github.io/php_nml/
16
 * @since     v0.7.0
17
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
18
 * */
19
20
namespace NelsonMartell\Test\Helpers;
21
22
use Cake\Utility\Inflector;
23
use NelsonMartell\Extensions\Text;
24
use NelsonMartell\IStrictPropertiesContainer;
25
use SebastianBergmann\Exporter\Exporter;
26
27
/**
28
 * Split of ImplementsIStrictPropertiesContainer, for classes implementing any write-only property.
29
 *
30
 * @author Nelson Martell <[email protected]>
31
 * */
32
trait HasWriteOnlyProperties
33
{
34
    /**
35
     * @returns IStrictPropertiesContainer
36
     */
37
    public abstract function testImplementsIStrictPropertiesContainerInterface($obj);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
38
39
    public abstract function writeonlyPropertiesProvider();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
40
41
    /**
42
     * @dataProvider writeonlyPropertiesProvider
43
     */
44
    public function testWriteonlyPropertiesAreWritables(
45
        IStrictPropertiesContainer $obj,
46
        $property,
47
        $value
48
    ) {
49
        $obj->$property = $value;
50
    }
51
52
    /**
53
     * @depends testWriteonlyPropertiesAreWritables
54
     * @dataProvider writeonlyPropertiesProvider
55
     * @expectedException \BadMethodCallException
56
     */
57
    public function testWriteonlyPropertiesAreNotReadables(
58
        IStrictPropertiesContainer $obj,
59
        $property,
60
        $value
61
    ) {
62
        $obj->$property = $value;
63
        $actual = $obj->$property;
0 ignored issues
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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
    }
65
}
66