File tree Expand file tree Collapse file tree 4 files changed +229
-33
lines changed Expand file tree Collapse file tree 4 files changed +229
-33
lines changed Original file line number Diff line number Diff line change @@ -10,38 +10,23 @@ use Nette\PhpGenerator\ClassType;
10
10
11
11
12
12
require __DIR__ . '/../bootstrap.php ' ;
13
+ require __DIR__ . '/fixtures/traits.php ' ;
13
14
14
15
15
- /**
16
- * Trait1
17
- */
18
- trait Trait1
19
- {
20
- public function func1 ()
21
- {
22
- }
23
- }
24
-
25
- trait Trait2
26
- {
27
- protected function func2 ()
28
- {
29
- }
30
- }
31
-
32
- abstract class Class1
33
- {
34
- use Trait1;
35
- use Trait2;
36
- }
37
-
38
- class Class2 extends Class1
39
- {
40
- }
41
-
42
16
$ res [] = ClassType::from ('Trait1 ' );
43
17
$ res [] = ClassType::from ('Trait2 ' );
44
18
$ res [] = ClassType::from ('Class1 ' );
45
19
$ res [] = ClassType::from ('Class2 ' );
20
+ $ res [] = ClassType::from ('Class3 ' );
46
21
47
22
sameFile (__DIR__ . '/expected/ClassType.from.trait.expect ' , implode ("\n" , $ res ));
23
+
24
+
25
+ $ res = [];
26
+ $ res [] = ClassType::withBodiesFrom ('Trait1 ' );
27
+ $ res [] = ClassType::withBodiesFrom ('Trait2 ' );
28
+ $ res [] = ClassType::withBodiesFrom ('Class1 ' );
29
+ $ res [] = ClassType::withBodiesFrom ('Class2 ' );
30
+ $ res [] = ClassType::withBodiesFrom ('Class3 ' );
31
+
32
+ sameFile (__DIR__ . '/expected/ClassType.from.trait.bodies.expect ' , implode ("\n" , $ res ));
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Trait1
3
+ */
4
+ trait Trait1
5
+ {
6
+ public $x1;
7
+
8
+
9
+ public function f1()
10
+ {
11
+ echo 'Trait1::f1';
12
+ }
13
+ }
14
+
15
+ trait Trait2
16
+ {
17
+ protected $x2;
18
+ public $x1;
19
+
20
+
21
+ public function f2()
22
+ {
23
+ echo 'Trait2::f2';
24
+ }
25
+
26
+
27
+ public function f1()
28
+ {
29
+ }
30
+ }
31
+
32
+ class Class1 extends ParentClass
33
+ {
34
+ protected $x2;
35
+
36
+
37
+ public function f1()
38
+ {
39
+ }
40
+
41
+
42
+ public function f2()
43
+ {
44
+ }
45
+ }
46
+
47
+ class Class2 extends ParentClass
48
+ {
49
+ public $x1;
50
+ protected $x2;
51
+
52
+
53
+ public function f1()
54
+ {
55
+ echo 'Class2::f1';
56
+ }
57
+
58
+
59
+ public function f2()
60
+ {
61
+ }
62
+ }
63
+
64
+ class Class3 extends ParentClass
65
+ {
66
+ public $x1;
67
+ protected $x2;
68
+
69
+
70
+ public function f1()
71
+ {
72
+ echo 'Class3::f1';
73
+ }
74
+
75
+
76
+ public function f2()
77
+ {
78
+ }
79
+
80
+
81
+ public function aliased()
82
+ {
83
+ }
84
+ }
Original file line number Diff line number Diff line change 3
3
*/
4
4
trait Trait1
5
5
{
6
- public function func1()
6
+ public $x1;
7
+
8
+
9
+ public function f1()
7
10
{
8
11
}
9
12
}
10
13
11
14
trait Trait2
12
15
{
13
- protected function func2()
16
+ protected $x2;
17
+ public $x1;
18
+
19
+
20
+ public function f2()
21
+ {
22
+ }
23
+
24
+
25
+ public function f1()
14
26
{
15
27
}
16
28
}
17
29
18
- abstract class Class1
30
+ class Class1 extends ParentClass
19
31
{
20
- public function func1()
32
+ protected $x2;
33
+
34
+
35
+ public function f1()
21
36
{
22
37
}
23
38
24
39
25
- protected function func2 ()
40
+ public function f2 ()
26
41
{
27
42
}
28
43
}
29
44
30
- class Class2 extends Class1
45
+ class Class2 extends ParentClass
31
46
{
47
+ public $x1;
48
+ protected $x2;
49
+
50
+
51
+ public function f1()
52
+ {
53
+ }
54
+
55
+
56
+ public function f2()
57
+ {
58
+ }
59
+ }
60
+
61
+ class Class3 extends ParentClass
62
+ {
63
+ public $x1;
64
+ protected $x2;
65
+
66
+
67
+ public function f1()
68
+ {
69
+ }
70
+
71
+
72
+ public function f2()
73
+ {
74
+ }
75
+
76
+
77
+ public function aliased()
78
+ {
79
+ }
32
80
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ /**
6
+ * Trait1
7
+ */
8
+ trait Trait1
9
+ {
10
+ public $ x1 ;
11
+
12
+
13
+ public function f1 ()
14
+ {
15
+ echo 'Trait1::f1 ' ;
16
+ }
17
+ }
18
+
19
+
20
+ trait Trait2
21
+ {
22
+ use Trait1;
23
+
24
+ protected $ x2 ;
25
+
26
+
27
+ public function f2 ()
28
+ {
29
+ echo 'Trait2::f2 ' ;
30
+ }
31
+ }
32
+
33
+
34
+ class ParentClass
35
+ {
36
+ public $ x1 ;
37
+
38
+
39
+ public function f1 ()
40
+ {
41
+ echo 'ParentClass::f1 ' ;
42
+ }
43
+ }
44
+
45
+
46
+ class Class1 extends ParentClass
47
+ {
48
+ use Trait2;
49
+ }
50
+
51
+
52
+ class Class2 extends ParentClass
53
+ {
54
+ use Trait2;
55
+
56
+ public $ x1 ;
57
+
58
+
59
+ public function f1 ()
60
+ {
61
+ echo 'Class2::f1 ' ;
62
+ }
63
+ }
64
+
65
+
66
+ class Class3 extends ParentClass
67
+ {
68
+ use Trait2 {
69
+ Trait2::f1 as aliased;
70
+ }
71
+
72
+ public $ x1 ;
73
+
74
+
75
+ public function f1 ()
76
+ {
77
+ echo 'Class3::f1 ' ;
78
+ }
79
+ }
You can’t perform that action at this time.
0 commit comments