diff --git a/composer.json b/composer.json index ddfb2b8..e7d963e 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,12 @@ } ], "require": { - "nikic/php-parser": "^1.0", + "nikic/php-parser": "^2.0", "league/climate": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^4.8", - "phpspec/prophecy-phpunit": "^1.1", - "henrikbjorn/phpspec-code-coverage": "^1.0" + "phpunit/phpunit": "^5.6", + "phpspec/prophecy": "~1.0" }, "autoload": { "psr-4": { diff --git a/src/PhpAssumptions/Analyser.php b/src/PhpAssumptions/Analyser.php index 0565cc8..8f5a85c 100644 --- a/src/PhpAssumptions/Analyser.php +++ b/src/PhpAssumptions/Analyser.php @@ -5,7 +5,7 @@ use PhpAssumptions\Output\Result; use PhpParser\Node; use PhpParser\NodeTraverserInterface; -use PhpParser\ParserAbstract; +use PhpParser\Parser\Multiple; class Analyser { @@ -35,11 +35,11 @@ class Analyser private $result; /** - * @param ParserAbstract $parser + * @param ParserAbstract $parser * @param NodeTraverserInterface $nodeTraverser */ public function __construct( - ParserAbstract $parser, + Multiple $parser, NodeTraverserInterface $nodeTraverser ) { $this->parser = $parser; diff --git a/src/PhpAssumptions/Cli.php b/src/PhpAssumptions/Cli.php index eda2800..4ba8ec4 100644 --- a/src/PhpAssumptions/Cli.php +++ b/src/PhpAssumptions/Cli.php @@ -6,9 +6,8 @@ use PhpAssumptions\Output\PrettyOutput; use PhpAssumptions\Output\XmlOutput; use PhpAssumptions\Parser\NodeVisitor; -use PhpParser\Lexer; use PhpParser\NodeTraverser; -use PhpParser\Parser; +use PhpParser\ParserFactory; class Cli { @@ -19,10 +18,17 @@ class Cli */ private $cli; + private function createParser() + { + $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); + return $parser; + } + public function __construct(CLImate $cli) { $this->cli = $cli; - $this->cli->arguments->add([ + $this->cli->arguments->add( + [ 'path' => [ 'description' => 'The path to analyse', 'required' => true, @@ -39,7 +45,9 @@ public function __construct(CLImate $cli) 'description' => 'Output file', 'defaultValue' => 'phpa.xml', ], - ]); + ] + ); + $this->parser = self::createParser(); } /** @@ -68,7 +76,7 @@ public function handle(array $args) $nodeTraverser = new NodeTraverser(); $analyser = new Analyser( - new Parser(new Lexer()), + $this->parser, $nodeTraverser ); diff --git a/src/PhpAssumptions/Detector.php b/src/PhpAssumptions/Detector.php index a3b1677..87e6e50 100644 --- a/src/PhpAssumptions/Detector.php +++ b/src/PhpAssumptions/Detector.php @@ -81,7 +81,7 @@ private function isVariableExpression(Node $node) } /** - * @param Expr $condition + * @param Expr $condition * @param string $left * @param string $right * @return bool diff --git a/src/PhpAssumptions/Output/PrettyOutput.php b/src/PhpAssumptions/Output/PrettyOutput.php index caa86d3..26f2ce4 100644 --- a/src/PhpAssumptions/Output/PrettyOutput.php +++ b/src/PhpAssumptions/Output/PrettyOutput.php @@ -28,11 +28,13 @@ public function output(Result $result) $this->cli->table($result->getAssumptions())->br(); } - $this->cli->out(sprintf( - '%d out of %d boolean expressions are assumptions (%d%%)', - $result->getAssumptionsCount(), - $result->getBoolExpressionsCount(), - $result->getPercentage() - )); + $this->cli->out( + sprintf( + '%d out of %d boolean expressions are assumptions (%d%%)', + $result->getAssumptionsCount(), + $result->getBoolExpressionsCount(), + $result->getPercentage() + ) + ); } } diff --git a/src/PhpAssumptions/Output/Result.php b/src/PhpAssumptions/Output/Result.php index 0e26039..24dad37 100644 --- a/src/PhpAssumptions/Output/Result.php +++ b/src/PhpAssumptions/Output/Result.php @@ -16,7 +16,7 @@ class Result /** * @param string $file - * @param int $line + * @param int $line * @param string $message */ public function addAssumption($file, $line, $message) diff --git a/src/PhpAssumptions/Output/XmlOutput.php b/src/PhpAssumptions/Output/XmlOutput.php index 58e758c..928aee6 100644 --- a/src/PhpAssumptions/Output/XmlOutput.php +++ b/src/PhpAssumptions/Output/XmlOutput.php @@ -29,7 +29,7 @@ class XmlOutput implements OutputInterface /** * @param CLImate $cli - * @param string $file + * @param string $file */ public function __construct(CLImate $cli, $file) { diff --git a/tests/PhpAssumptions/AnalyserTest.php b/tests/PhpAssumptions/AnalyserTest.php index 0122474..36a0e57 100644 --- a/tests/PhpAssumptions/AnalyserTest.php +++ b/tests/PhpAssumptions/AnalyserTest.php @@ -4,13 +4,12 @@ use PhpAssumptions\Analyser; use PhpAssumptions\Output\OutputInterface; +use PhpParser\Parser\Multiple; use PhpParser\Node; use PhpParser\NodeTraverser; -use PhpParser\Parser; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTestCase; -class AnalyserTest extends ProphecyTestCase +class AnalyserTest extends \PHPUnit_Framework_TestCase { /** * @var Parser @@ -40,7 +39,7 @@ class AnalyserTest extends ProphecyTestCase public function setUp() { $this->node = $this->prophesize(Node::class); - $this->parser = $this->prophesize(Parser::class); + $this->parser = $this->prophesize(Multiple::class); $this->output = $this->prophesize(OutputInterface::class); $this->nodeTraverser = $this->prophesize(NodeTraverser::class); $this->analyser = new Analyser( @@ -58,6 +57,7 @@ public function itShouldAnalyseAllFiles() $files = [fixture('MyClass.php')]; $nodes = [$this->node]; + $parseRes = $this->parser->parse(Argument::type('string')); $this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes); $this->nodeTraverser->traverse($nodes)->shouldBeCalled(); diff --git a/tests/PhpAssumptions/CliTest.php b/tests/PhpAssumptions/CliTest.php index 2622eab..a16105b 100644 --- a/tests/PhpAssumptions/CliTest.php +++ b/tests/PhpAssumptions/CliTest.php @@ -6,9 +6,8 @@ use League\CLImate\CLImate; use PhpAssumptions\Cli; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTestCase; -class CliTest extends ProphecyTestCase +class CliTest extends \PHPUnit_Framework_TestCase { /** * @var Cli diff --git a/tests/PhpAssumptions/DetectorTest.php b/tests/PhpAssumptions/DetectorTest.php index 55482a1..40e1706 100644 --- a/tests/PhpAssumptions/DetectorTest.php +++ b/tests/PhpAssumptions/DetectorTest.php @@ -3,11 +3,9 @@ namespace tests\PhpAssumptions; use PhpAssumptions\Detector; -use PhpParser\Lexer; -use PhpParser\Parser; -use Prophecy\PhpUnit\ProphecyTestCase; +use PhpParser\ParserFactory; -class NodeVisitorTest extends ProphecyTestCase +class NodeVisitorTest extends \PHPUnit_Framework_TestCase { /** * @var Parser @@ -21,7 +19,7 @@ class NodeVisitorTest extends ProphecyTestCase public function setUp() { - $this->parser = new Parser(new Lexer()); + $this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); $this->detector = new Detector(); } diff --git a/tests/PhpAssumptions/ExampleTest.php b/tests/PhpAssumptions/ExampleTest.php index 38c4804..a79c829 100644 --- a/tests/PhpAssumptions/ExampleTest.php +++ b/tests/PhpAssumptions/ExampleTest.php @@ -5,13 +5,11 @@ use PhpAssumptions\Analyser; use PhpAssumptions\Detector; use PhpAssumptions\Parser\NodeVisitor; -use PhpParser\Lexer; use PhpParser\NodeTraverser; -use PhpParser\Parser; +use PhpParser\ParserFactory; use PhpParser\PrettyPrinter\Standard; -use Prophecy\PhpUnit\ProphecyTestCase; -class ExampleTest extends ProphecyTestCase +class ExampleTest extends \PHPUnit_Framework_TestCase { /** * @var Analyser @@ -21,7 +19,7 @@ class ExampleTest extends ProphecyTestCase public function setUp() { $nodeTraverser = new NodeTraverser(); - $this->analyser = new Analyser(new Parser(new Lexer()), $nodeTraverser); + $this->analyser = new Analyser((new ParserFactory)->create(ParserFactory::PREFER_PHP7), $nodeTraverser); $nodeTraverser->addVisitor(new NodeVisitor($this->analyser, new Detector())); } diff --git a/tests/PhpAssumptions/Output/PrettyOutputTest.php b/tests/PhpAssumptions/Output/PrettyOutputTest.php index 2ef7511..3e4189f 100644 --- a/tests/PhpAssumptions/Output/PrettyOutputTest.php +++ b/tests/PhpAssumptions/Output/PrettyOutputTest.php @@ -6,9 +6,8 @@ use PhpAssumptions\Output\PrettyOutput; use PhpAssumptions\Output\Result; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTestCase; -class PrettyOutputTest extends ProphecyTestCase +class PrettyOutputTest extends \PHPUnit_Framework_TestCase { /** * @var PrettyOutput diff --git a/tests/PhpAssumptions/Output/XmlOutputTest.php b/tests/PhpAssumptions/Output/XmlOutputTest.php index 7cec459..7ba6d0c 100644 --- a/tests/PhpAssumptions/Output/XmlOutputTest.php +++ b/tests/PhpAssumptions/Output/XmlOutputTest.php @@ -5,10 +5,9 @@ use League\CLImate\CLImate; use PhpAssumptions\Cli; use PhpAssumptions\Output\Result; -use Prophecy\PhpUnit\ProphecyTestCase; use PhpAssumptions\Output\XmlOutput; -class XmlOutputTest extends ProphecyTestCase +class XmlOutputTest extends \PHPUnit_Framework_TestCase { /** * @var XmlOutput diff --git a/tests/PhpAssumptions/Parser/NodeVisitorTest.php b/tests/PhpAssumptions/Parser/NodeVisitorTest.php index edd4f37..e3a3586 100644 --- a/tests/PhpAssumptions/Parser/NodeVisitorTest.php +++ b/tests/PhpAssumptions/Parser/NodeVisitorTest.php @@ -8,9 +8,8 @@ use PhpParser\Node; use PhpParser\PrettyPrinter\Standard; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTestCase; -class NodeVisitorTest extends ProphecyTestCase +class NodeVisitorTest extends \PHPUnit_Framework_TestCase { /** * @var NodeVisitor diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 903ceed..18d703d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,6 @@