Skip to content

Commit

Permalink
Improve exception message of ExtractionException
Browse files Browse the repository at this point in the history
  • Loading branch information
pierallard committed Jun 20, 2017
1 parent b28567f commit 392d04f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ interface NodeParserInterface
/**
* @param \SplFileInfo $file
*
* @return NodeInterface
* @return Node
*
* @throws ExtractionException
* @throws ParsingException
*/
public function parse(\SplFileInfo $file);
}
14 changes: 14 additions & 0 deletions src/Akeneo/CouplingDetector/NodeParser/ParsingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Akeneo\CouplingDetector\NodeParser;

/**
* Class ParsingException.
*
* @author Pierre Allard <pierre.allard@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
* @license http://opensource.org/licenses/MIT MIT
*/
class ParsingException extends \LogicException
{
}
15 changes: 13 additions & 2 deletions src/Akeneo/CouplingDetector/NodeParser/PhpClassNodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
class PhpClassNodeParser implements NodeParserInterface
{
/**
* {@inheritdoc}
*/
public function parse(\SplFileInfo $file)
{
$namespaceExtractor = new NamespaceExtractor();
Expand All @@ -28,8 +31,16 @@ public function parse(\SplFileInfo $file)

$content = file_get_contents($file->getRealPath());
$tokens = Tokens::fromCode($content);
$classNamespace = $namespaceExtractor->extract($tokens);
$className = $classNameExtractor->extract($tokens);
try {
$classNamespace = $namespaceExtractor->extract($tokens, $file);
$className = $classNameExtractor->extract($tokens, $file);
} catch (ExtractionException $e) {
throw new ParsingException(sprintf(
"Parsing exception on \"%s\":\n%s",
$file->getPathname(),
$e->getMessage()
));
}
$classFullName = sprintf('%s\%s', $classNamespace, $className);
$useDeclarations = $useDeclarationExtractor->extract($tokens);

Expand Down

0 comments on commit 392d04f

Please sign in to comment.