Skip to content

Commit

Permalink
+ Filter out fenced code out of comments #28
Browse files Browse the repository at this point in the history
* Enable debug mode in run-test script
  • Loading branch information
pmaselkowski committed Mar 10, 2016
1 parent 0c4d589 commit c9b4d62
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion run-test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rm -rf runtime/addendum/*
vendor/bin/codecept run unit "$@"Test.php
vendor/bin/codecept run unit "$@"Test.php --debug
10 changes: 8 additions & 2 deletions src/Addendum.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use Maslosoft\Addendum\Collections\AddendumPlugins;
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
use Maslosoft\Addendum\Interfaces\AnnotationInterface;
use Maslosoft\Addendum\Matcher\AnnotationsMatcher;
use Maslosoft\Addendum\Matcher\ClassLiteralMatcher;
use Maslosoft\Addendum\Plugins\Matcher\DefencerDecorator;
use Maslosoft\Addendum\Plugins\Matcher\UseResolverDecorator;
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedClass;
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
Expand All @@ -36,6 +38,7 @@
use Psr\Log\NullLogger;
use ReflectionClass;
use ReflectionException;
use Reflector;

class Addendum implements LoggerAwareInterface
{
Expand Down Expand Up @@ -76,6 +79,9 @@ class Addendum implements LoggerAwareInterface
'matcher' => [
ClassLiteralMatcher::class => [
UseResolverDecorator::class
],
AnnotationsMatcher::class => [
DefencerDecorator::class
]
]
];
Expand Down Expand Up @@ -308,10 +314,10 @@ public static function cacheClear()

/**
* TODO This should not be static
* @param \Reflector $reflection
* @param Reflector $reflection
* @return mixed[]
*/
public static function getDocComment(\Reflector $reflection)
public static function getDocComment(Reflector $reflection)
{
// NOTE: Due to a nature of traits, raw doc parsing is always needed
// When using reflection's method `getDocComment` it will return
Expand Down
3 changes: 3 additions & 0 deletions src/Builder/DocComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public function forFile($name, $className = null)
{
$fqn = $className;
}
/**
* TODO Use some container here with ArrayAccess interface. Array-like access is *required* here.
*/
$result = [
'namespace' => isset(self::$namespaces[$fqn]) ? self::$namespaces[$fqn] : [],
'use' => isset(self::$use[$fqn]) ? self::$use[$fqn] : [],
Expand Down
7 changes: 7 additions & 0 deletions src/Matcher/AnnotationsMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@

use Maslosoft\Addendum\Exceptions\ParseException;
use Maslosoft\Addendum\Interfaces\Matcher\MatcherInterface;
use Maslosoft\Addendum\Matcher\Helpers\Processor;

class AnnotationsMatcher implements MatcherInterface
{

use Traits\PluginsTrait;

protected function process($string)
{
return Processor::process($this, $string);
}

public function matches($string, &$annotations)
{
$string = $this->process($string);
$annotations = [];
$annotationMatcher = new AnnotationMatcher;
$annotationMatcher->setPlugins($this->getPlugins());
Expand Down
29 changes: 29 additions & 0 deletions src/Plugins/Matcher/DefencerDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace Maslosoft\Addendum\Plugins\Matcher;

use Maslosoft\Addendum\Helpers\Fence;
use Maslosoft\Addendum\Interfaces\Matcher\MatcherInterface;
use Maslosoft\Addendum\Interfaces\Plugins\Matcher\MatcherDecoratorInterface;

/**
* Remove fenced comments from annotations.
* This allows to write php doc with annotations - these documentation annotations will not get parsed.
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class DefencerDecorator implements MatcherDecoratorInterface
{

public function decorate(MatcherInterface $matcher, &$value)
{
Fence::out($value);
}

}

0 comments on commit c9b4d62

Please sign in to comment.