Skip to content

Commit

Permalink
Merge pull request #29 from ProtonMail/feat/updateProtonStyle
Browse files Browse the repository at this point in the history
Feat/update proton style
  • Loading branch information
valentinbonneaud authored Nov 26, 2019
2 parents 252f00f + bc104df commit 5ffb3be
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 234 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
},
"require-dev": {
"phpunit/phpunit": "^7",
"squizlabs/php_codesniffer": "*",
"protonlabs/php-coding-standard": "^2.1"
"squizlabs/php_codesniffer": "^3.5",
"protonlabs/php-coding-standard": "^3.0"
},
"scripts": {
"phpcs": "phpcs lib",
Expand Down
21 changes: 8 additions & 13 deletions lib/SieveKeywordRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SieveKeywordRegistry
*/
public function __construct(?array $extensionsEnabled, array $customExtensions)
{
$keywords = simplexml_load_file(dirname(__FILE__) . '/keywords.xml');
$keywords = simplexml_load_file(__DIR__ . '/keywords.xml');
foreach ($keywords->children() as $keyword) {
switch ($keyword->getName()) {
case 'matchtype':
Expand Down Expand Up @@ -76,11 +76,11 @@ public function __construct(?array $extensionsEnabled, array $customExtensions)
}
}

foreach (glob(dirname(__FILE__) . '/extensions/*.xml') as $file) {
foreach (glob(__DIR__ . '/extensions/*.xml') as $file) {
$extension = simplexml_load_file($file);
$name = (string) $extension['name'];

if ($extensionsEnabled !== null && !in_array($name, $extensionsEnabled)) {
if ($extensionsEnabled !== null && !in_array($name, $extensionsEnabled, true)) {
continue;
}

Expand Down Expand Up @@ -168,8 +168,7 @@ public function activate(string $extension): void
}

$name = (string) $e['name'];
if (!isset($type[$name]) ||
(string) $e['overrides'] === 'true') {
if (!isset($type[$name]) || (string) $e['overrides'] === 'true') {
$type[$name] = $e->children();
}
}
Expand Down Expand Up @@ -198,23 +197,19 @@ public function isCommand(string $name): bool
}

/**
* Get matchtype.
*
* @param string $name
* @return mixed|null
*/
public function matchtype($name)
public function matchType($name)
{
return $this->matchTypes[$name] ?? null;
}

/**
* Get addresspart.
*
* @param string $name
* @return mixed|null
*/
public function addresspart(string $name)
public function addressPart(string $name)
{
return $this->addressParts[$name] ?? null;
}
Expand Down Expand Up @@ -263,7 +258,7 @@ public function arguments(string $command): array
$res = [];
foreach ($this->arguments as $arg) {
if (preg_match('/' . $arg['extends'] . '/', $command)) {
array_push($res, $arg['rules']);
$res[] = $arg['rules'];
}
}

Expand Down Expand Up @@ -306,7 +301,7 @@ public function matchTypes(): array
*
* @return string[]
*/
public function comparators()
public function comparators(): array
{
return array_keys($this->comparators);
}
Expand Down
24 changes: 10 additions & 14 deletions lib/SieveParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ protected function getPrevToken(int $parentId): ?SieveToken
*/

/**
* Passthrough whitespace comment.
* PassThrough whitespace comment.
*
* @param SieveToken $token
*/
public function passthroughWhitespaceComment(SieveToken $token): void
public function passThroughWhitespaceComment(SieveToken $token): void
{
if ($token->is(SieveToken::WHITESPACE)) {
$this->tree->addChild($token);
Expand Down Expand Up @@ -129,7 +129,7 @@ public function passthroughWhitespaceComment(SieveToken $token): void
*
* @param SieveToken $token
*/
public function passthroughFunction(SieveToken $token): void
public function passThroughFunction(SieveToken $token): void
{
$this->tree->addChild($token);
}
Expand All @@ -150,11 +150,7 @@ public function parse(string $script): void
$this->scanner = new SieveScanner($this->script);

// Define what happens with passthrough tokens like whitespaces and comments
$this->scanner->setPassthroughFunc(
[
$this, 'passthroughWhitespaceComment',
]
);
$this->scanner->setPassthroughFunc([$this, 'passThroughWhitespaceComment']);

$this->tree = new SieveTree('tree');
$this->commands($this->tree->getRoot());
Expand Down Expand Up @@ -194,7 +190,7 @@ protected function commands(int $parentId): void

if ($token->is(SieveToken::BLOCK_START)) {
$this->tree->addChildTo($thisNode, $token);
$this->block($thisNode, $semantics);
$this->block($thisNode);
continue;
}

Expand Down Expand Up @@ -226,14 +222,14 @@ protected function arguments(int $parentId, SieveSemantics $semantics): void
$semantics->validateToken($token);
$this->tree->addChildTo($parentId, $token);
} elseif ($this->scanner->nextTokenIs(SieveToken::STRING_LIST)) {
$this->stringlist($parentId, $semantics);
$this->stringList($parentId, $semantics);
} else {
break;
}
}

if ($this->scanner->nextTokenIs(SieveToken::TEST_LIST)) {
$this->testlist($parentId, $semantics);
$this->testList($parentId, $semantics);
}
}

Expand All @@ -244,7 +240,7 @@ protected function arguments(int $parentId, SieveSemantics $semantics): void
* @param SieveSemantics $semantics
* @throws SieveException
*/
protected function stringlist($parentId, $semantics): void
protected function stringList(int $parentId, SieveSemantics $semantics): void
{
if (!$this->scanner->nextTokenIs(SieveToken::LEFT_BRACKET)) {
$this->string($parentId, $semantics);
Expand Down Expand Up @@ -303,7 +299,7 @@ protected function string(int $parentId, SieveSemantics $semantics): void
* @param SieveSemantics $semantics
* @throws SieveException
*/
protected function testlist(int $parentId, SieveSemantics $semantics): void
protected function testList(int $parentId, SieveSemantics $semantics): void
{
if (!$this->scanner->nextTokenIs(SieveToken::LEFT_PARENTHESIS)) {
$this->test($parentId, $semantics);
Expand Down Expand Up @@ -333,7 +329,7 @@ protected function testlist(int $parentId, SieveSemantics $semantics): void
* @param SieveSemantics $semantics
* @throws SieveException
*/
protected function test($parentId, $semantics): void
protected function test(int $parentId, SieveSemantics $semantics): void
{
// Check if semantics allow an identifier
$token = $this->scanner->nextToken();
Expand Down
4 changes: 2 additions & 2 deletions lib/SieveScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function tokenize(string &$script): void
$filterMatch = array_filter(
$match,
function ($value, $key) {
return is_string($key) && isset($value) && $value !== "";
return is_string($key) && isset($value) && $value !== '';
},
ARRAY_FILTER_USE_BOTH
);
Expand Down Expand Up @@ -126,7 +126,7 @@ public function nextTokenIs(int $type): bool
* @param $type
* @return bool
*/
public function currentTokenIs($type): bool
public function currentTokenIs(int $type): bool
{
$currentToken = $this->getCurrentToken();
return isset($currentToken) ? $currentToken->is($type) : false;
Expand Down
Loading

0 comments on commit 5ffb3be

Please sign in to comment.