-
Notifications
You must be signed in to change notification settings - Fork 19
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
PHPFilter: Added support for new statement parameters extracting #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ public function enterNode(PHPParser_Node $node) { | |
} elseif ($node instanceof PHPParser_Node_Expr_FuncCall && $node->name instanceof PHPParser_Node_Name) { | ||
$parts = $node->name->parts; | ||
$name = array_pop($parts); | ||
} elseif ($node instanceof PhpParser_Node_Expr_New && isset($node->class->parts)) { | ||
$parts = $node->class->parts; | ||
$name = array_pop($parts); | ||
} else { | ||
return; | ||
} | ||
|
@@ -100,6 +103,19 @@ private function processFunction(array $definition, PHPParser_Node $node) { | |
} | ||
} | ||
|
||
/** | ||
* Includes a classs construct parameters to parse gettext phrases from | ||
* | ||
* @param $functionName string | ||
* @param $singular int | ||
* @param $plural int|null | ||
* @param $context int|null | ||
* @return self | ||
*/ | ||
public function addClassName($functionName, $singular = 1, $plural = null, $context = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is imho not needed, a comment in PHPFilter or readme should be enough |
||
parent::addFunction($functionName, $singular, $plural, $context); | ||
} | ||
|
||
/*** PHPParser_NodeVisitor: dont need these *******************************/ | ||
|
||
public function afterTraverse(array $nodes) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ protected function setUp() { | |
error_reporting(-1); | ||
$this->object = new GettextExtractor_Filters_PHPFilter(); | ||
$this->object->addFunction('addRule', 2); | ||
$this->object->addClassName('TextInput', 2); | ||
$this->file = dirname(__FILE__) . '/../../data/default.php'; | ||
} | ||
|
||
|
@@ -33,6 +34,7 @@ public function testFunctionCallWithVariables() { | |
GettextExtractor_Extractor::PLURAL => 'I see %d little indians!' | ||
), $messages); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single empty line between methods |
||
|
||
public function testNestedFunctions() { | ||
$messages = $this->object->extract($this->file); | ||
|
@@ -116,6 +118,15 @@ public function testSingularAndPluralMessageFromOneParameter() { | |
), $messages); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single empty line between methods |
||
public function testNewObjectParameter() { | ||
$messages = $this->object->extract(dirname(__FILE__) . '/../../data/newObject.php'); | ||
$this->assertContains(array( | ||
GettextExtractor_Extractor::LINE => 3, | ||
GettextExtractor_Extractor::SINGULAR => "Label" | ||
), $messages); | ||
} | ||
|
||
/** | ||
* @group bug5 | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
$obj = new $class('Label'); | ||
$obj = new Forms\Controls\TextInput($name, 'Label'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$name should be FQCN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FQCN makes thinks much more complicated (namespace, use statements). Or PhpParser solve this automaticall? I make tests durring next week..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if PhpParser solves it, never tested it.