Skip to content

Commit 72a4c98

Browse files
committed
code style
1 parent eaf40a8 commit 72a4c98

7 files changed

+22
-48
lines changed

.php_cs.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return My\PhpCsFixerConfig::create()
4+
->setFinder(
5+
PhpCsFixer\Finder::create()
6+
->files()
7+
->name('*.php')
8+
->in(__DIR__.'/src')
9+
->in(__DIR__.'/tests')
10+
->exclude('assets')
11+
);

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "^8.0",
27-
"squizlabs/php_codesniffer": "^3.0"
27+
"squizlabs/php_codesniffer": "^3.0",
28+
"oscarotero/php-cs-fixer-config": "^1.0",
29+
"friendsofphp/php-cs-fixer": "^2.15"
2830
},
2931
"autoload": {
3032
"psr-4": {
@@ -41,6 +43,6 @@
4143
"phpunit",
4244
"phpcs"
4345
],
44-
"codefix": "phpcbf"
46+
"cs-fix": "php-cs-fixer fix"
4547
}
4648
}

src/PhpFunctionsScanner.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
namespace Gettext\Scanner;
55

6+
use PhpParser\NodeTraverser;
67
use PhpParser\Parser;
78
use PhpParser\ParserFactory;
8-
use PhpParser\NodeTraverser;
9-
use PhpParser\NodeDumper;
109

1110
class PhpFunctionsScanner implements FunctionsScannerInterface
1211
{
@@ -16,7 +15,7 @@ class PhpFunctionsScanner implements FunctionsScannerInterface
1615
public function __construct(array $validFunctions = null, Parser $parser = null)
1716
{
1817
$this->validFunctions = $validFunctions;
19-
$this->parser = $parser ?: (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
18+
$this->parser = $parser ?: (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
2019
}
2120

2221
public function scan(string $code, string $filename = null): array

src/PhpNodeVisitor.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
namespace Gettext\Scanner;
55

6-
use PhpParser\NodeVisitor;
6+
use PhpParser\Comment;
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\FuncCall;
9-
use PhpParser\Node\Stmt\Nop;
10-
use PhpParser\Comment;
9+
use PhpParser\NodeVisitor;
1110

1211
class PhpNodeVisitor implements NodeVisitor
1312
{
@@ -30,7 +29,7 @@ public function enterNode(Node $node)
3029
{
3130
if ($node instanceof FuncCall) {
3231
$name = $node->name->getLast();
33-
32+
3433
if ($this->validFunctions === null || in_array($name, $this->validFunctions)) {
3534
$this->functions[] = $this->createFunction($node);
3635
}
@@ -66,7 +65,7 @@ protected function createFunction(FuncCall $node): ParsedFunction
6665
$node->getEndLine()
6766
);
6867

69-
foreach($node->getComments() as $comment) {
68+
foreach ($node->getComments() as $comment) {
7069
$function->addComment(static::getComment($comment));
7170
}
7271

@@ -83,7 +82,6 @@ protected function createFunction(FuncCall $node): ParsedFunction
8382
case 'Scalar_DNumber':
8483
$function->addArgument($value->value);
8584
break;
86-
8785
default:
8886
$function->addArgument();
8987
}

src/PhpScanner.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33

44
namespace Gettext\Scanner;
55

6-
use Exception;
76
use Gettext\Translations;
8-
use Gettext\Translation;
9-
use Gettext\Scanner\ParsedFunction;
10-
use Gettext\Scanner\PhpFunctionsScanner;
11-
use Gettext\Scanner\FunctionsScannerInterface;
127

138
/**
149
* Class to scan PHP files and get gettext translations

tests/PhpFunctionsScannerTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public function testPhpFunctionsExtractor()
102102
$this->assertSame('fn_8();', array_shift($comments));
103103
$this->assertSame('ALLOW: This is a comment to fn9', array_shift($comments));
104104

105-
106105
//fn10
107106
$function = array_shift($functions);
108107
$this->assertSame('fn10', $function->getName());
@@ -180,34 +179,4 @@ public function _testPhpFunctionsScannerWithPrefixedComments()
180179
$this->assertSame(23, $comment->getLastLine());
181180
$this->assertSame('ALLOW: Related comment 3', $comment->getComment());
182181
}
183-
184-
public function stringDecodeProvider()
185-
{
186-
return [
187-
['"test"', 'test'],
188-
["'test'", 'test'],
189-
["'DATE \a\\t TIME'", 'DATE \a\t TIME'],
190-
["'DATE \a\\t TIME$'", 'DATE \a\t TIME$'],
191-
["'DATE \a\\t TIME\$'", 'DATE \a\t TIME$'],
192-
["'DATE \a\\t TIME\$a'", 'DATE \a\t TIME$a'],
193-
['"FIELD\\tFIELD"', "FIELD\tFIELD"],
194-
['"$"', '$'],
195-
['"Hi $"', 'Hi $'],
196-
['"$ hi"', '$ hi'],
197-
['"Hi\t$name"', "Hi\t\$name"],
198-
['"Hi\\\\"', 'Hi\\'],
199-
['"{$obj->name}"', '{$obj->name}'],
200-
['"a\x20b $c"', 'a b $c'],
201-
['"a\x01b\2 \1 \01 \001 \r \n \t \v \f"', "a\1b\2 \1 \1 \1 \r \n \t \v \f"],
202-
['"$ \$a \""', '$ $a "'],
203-
];
204-
}
205-
206-
/**
207-
* @dataProvider stringDecodeProvider
208-
*/
209-
public function _testStringDecode($source, $decoded)
210-
{
211-
$this->assertSame($decoded, PhpFunctionsScanner::decode($source));
212-
}
213182
}

tests/PhpScannerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public function testPhpCodeScanner()
3535
$this->assertCount(4, $domain2);
3636
$this->assertCount(1, $domain3);
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)