Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrooo committed Jul 15, 2015
1 parent 1eb7aa3 commit b67fef6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
37 changes: 23 additions & 14 deletions src/WSDL/Parser/ClassParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,42 @@
*/
class ClassParser
{
private $_reflectedClass;
/**
* @var ReflectionClass
*/
private $reflectedClass;
/**
* @var MethodParser[]
*/
private $_methodDocComments = array();
private $methodDocComments = array();

public function __construct($className)
{
$this->_reflectedClass = new ReflectionClass($className);
$this->reflectedClass = new ReflectionClass($className);
}

public function parse()
{
$this->_getAllPublicMethodDocComment();
$this->allPublicMethodDocComment();
}

private function _getAllPublicMethodDocComment()
private function allPublicMethodDocComment()
{
$reflectionClassMethods = $this->_reflectedClass->getMethods();
foreach ($reflectionClassMethods as $method) {
if ($this->_checkCanParseMethod($method)) {
$methodName = $method->getName();
$methodDocComment = $method->getDocComment();
$this->_methodDocComments[] = new MethodParser($methodName, $methodDocComment);
$reflectionClassMethods = $this->reflectedClass->getMethods();
foreach ($reflectionClassMethods as $reflectionMethod) {
if ($this->canParseMethod($reflectionMethod)) {
$methodName = $reflectionMethod->getName();
$methodDocComment = $reflectionMethod->getDocComment();
$this->methodDocComments[] = new MethodParser($methodName, $methodDocComment);
}
}
return $this;
}

private function _checkCanParseMethod(ReflectionMethod $method)
/**
* @param ReflectionMethod $method
* @return bool
*/
private function canParseMethod(ReflectionMethod $method)
{
return
Strings::contains($method->getDocComment(), '@WebMethod') &&
Expand All @@ -73,8 +79,11 @@ private function _checkCanParseMethod(ReflectionMethod $method)
!Strings::contains($method->getName(), '__');
}

/**
* @return MethodParser[]
*/
public function getMethods()
{
return $this->_methodDocComments;
return $this->methodDocComments;
}
}
65 changes: 48 additions & 17 deletions src/WSDL/Parser/MethodParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace WSDL\Parser;

use Ouzo\Utilities\Arrays;
use Ouzo\Utilities\Functions;
use WSDL\Types\Type;

/**
Expand All @@ -33,21 +34,36 @@
*/
class MethodParser
{
private $_name;
private $_doc;
private $_rawParameters;
private $_rawReturn;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $doc;
/**
* @var array
*/
private $rawParameters;
/**
* @var string
*/
private $rawReturn;

public function __construct($name, $doc)
{
$this->_name = $name;
$this->_doc = $doc;
$this->name = $name;
$this->doc = $doc;
}

/**
* @return string
*/
public function description()
{
preg_match('#@desc (.+)#', $this->_doc, $groupMatches);
$trimGroupMatches = array_map('trim', $groupMatches);
preg_match('#@desc (.+)#', $this->doc, $groupMatches);
$trimGroupMatches = Arrays::map($groupMatches, Functions::trim());
return Arrays::getValue($trimGroupMatches, 1, '');
}

Expand All @@ -56,41 +72,56 @@ public function description()
*/
public function parameters()
{
preg_match_all('#@param (.+)#', $this->_doc, $groupMatches);
$this->_rawParameters = $groupMatches[1];
preg_match_all('#@param (.+)#', $this->doc, $groupMatches);
$this->rawParameters = $groupMatches[1];
return ParameterParser::create($groupMatches[1], $this->getName());
}

/**
* @return Type
*/
public function returning()
{
preg_match('#@return (.+)#', $this->_doc, $groupMatches);
preg_match('#@return (.+)#', $this->doc, $groupMatches);
$trimGroupMatches = array_map('trim', $groupMatches);
if (isset($trimGroupMatches[1])) {
$this->_rawReturn = $trimGroupMatches[1];
$this->rawReturn = $trimGroupMatches[1];
}
$parameterParser = new ParameterParser($this->_rawReturn, $this->getName());
$parameterParser = new ParameterParser($this->rawReturn, $this->getName());
return $parameterParser->parse();
}

/**
* @return string
*/
public function getDoc()
{
return $this->_doc;
return $this->doc;
}

/**
* @return string
*/
public function getName()
{
return $this->_name;
return $this->name;
}

/**
* @return array
*/
public function getRawParameters()
{
$this->parameters();
return $this->_rawParameters;
return $this->rawParameters;
}

/**
* @return string
*/
public function getRawReturn()
{
$this->returning();
return $this->_rawReturn;
return $this->rawReturn;
}
}

0 comments on commit b67fef6

Please sign in to comment.