Skip to content

Commit feb7b00

Browse files
Use PHP_Token_INTERFACE::getPackage().
1 parent eeb2e7a commit feb7b00

File tree

3 files changed

+10
-149
lines changed

3 files changed

+10
-149
lines changed

PHP/CodeCoverage/Report/Clover.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,39 +197,35 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
197197
);
198198
}
199199

200-
$package = PHP_CodeCoverage_Util::getPackageInformation(
201-
$className, $_class['docblock']
202-
);
203-
204-
if (!empty($package['namespace'])) {
205-
$namespace = $package['namespace'];
200+
if (!empty($_class['package']['namespace'])) {
201+
$namespace = $_class['package']['namespace'];
206202
}
207203

208204
$class = $document->createElement('class');
209205
$class->setAttribute('name', $className);
210206
$class->setAttribute('namespace', $namespace);
211207

212-
if (!empty($package['fullPackage'])) {
208+
if (!empty($_class['package']['fullPackage'])) {
213209
$class->setAttribute(
214-
'fullPackage', $package['fullPackage']
210+
'fullPackage', $_class['package']['fullPackage']
215211
);
216212
}
217213

218-
if (!empty($package['category'])) {
214+
if (!empty($_class['package']['category'])) {
219215
$class->setAttribute(
220-
'category', $package['category']
216+
'category', $_class['package']['category']
221217
);
222218
}
223219

224-
if (!empty($package['package'])) {
220+
if (!empty($_class['package']['package'])) {
225221
$class->setAttribute(
226-
'package', $package['package']
222+
'package', $_class['package']['package']
227223
);
228224
}
229225

230-
if (!empty($package['subpackage'])) {
226+
if (!empty($_class['package']['subpackage'])) {
231227
$class->setAttribute(
232-
'subpackage', $package['subpackage']
228+
'subpackage', $_class['package']['subpackage']
233229
);
234230
}
235231

PHP/CodeCoverage/Util.php

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -328,52 +328,6 @@ public static function getLinesToBeIgnored($filename)
328328
return self::$ignoredLines[$filename];
329329
}
330330

331-
/**
332-
* Returns the package information of a user-defined class.
333-
*
334-
* @param string $className
335-
* @param string $docComment
336-
* @return array
337-
*/
338-
public static function getPackageInformation($className, $docComment)
339-
{
340-
$result = array(
341-
'namespace' => '',
342-
'fullPackage' => '',
343-
'category' => '',
344-
'package' => '',
345-
'subpackage' => ''
346-
);
347-
348-
if (strpos($className, '\\') !== FALSE) {
349-
$result['namespace'] = self::arrayToName(
350-
explode('\\', $className)
351-
);
352-
}
353-
354-
if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) {
355-
$result['category'] = $matches[1];
356-
}
357-
358-
if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) {
359-
$result['package'] = $matches[1];
360-
$result['fullPackage'] = $matches[1];
361-
}
362-
363-
if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) {
364-
$result['subpackage'] = $matches[1];
365-
$result['fullPackage'] .= '.' . $matches[1];
366-
}
367-
368-
if (empty($result['fullPackage'])) {
369-
$result['fullPackage'] = self::arrayToName(
370-
explode('_', str_replace('\\', '_', $className)), '.'
371-
);
372-
}
373-
374-
return $result;
375-
}
376-
377331
/**
378332
* Returns a filesystem safe version of the passed filename.
379333
* This function does not operate on full paths, just filenames.
@@ -515,26 +469,6 @@ public static function reducePaths(&$files)
515469
return $commonPath;
516470
}
517471

518-
/**
519-
* Returns the package information of a user-defined class.
520-
*
521-
* @param array $parts
522-
* @param string $join
523-
* @return string
524-
*/
525-
protected static function arrayToName(array $parts, $join = '\\')
526-
{
527-
$result = '';
528-
529-
if (count($parts) > 1) {
530-
array_pop($parts);
531-
532-
$result = join($join, $parts);
533-
}
534-
535-
return $result;
536-
}
537-
538472
/**
539473
* @param string $coveredElement
540474
* @return array

Tests/PHP/CodeCoverage/UtilTest.php

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -253,75 +253,6 @@ public function testGetLinesToBeIgnored2()
253253
);
254254
}
255255

256-
/**
257-
* @covers PHP_CodeCoverage_Util::getPackageInformation
258-
*/
259-
public function testGetPackageInformation()
260-
{
261-
$this->assertEquals(
262-
array(
263-
'category' => 'Foo',
264-
'fullPackage' => 'Bar.Baz',
265-
'namespace' => '',
266-
'package' => 'Bar',
267-
'subpackage' => 'Baz'
268-
),
269-
PHP_CodeCoverage_Util::getPackageInformation(
270-
'Foo',
271-
'/**
272-
* @category Foo
273-
* @package Bar
274-
* @subpackage Baz
275-
*/'
276-
)
277-
);
278-
}
279-
280-
/**
281-
* @covers PHP_CodeCoverage_Util::getPackageInformation
282-
* @covers PHP_CodeCoverage_Util::arrayToName
283-
*/
284-
public function testGetPackageInformation2()
285-
{
286-
$this->assertEquals(
287-
array(
288-
'category' => 'Foo',
289-
'fullPackage' => 'Bar.Baz',
290-
'namespace' => 'Foo',
291-
'package' => 'Bar',
292-
'subpackage' => 'Baz'
293-
),
294-
PHP_CodeCoverage_Util::getPackageInformation(
295-
'Foo\\Bar',
296-
'/**
297-
* @category Foo
298-
* @package Bar
299-
* @subpackage Baz
300-
*/'
301-
)
302-
);
303-
}
304-
305-
/**
306-
* @covers PHP_CodeCoverage_Util::getPackageInformation
307-
*/
308-
public function testGetPackageInformation3()
309-
{
310-
$this->assertEquals(
311-
array(
312-
'category' => '',
313-
'fullPackage' => '',
314-
'namespace' => '',
315-
'package' => '',
316-
'subpackage' => ''
317-
),
318-
PHP_CodeCoverage_Util::getPackageInformation(
319-
'Foo',
320-
''
321-
)
322-
);
323-
}
324-
325256
/**
326257
* @covers PHP_CodeCoverage_Util::reducePaths
327258
*/

0 commit comments

Comments
 (0)