Skip to content

Commit

Permalink
Support multiple copyrights, and extract @copyright content from docb…
Browse files Browse the repository at this point in the history
…lock descriptions.
  • Loading branch information
yunosh committed Mar 9, 2017
1 parent f745902 commit 4415ea0
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
Expand Up @@ -39,7 +39,7 @@ class FileLevelDocBlock extends Base
*
* @var string
*/
public $fileSummaryRegexp = '/Copyright \d{4}(-\d{4})? Horde LLC \(http:\/\/www\.horde\.org\/\)/';
public $fileSummaryRegexp = '/Copyright \d{4}(-\d{4})? .+/';

/**
* Default description for new, empty file-level DocBlocks.
Expand Down Expand Up @@ -123,6 +123,13 @@ class FileLevelDocBlock extends Base
*/
public $classForbiddenTags = array();

/**
* Regular expression to extract copyrights from description.
*
* @var string
*/
public $copyrightExtractRegexp = '/Copyright (\d{4}(?:-\d{4})? .+)(?:\s+\(?http:.+)/';

/**
* Default license name for new, empty DocBlocks.
*
Expand Down
13 changes: 6 additions & 7 deletions framework/Refactor/lib/Horde/Refactor/Rule/FileLevelDocBlock.php
Expand Up @@ -480,14 +480,13 @@ protected function _getDocBlock($descriptions, array $tags)
*/
protected function _processDocBlock($block)
{
if (preg_match($this->_config->licenseExtractRegexp, $block->getText(), $match)) {
$this->_config->license = $match[1];
}
if (preg_match($this->_config->licenseUrlExtractRegexp, $block->getText(), $match)) {
$this->_config->licenseUrl = $match[1];
foreach (array('license', 'licenseUrl', 'year') as $property) {
if (preg_match($this->_config->{$property . 'ExtractRegexp'}, $block->getText(), $match)) {
$this->_config->$property = $match[1];
}
}
if (preg_match($this->_config->yearExtractRegexp, $block->getText(), $match)) {
$this->_config->year = $match[1];
if (preg_match_all($this->_config->copyrightExtractRegexp, $block->getText(), $match)) {
$this->_config->classTags['copyright'] = $match[1];
}
if ($tags = $block->getTagsByName('copyright')) {
foreach ($tags as $tag) {
Expand Down
4 changes: 4 additions & 0 deletions framework/Refactor/package.xml
Expand Up @@ -175,13 +175,15 @@
<file name="ConfiguredNoFileLevelDocBlock.php" role="test" />
<file name="ExtractYearFixTagOrder.php" role="test" />
<file name="NoFileLevelDocBlock.php" role="test" />
<file name="OtherCopyright.php" role="test" />
</dir> <!-- /test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored -->
<file name="ClassLevelDocBlock.php" role="test" />
<file name="ClassLevelDocBlockWithFileLevelDocs.php" role="test" />
<file name="CorrectDocBlocks.php" role="test" />
<file name="ExtractYearFixTagOrder.php" role="test" />
<file name="IncorrectDocBlocks.php" role="test" />
<file name="NoFileLevelDocBlock.php" role="test" />
<file name="OtherCopyright.php" role="test" />
</dir> <!-- /test/Horde/Refactor/fixtures/FileLevelDocBlock -->
<dir name="Php4Constructor">
<dir name="refactored">
Expand Down Expand Up @@ -336,11 +338,13 @@
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/ExtractYearFixTagOrder.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/ExtractYearFixTagOrder.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/IncorrectDocBlocks.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/IncorrectDocBlocks.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/NoFileLevelDocBlock.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/NoFileLevelDocBlock.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/OtherCopyright.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/OtherCopyright.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ClassLevelDocBlock.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ClassLevelDocBlock.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ClassLevelDocBlockWithFileLevelDocs.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ClassLevelDocBlockWithFileLevelDocs.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ConfiguredNoFileLevelDocBlock.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ConfiguredNoFileLevelDocBlock.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ExtractYearFixTagOrder.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/ExtractYearFixTagOrder.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/NoFileLevelDocBlock.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/NoFileLevelDocBlock.php" />
<install as="Horde/Refactor/fixtures/FileLevelDocBlock/refactored/OtherCopyright.php" name="test/Horde/Refactor/fixtures/FileLevelDocBlock/refactored/OtherCopyright.php" />
<install as="Horde/Refactor/fixtures/Php4Constructor/Php4ConstructorOnly.php" name="test/Horde/Refactor/fixtures/Php4Constructor/Php4ConstructorOnly.php" />
<install as="Horde/Refactor/fixtures/Php4Constructor/Php5Constructor.php" name="test/Horde/Refactor/fixtures/Php4Constructor/Php5Constructor.php" />
<install as="Horde/Refactor/fixtures/Php4Constructor/WrongConstructorOrder.php" name="test/Horde/Refactor/fixtures/Php4Constructor/WrongConstructorOrder.php" />
Expand Down
Expand Up @@ -116,6 +116,7 @@ public function getFileNames()
array('ClassLevelDocBlock.php', false),
array('ClassLevelDocBlockWithFileLevelDocs.php', false),
array('ExtractYearFixTagOrder.php', false),
array('OtherCopyright.php', false),
);
}
}
@@ -0,0 +1,25 @@
<?php
/**
* Copyright 2006 AMCME, Inc. http://www.acme.org/
* Copyright 2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did
* not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Some Author <author@acme.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Auth
*/

/**
* This class does stuff.
*
* @author Some Author <author@acme.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Auth
*/
class Foo
{
}
@@ -0,0 +1,27 @@
<?php
/**
* Copyright 2006 AMCME, Inc. http://www.acme.org/
* Copyright 2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did
* not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Some Author <author@acme.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Auth
*/

/**
* This class does stuff.
*
* @author Some Author <author@acme.org>
* @category Horde
* @copyright 2006 AMCME, Inc.
* @copyright 2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Auth
*/
class Foo
{
}

0 comments on commit 4415ea0

Please sign in to comment.