Completed
Push — master ( 446f2e...32b2c3 )
by Nelson
11:26
created

A   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getProperty1() 0 4 1
A getAttribute2() 0 5 1
A getProperty3() 0 4 1
A setProperty3() 0 4 1
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Content:
6
 * - Class definition.
7
 *
8
 * Copyright © 2016 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 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\ExampleClass;
21
22
use NelsonMartell\PropertiesHandler;
23
24
/**
25
 * Example class to be used in PropertiesHandler test.
26
 * Not customized.
27
 *
28
 * Prefixes in member names:
29
 * 'property': using getter or setter;
30
 * 'attribute': direct access
31
 */
32
class A
33
{
34
    use PropertiesHandler;
35
36
    public function __construct()
37
    {
38
        // Unset the wrappers
39
        unset(
40
            $this->property1,
41
            $this->property3
42
        );
43
    }
44
45
    /**
46
     * This should not be accesible from external or inherited clases.
47
     * @var [type]
48
     */
49
    private $attribute1 = -1;
50
    public $property1;
51
52
    public function getProperty1()
53
    {
54
        return $this->attribute1;
55
    }
56
57
    protected $attribute2 = -2;
58
59
    public function getAttribute2()
60
    {
61
        // Only from external will use this getter
62
        return $this->attribute2;
63
    }
64
65
    private $attribute3 = -3;
66
    private $property3;
67
68
    public function getProperty3()
69
    {
70
        return $this->attribute3;
71
    }
72
73
    public function setProperty3($value)
74
    {
75
        $this->attribute3 = $value * 100;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value * 100 can also be of type double. However, the property $attribute3 is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
76
    }
77
78
    protected $attribute4 = -4;
79
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
80