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

PHPFilter: Added support for new statement parameters extracting #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions GettextExtractor/Filters/PHPFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

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

$name should be FQCN

Copy link
Contributor Author

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..

Copy link
Owner

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.

} else {
return;
}
Expand Down Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The 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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/GettextExtractor/Filters/PHPFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -33,6 +34,7 @@ public function testFunctionCallWithVariables() {
GettextExtractor_Extractor::PLURAL => 'I see %d little indians!'
), $messages);
}

Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -116,6 +118,15 @@ public function testSingularAndPluralMessageFromOneParameter() {
), $messages);
}


Copy link
Owner

Choose a reason for hiding this comment

The 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
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/data/newObject.php
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');