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; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected $attribute4 = -4; |
79
|
|
|
} |
|
|
|
|
80
|
|
|
|
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 theid
property of an instance of theAccount
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.