1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by IntelliJ IDEA. |
4
|
|
|
* User: yoshi |
5
|
|
|
* Date: 26.01.16 |
6
|
|
|
* Time: 12:42 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace CodeMine\ConfluenceImporter\Parser; |
10
|
|
|
use CodeMine\ConfluenceImporter\Parser\File\File; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Parser |
14
|
|
|
* @package CodeMine\ConfluenceImporter\Parser |
15
|
|
|
*/ |
16
|
|
|
class Parser |
17
|
|
|
{ |
18
|
|
|
private $xmlString; |
19
|
|
|
|
20
|
|
|
private $classArray; |
21
|
|
|
private $package; |
22
|
|
|
private $namespace; |
23
|
|
|
private $deprecated; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Parser constructor. |
27
|
|
|
* @param string $path |
28
|
|
|
*/ |
29
|
|
|
public function __construct($path = '/home/yoshi/projekty/PhpDoc-Confluence-Importer/docs/structure.xml') |
30
|
|
|
{ |
31
|
|
|
$this->xmlString = file_get_contents($path); |
32
|
|
|
|
33
|
|
|
$array = $this->xmlToArray($this->xmlString); |
34
|
|
|
|
35
|
|
|
$this->classArray = $array['file']; |
36
|
|
|
$this->package = $array['package']; |
37
|
|
|
$this->namespace = $array['namespace']; |
38
|
|
|
$this->deprecated = $array['deprecated']; |
39
|
|
|
|
40
|
|
|
$this->prepareFiles(); |
41
|
|
|
// print_r($this->fileArray);die; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
private function prepareFiles() |
46
|
|
|
{ |
47
|
|
|
$fileCollection = new \SplObjectStorage(); |
48
|
|
|
|
49
|
|
|
foreach ($this->classArray as $class){ |
50
|
|
|
|
51
|
|
|
$file = new File(); |
52
|
|
|
|
53
|
|
|
if (isset($class['@attributes'])){ |
54
|
|
|
$path = $class['@attributes']['path']; |
|
|
|
|
55
|
|
|
$package = $class['@attributes']['package']; |
56
|
|
|
$file->setPath($path); |
57
|
|
|
$file->setPackage($package); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
foreach ($class as $key => $value){ |
61
|
|
|
switch($key){ |
62
|
|
|
case 'class': |
63
|
|
|
$file->setType($key); |
64
|
|
|
$file->setAbstract(strtolower($class['class']['@attributes']['abstract']) === 'true'); |
65
|
|
|
$file->setFinal(strtolower($class['class']['@attributes']['final']) === 'true'); |
66
|
|
|
$file->setNamespace($class['class']['@attributes']['namespace']); |
67
|
|
|
$file->setExtends(is_array($class['class']['extends']) ? NULL : $class['class']['extends']); |
68
|
|
|
|
69
|
|
|
if (isset($class['class']['implements'])) { |
70
|
|
|
$file->setImplements($class['class']['implements']); |
71
|
|
|
|
72
|
|
|
//// var_dump($array['file'][0]['class']['constant'][0]['name']); |
73
|
|
|
//// var_dump($array['file'][0]['class']['constant'][0]['full_name']); |
74
|
|
|
//// var_dump($array['file'][0]['class']['constant'][0]['value']); |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (isset($class['namespace-alias'])){ |
80
|
|
|
$file->setNamespaceAlias($class['namespace-alias']); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($class['constant'])){ |
84
|
|
|
$file->setConstant(); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
echo $key . PHP_EOL; |
89
|
|
|
break; |
90
|
|
|
case 'interface': |
91
|
|
|
$file->setType($key); |
92
|
|
|
$file->setNamespace($class['interface']['@attributes']['namespace']); |
93
|
|
|
if (isset($class['namespace-alias'])){ |
94
|
|
|
$file->setNamespaceAlias($class['namespace-alias']); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
echo $key . PHP_EOL; |
98
|
|
|
break; |
99
|
|
|
case 'trait': |
100
|
|
|
$file->setType($key); |
101
|
|
|
if (isset($class['namespace-alias'])){ |
102
|
|
|
$file->setNamespaceAlias($class['namespace-alias']); |
103
|
|
|
} |
104
|
|
|
echo $key . PHP_EOL; |
105
|
|
|
break; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$fileCollection->attach($file); |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $fileCollection; |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param $xmlString |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function xmlToJson($xmlString) |
127
|
|
|
{ |
128
|
|
|
$json = $this->generateJson($xmlString); |
129
|
|
|
|
130
|
|
|
return $json; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $xmlString |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
|
|
public function xmlToArray($xmlString) |
138
|
|
|
{ |
139
|
|
|
$json = $this->generateJson($xmlString); |
|
|
|
|
140
|
|
|
$array = json_decode($json, true); |
141
|
|
|
|
142
|
|
|
return $array; |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param $xmlString |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
private function generateJson($xmlString) |
151
|
|
|
{ |
152
|
|
|
$xml = simplexml_load_string($xmlString); |
153
|
|
|
$json = json_encode($xml); |
154
|
|
|
|
155
|
|
|
return $json; |
156
|
|
|
} |
157
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.