|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpToZephir\Converter\Printer\Stmt; |
|
4
|
|
|
|
|
5
|
|
|
use PhpToZephir\Converter\Dispatcher; |
|
6
|
|
|
use PhpToZephir\Logger; |
|
7
|
|
|
use PhpParser\Node\Stmt; |
|
8
|
|
|
use PhpToZephir\ReservedWordReplacer; |
|
9
|
|
|
use PhpToZephir\Converter\Manipulator\ClassManipulator; |
|
10
|
|
|
|
|
11
|
|
|
class InterfacePrinter |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var Dispatcher |
|
15
|
|
|
*/ |
|
16
|
|
|
private $dispatcher = null; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Logger |
|
19
|
|
|
*/ |
|
20
|
|
|
private $logger = null; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var ClassManipulator |
|
23
|
|
|
*/ |
|
24
|
|
|
private $classManipulator = null; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ReservedWordReplacer |
|
27
|
|
|
*/ |
|
28
|
|
|
private $reservedWordReplacer = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Dispatcher $dispatcher |
|
32
|
|
|
* @param Logger $logger |
|
33
|
|
|
* @param ClassManipulator $classManipulator |
|
34
|
|
|
* @param ReservedWordReplacer $reservedWordReplacer |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function __construct( |
|
37
|
|
|
Dispatcher $dispatcher, |
|
38
|
|
|
Logger $logger, |
|
39
|
|
|
ClassManipulator $classManipulator, |
|
40
|
|
|
ReservedWordReplacer $reservedWordReplacer |
|
41
|
|
|
) { |
|
42
|
1 |
|
$this->dispatcher = $dispatcher; |
|
|
|
|
|
|
43
|
1 |
|
$this->logger = $logger; |
|
|
|
|
|
|
44
|
1 |
|
$this->classManipulator = $classManipulator; |
|
|
|
|
|
|
45
|
1 |
|
$this->reservedWordReplacer = $reservedWordReplacer; |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
public static function getType() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return 'pStmt_Interface'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
4 |
|
public function convert(Stmt\Interface_ $node) |
|
54
|
|
|
{ |
|
55
|
4 |
|
$node->name = $this->reservedWordReplacer->replace($node->name); |
|
56
|
|
|
|
|
57
|
4 |
|
$extendsStmt = ''; |
|
58
|
|
|
|
|
59
|
4 |
|
if (!empty($node->extends)) { |
|
60
|
|
|
$extendsStmt = ' extends '; |
|
61
|
|
|
$extends = array(); |
|
|
|
|
|
|
62
|
|
|
foreach ($node->extends as $extend) { |
|
63
|
|
|
$extends[] = $this->reservedWordReplacer->replace($extend); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$extendsStmt .= implode(', ', $extends); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
4 |
|
return 'interface '.$node->name |
|
70
|
4 |
|
.$extendsStmt |
|
71
|
4 |
|
."\n".'{'.$this->dispatcher->pStmts($node->stmts)."\n".'}'; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
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
will produce issues in the first and second line, while this second example
will produce no issues.