Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php7 compatibility update #16

Merged
merged 6 commits into from Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions composer.json
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/PhpAssumptions/Analyser.php
Expand Up @@ -5,7 +5,7 @@
use PhpAssumptions\Output\Result;
use PhpParser\Node;
use PhpParser\NodeTraverserInterface;
use PhpParser\ParserAbstract;
use PhpParser\Parser\Multiple;

class Analyser
{
Expand Down Expand Up @@ -35,11 +35,11 @@ class Analyser
private $result;

/**
* @param ParserAbstract $parser
* @param ParserAbstract $parser
* @param NodeTraverserInterface $nodeTraverser
*/
public function __construct(
ParserAbstract $parser,
Multiple $parser,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should hint against the Parser interface, instead of Multiple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's quite right. From what I'm seeing Cli.php creates the class being passed into this construct here:

    private function createParser()
    {
        $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
        return $parser;
    }

Since this results in the creation of an instance of: PhpParser\Parser\Multiple I'm type hinting for that class.

NodeTraverserInterface $nodeTraverser
) {
$this->parser = $parser;
Expand Down
18 changes: 13 additions & 5 deletions src/PhpAssumptions/Cli.php
Expand Up @@ -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
{
Expand All @@ -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,
Expand All @@ -39,7 +45,9 @@ public function __construct(CLImate $cli)
'description' => 'Output file',
'defaultValue' => 'phpa.xml',
],
]);
]
);
$this->parser = self::createParser();
}

/**
Expand Down Expand Up @@ -68,7 +76,7 @@ public function handle(array $args)
$nodeTraverser = new NodeTraverser();

$analyser = new Analyser(
new Parser(new Lexer()),
$this->parser,
$nodeTraverser
);

Expand Down
2 changes: 1 addition & 1 deletion src/PhpAssumptions/Detector.php
Expand Up @@ -81,7 +81,7 @@ private function isVariableExpression(Node $node)
}

/**
* @param Expr $condition
* @param Expr $condition
* @param string $left
* @param string $right
* @return bool
Expand Down
14 changes: 8 additions & 6 deletions src/PhpAssumptions/Output/PrettyOutput.php
Expand Up @@ -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()
)
);
}
}
2 changes: 1 addition & 1 deletion src/PhpAssumptions/Output/Result.php
Expand Up @@ -16,7 +16,7 @@ class Result

/**
* @param string $file
* @param int $line
* @param int $line
* @param string $message
*/
public function addAssumption($file, $line, $message)
Expand Down
2 changes: 1 addition & 1 deletion src/PhpAssumptions/Output/XmlOutput.php
Expand Up @@ -29,7 +29,7 @@ class XmlOutput implements OutputInterface

/**
* @param CLImate $cli
* @param string $file
* @param string $file
*/
public function __construct(CLImate $cli, $file)
{
Expand Down
12 changes: 6 additions & 6 deletions tests/PhpAssumptions/AnalyserTest.php
Expand Up @@ -6,11 +6,10 @@
use PhpAssumptions\Output\OutputInterface;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTestCase;

class AnalyserTest extends ProphecyTestCase
class AnalyserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Parser
Expand Down Expand Up @@ -40,11 +39,11 @@ class AnalyserTest extends ProphecyTestCase
public function setUp()
{
$this->node = $this->prophesize(Node::class);
$this->parser = $this->prophesize(Parser::class);
$this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$this->output = $this->prophesize(OutputInterface::class);
$this->nodeTraverser = $this->prophesize(NodeTraverser::class);
$this->analyser = new Analyser(
$this->parser->reveal(),
$this->parser,
$this->nodeTraverser->reveal(),
$this->output->reveal()
);
Expand All @@ -58,7 +57,8 @@ public function itShouldAnalyseAllFiles()
$files = [fixture('MyClass.php')];
$nodes = [$this->node];

$this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes);
$parseRes = $this->parser->parse(Argument::type('string'));
//$this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes);

$this->nodeTraverser->traverse($nodes)->shouldBeCalled();

Expand Down
3 changes: 1 addition & 2 deletions tests/PhpAssumptions/CliTest.php
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/PhpAssumptions/DetectorTest.php
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
8 changes: 3 additions & 5 deletions tests/PhpAssumptions/ExampleTest.php
Expand Up @@ -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
Expand All @@ -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()));
}

Expand Down
3 changes: 1 addition & 2 deletions tests/PhpAssumptions/Output/PrettyOutputTest.php
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/PhpAssumptions/Output/XmlOutputTest.php
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/PhpAssumptions/Parser/NodeVisitorTest.php
Expand Up @@ -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
Expand Down