Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
application/tests/_ci_phpunit_test/patcher/Patcher/AbstractPatcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Part of CI PHPUnit Test | ||
* | ||
* @author Kenji Suzuki <https://github.com/kenjis> | ||
* @license MIT License | ||
* @copyright 2015 Kenji Suzuki | ||
* @link https://github.com/kenjis/ci-phpunit-test | ||
*/ | ||
|
||
namespace Kenjis\MonkeyPatch\Patcher; | ||
|
||
use PhpParser\Parser; | ||
use PhpParser\Lexer; | ||
use PhpParser\NodeTraverser; | ||
|
||
abstract class AbstractPatcher | ||
{ | ||
protected $node_visitor; | ||
|
||
public static $replacement; | ||
|
||
public function patch($source) | ||
{ | ||
$patched = false; | ||
static::$replacement = []; | ||
|
||
$parser = new Parser(new Lexer( | ||
['usedAttributes' => ['startTokenPos', 'endTokenPos']] | ||
)); | ||
$traverser = new NodeTraverser; | ||
$traverser->addVisitor($this->node_visitor); | ||
|
||
$ast_orig = $parser->parse($source); | ||
$traverser->traverse($ast_orig); | ||
|
||
if (static::$replacement !== []) | ||
{ | ||
$patched = true; | ||
$new_source = static::generateNewSource($source); | ||
} | ||
else | ||
{ | ||
$new_source = $source; | ||
} | ||
|
||
return [ | ||
$new_source, | ||
$patched, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters