Skip to content

Commit 4cf9130

Browse files
authored
Merge pull request #133 from delmicio/master
Comment extractor now acepts multiple strings (v4)
2 parents 8b9632c + 3e96ceb commit 4cf9130

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/Extractors/PhpCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PhpCode extends Extractor implements ExtractorInterface
1414
// - false: to not extract comments
1515
// - empty string: to extract all comments
1616
// - non-empty string: to extract comments that start with that string
17+
// - array with strings to extract comments format.
1718
'extractComments' => false,
1819

1920
'constants' => [],

src/Utils/PhpFunctionsScanner.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ class PhpFunctionsScanner extends FunctionsScanner
1616
/**
1717
* If not false, comments will be extracted.
1818
*
19-
* @var string|false
19+
* @var string|false|array
2020
*/
2121
protected $extractComments = false;
2222

2323
/**
2424
* Enable extracting comments that start with a tag (if $tag is empty all the comments will be extracted).
2525
*
26-
* @param string $tag
26+
* @param mixed $tag
2727
*/
2828
public function enableCommentsExtraction($tag = '')
2929
{
30-
$this->extractComments = (string) $tag;
30+
$this->extractComments = $tag;
3131
}
3232

3333
/**
@@ -157,11 +157,20 @@ protected function parsePhpComment($value)
157157
$value = substr($value, 2, -2);
158158
}
159159
$value = trim($value);
160-
if ($value !== '' && ($this->extractComments === '' || strpos($value, $this->extractComments) === 0)) {
161-
$result = $value;
160+
if ($value !== '') {
161+
if ($this->extractComments === '' || strpos($value, $this->extractComments) === 0) {
162+
$result = $value;
163+
}
164+
elseif (is_array($this->extractComments)) {
165+
foreach ($this->extractComments as $string) {
166+
if (strpos($value, $string) === 0) {
167+
$result = $value;
168+
break;
169+
}
170+
}
171+
}
162172
}
163173
}
164-
165174
return $result;
166175
}
167176
}

0 commit comments

Comments
 (0)