Skip to content

Commit

Permalink
Changes for version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gossi committed Nov 4, 2014
1 parent be86f70 commit 63dd0f9
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 78 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.php.core.prefs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
eclipse.preferences.version=1
include_path=
phpVersion=php5.4
use_asp_tags_as_php=false
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Docblock

![DOI](https://zenodo.org/badge/3684/gossi/docblock.png)
[![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.10182.png)](http://dx.doi.org/10.5281/zenodo.10182)
[![Build Status](https://travis-ci.org/gossi/docblock.svg?branch=master)](https://travis-ci.org/gossi/docblock)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gossi/docblock/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gossi/docblock/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/gossi/docblock/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/gossi/docblock/?branch=master)

PHP DocBlock parser and generator. An API to read and write DocBlocks.
PHP Docblock parser and generator. An API to read and write Docblocks.

## Installation

Expand All @@ -27,22 +27,22 @@ require_once 'path/to/vendor/autoload.php';

## Usage

### 1. Generate a DocBlock instance
### 1. Generate a Docblock instance

a) Simple:

```php
use gossi\docblock\DocBlock;
use gossi\docblock\Docblock;

$docblock = new DocBlock();
$docblock = new Docblock();
```

b) Create from string:

```php
use gossi\docblock\DocBlock;
use gossi\docblock\Docblock;

$docblock = new DocBlock('/**
$docblock = new Docblock('/**
* Short Description.
*
* Long Description.
Expand All @@ -54,9 +54,9 @@ $docblock = new DocBlock('/**
c) Create from reflection:

```php
use gossi\docblock\DocBlock;
use gossi\docblock\Docblock;

$docblock = new DocBlock(new \ReflectionClass('MyClass'));
$docblock = new Docblock(new \ReflectionClass('MyClass'));
```

### 2. Manipulate tags
Expand Down Expand Up @@ -123,6 +123,20 @@ Feel free to fork and submit a pull request (don't forget the tests) and I am ha

## Changelog

Version 1.2 - *November, 4th 2014*

* Renamed `DocBlock` to `Docblock`
* Added License Tag
* Added Link Tag

Version 1.1 - *May, 28th 2014*

* Added tag sorting for DocBlock::toString();

Version 1.0.1 - *May, 28th 2014*

* Don't wordwrap long lines anymore. Fixing fluent interface for AbstractTag::setDescription();

Version 1.0 - *May, 28th 2014*

* Initial release
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Docblock Test Suite">
Expand Down
5 changes: 3 additions & 2 deletions src/DocBlock.php → src/Docblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use gossi\docblock\tags\TagFactory;
use gossi\docblock\tags\AbstractTag;

class DocBlock {
class Docblock {

protected $shortDescription;
protected $longDescription;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function cleanInput($comment) {
}

/**
* Splits the DocBlock into a short description, long description and
* Splits the Docblock into a short description, long description and
* block of tags.
*
* @see https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/src/phpDocumentor/Reflection/DocBlock.php Original Method
Expand Down Expand Up @@ -320,6 +320,7 @@ protected function compareTagNames($tagA, $tagB) {
'method', 'deprecated', 'since', 'version', 'var', 'type', 'param',
'throws', 'return'];

// there are never two of the same tags
if ($tagA == $tagB) {
return 0;
}
Expand Down
32 changes: 32 additions & 0 deletions src/tags/AbstractDescriptionTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace gossi\docblock\tags;

/**
* Abstract tag with a description
*/
abstract class AbstractDescriptionTag extends AbstractTag {

protected $description;

/**
* Returns the description
*
* @return string the description
*/
public function getDescription() {
return $this->description;
}

/**
* Sets the description
*
* @param string $description the new description
* @return $this
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}


}
49 changes: 9 additions & 40 deletions src/tags/AbstractTag.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<?php

namespace gossi\docblock\tags;

/**
* Abstract tag
*/
abstract class AbstractTag {

protected $tagName;
protected $description;

/**
* Creates a new tag instance
*
*
* @return $this
*/
public static function create($content = '') {
return new static($content);
}

/**
* Creates a new tag instance
*
*
* @param string $tagName
* @param string $content
*/
Expand All @@ -31,48 +28,21 @@ protected function __construct($tagName, $content = '') {

/**
* Returns the tag name.
*
*
* @return string the tag name
*/
public function getTagName() {
return $this->tagName;
}

/**
* Returns the description
*
* @return string the description
*/
public function getDescription() {
return $this->description;
}

/**
* Sets the description
*
* @param string $description the new description
* @return $this
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}

/**
* Parses the given string
*
*
* @param string $content
*/
abstract protected function parse($content);

/**
* Returns the string version of the tag in one line
*
* @return string
*/
public function toString() {
return sprintf('@%s %s', $this->tagName, $this->description);
}
abstract protected function toString();

/**
* Magic toString() method
Expand All @@ -82,5 +52,4 @@ public function toString() {
public function __toString() {
return $this->toString();
}

}
}
2 changes: 1 addition & 1 deletion src/tags/AbstractTypeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Represents tags which are in the format
* @tag [Type] [Description]
*/
abstract class AbstractTypeTag extends AbstractTag {
abstract class AbstractTypeTag extends AbstractDescriptionTag {

protected $type;

Expand Down
2 changes: 1 addition & 1 deletion src/tags/AbstractVersionTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Represents tags which are in the format
* @tag [Version] [Description]
*/
abstract class AbstractVersionTag extends AbstractTag {
abstract class AbstractVersionTag extends AbstractDescriptionTag {

/**
* PCRE regular expression matching a version vector.
Expand Down
2 changes: 1 addition & 1 deletion src/tags/DeprecatedTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class DeprecatedTag extends AbstractVersionTag {
public function __construct($content = '') {
parent::__construct('deprecated', $content);
}

}
80 changes: 80 additions & 0 deletions src/tags/LicenseTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
namespace gossi\docblock\tags;

/**
* Represents a @license tag.
*
* @see http://www.phpdoc.org/docs/latest/references/phpdoc/tags/license.html
*/
class LicenseTag extends AbstractTag {

private $url;
private $license;

/**
* Creates a new tag
*
* @param string $tagName the tag name
* @param string $content the tags content
*/
public function __construct($content = '') {
parent::__construct('license', $content);
}

protected function parse($content) {
$parts = preg_split('/\s+/Su', $content, 2);

$urlCandidate = $parts[0];
if (preg_match(LinkTag::URL_REGEX, $urlCandidate)) {
$this->url = $urlCandidate;
$this->license = isset($parts[1]) ? $parts[1] : '';
} else {
$this->license = $content;
}
}

/**
* Returns the url
*
* @return string the url
*/
public function getUrl() {
return $this->url;
}

/**
* Sets the url
*
* @param string $url
* @return $this
*/
public function setUrl($url) {
$this->url = $url;
return $this;
}

/**
* Returns the license
*
* @return string
*/
public function getLicense() {
return $this->license;
}

/**
* Sets the license
*
* @param string $license
* @return $this
*/
public function setLicense($license) {
$this->license = $license;
return $this;
}

public function toString() {
return sprintf('@license %s', trim($this->url . ' ' . $this->license));
}

}
Loading

0 comments on commit 63dd0f9

Please sign in to comment.