From a35e92b518a0d11785010e303968e87dcdd74412 Mon Sep 17 00:00:00 2001 From: Thomas Hareau Date: Tue, 26 Nov 2019 19:40:05 +0100 Subject: [PATCH 1/3] Update protonlabs/php-coding-standard and fix style --- composer.json | 2 +- lib/SieveKeywordRegistry.php | 2 +- lib/SieveParser.php | 2 +- lib/SieveScanner.php | 2 +- lib/SieveSemantics.php | 299 +++++++++++++++-------------------- lib/SieveTree.php | 8 +- 6 files changed, 138 insertions(+), 177 deletions(-) diff --git a/composer.json b/composer.json index 92f6e4d..cd4b538 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ }, "require-dev": { "phpunit/phpunit": "^7", - "squizlabs/php_codesniffer": "*", + "squizlabs/php_codesniffer": "^3.5", "protonlabs/php-coding-standard": "^2.1" }, "scripts": { diff --git a/lib/SieveKeywordRegistry.php b/lib/SieveKeywordRegistry.php index 39dd69a..cd1d814 100644 --- a/lib/SieveKeywordRegistry.php +++ b/lib/SieveKeywordRegistry.php @@ -263,7 +263,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']; } } diff --git a/lib/SieveParser.php b/lib/SieveParser.php index 5d2696f..846e1ed 100644 --- a/lib/SieveParser.php +++ b/lib/SieveParser.php @@ -194,7 +194,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; } diff --git a/lib/SieveScanner.php b/lib/SieveScanner.php index 1b00730..edb849e 100644 --- a/lib/SieveScanner.php +++ b/lib/SieveScanner.php @@ -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 ); diff --git a/lib/SieveSemantics.php b/lib/SieveSemantics.php index b9667ab..b627d77 100644 --- a/lib/SieveSemantics.php +++ b/lib/SieveSemantics.php @@ -47,7 +47,7 @@ public function __construct(SieveKeywordRegistry $registry, SieveToken $token, ? // Check if command may appear at this position within the script if ($this->registry->isTest($command)) { - if (is_null($prevToken)) { + if ($prevToken === null) { throw new SieveException($token, $command . ' may not appear as first command'); } if (!preg_match('/^(if|elsif|anyof|allof|not)$/i', $prevToken->text)) { @@ -77,20 +77,18 @@ public function __construct(SieveKeywordRegistry $registry, SieveToken $token, ? // Check for extension arguments to add to the command foreach ($this->registry->arguments($command) as $arg) { - switch ((string) $arg['type']) { - case 'tag': - array_unshift( - $this->arguments, - [ - 'type' => SieveToken::TAG, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->regex($arg), - 'call' => 'tagHook', - 'name' => $this->name($arg), - 'subArgs' => $this->makeArguments($arg->children()), - ] - ); - break; + if ((string) $arg['type'] === 'tag') { + array_unshift( + $this->arguments, + [ + 'type' => SieveToken::TAG, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->regex($arg), + 'call' => 'tagHook', + 'name' => $this->name($arg), + 'subArgs' => $this->makeArguments($arg->children()), + ] + ); } } } @@ -259,173 +257,137 @@ protected function makeArguments($parameters): array switch ((string) $arg['type']) { case 'addresspart': - array_push( - $arguments, - [ - 'type' => SieveToken::TAG, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->addressPartRegex(), - 'call' => 'addressPartHook', - 'name' => 'address part', - 'subArgs' => $this->makeArguments($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::TAG, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->addressPartRegex(), + 'call' => 'addressPartHook', + 'name' => 'address part', + 'subArgs' => $this->makeArguments($arg), + ]; break; case 'block': - array_push( - $arguments, - [ - 'type' => SieveToken::BLOCK_START, - 'occurrence' => '1', - 'regex' => '{', - 'name' => 'block', - 'subArgs' => $this->makeArguments($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::BLOCK_START, + 'occurrence' => '1', + 'regex' => '{', + 'name' => 'block', + 'subArgs' => $this->makeArguments($arg), + ]; break; case 'comparator': - array_push( - $arguments, - [ - 'type' => SieveToken::TAG, - 'occurrence' => $this->occurrence($arg), - 'regex' => 'comparator', - 'name' => 'comparator', - 'subArgs' => [ - [ - 'type' => SieveToken::STRING, - 'occurrence' => '1', - 'call' => 'comparatorHook', - 'case' => 'adhere', - 'regex' => $this->comparatorRegex(), - 'name' => 'comparator string', - 'follows' => 'comparator', - ] + $arguments[] = [ + 'type' => SieveToken::TAG, + 'occurrence' => $this->occurrence($arg), + 'regex' => 'comparator', + 'name' => 'comparator', + 'subArgs' => [ + [ + 'type' => SieveToken::STRING, + 'occurrence' => '1', + 'call' => 'comparatorHook', + 'case' => 'adhere', + 'regex' => $this->comparatorRegex(), + 'name' => 'comparator string', + 'follows' => 'comparator', ], - ] - ); + ], + ]; break; case 'matchtype': - array_push( - $arguments, - [ - 'type' => SieveToken::TAG, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->matchTypeRegex(), - 'call' => 'matchTypeHook', - 'name' => 'match type', - 'subArgs' => $this->makeArguments($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::TAG, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->matchTypeRegex(), + 'call' => 'matchTypeHook', + 'name' => 'match type', + 'subArgs' => $this->makeArguments($arg), + ]; break; case 'number': - array_push( - $arguments, - [ - 'type' => SieveToken::NUMBER, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->regex($arg), - 'name' => $this->name($arg), - 'follows' => $this->follows($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::NUMBER, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->regex($arg), + 'name' => $this->name($arg), + 'follows' => $this->follows($arg), + ]; break; case 'requirestrings': - array_push( - $arguments, - [ - 'type' => SieveToken::STRING_LIST, - 'occurrence' => $this->occurrence($arg), - 'call' => 'setRequire', - 'case' => 'adhere', - 'regex' => $this->requireStringsRegex(), - 'name' => $this->name($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::STRING_LIST, + 'occurrence' => $this->occurrence($arg), + 'call' => 'setRequire', + 'case' => 'adhere', + 'regex' => $this->requireStringsRegex(), + 'name' => $this->name($arg), + ]; break; case 'string': - array_push( - $arguments, - [ - 'type' => SieveToken::STRING, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->regex($arg), - 'case' => $this->getCase($arg), - 'name' => $this->name($arg), - 'follows' => $this->follows($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::STRING, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->regex($arg), + 'case' => $this->getCase($arg), + 'name' => $this->name($arg), + 'follows' => $this->follows($arg), + ]; break; case 'stringlist': - array_push( - $arguments, - [ - 'type' => SieveToken::STRING_LIST, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->regex($arg), - 'case' => $this->getCase($arg), - 'name' => $this->name($arg), - 'follows' => $this->follows($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::STRING_LIST, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->regex($arg), + 'case' => $this->getCase($arg), + 'name' => $this->name($arg), + 'follows' => $this->follows($arg), + ]; break; case 'tag': - array_push( - $arguments, - [ - 'type' => SieveToken::TAG, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->regex($arg), - 'call' => 'tagHook', - 'name' => $this->name($arg), - 'subArgs' => $this->makeArguments($arg->children()), - 'follows' => $this->follows($arg), - ] - ); + $arguments[] = [ + 'type' => SieveToken::TAG, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->regex($arg), + 'call' => 'tagHook', + 'name' => $this->name($arg), + 'subArgs' => $this->makeArguments($arg->children()), + 'follows' => $this->follows($arg), + ]; break; case 'test': - array_push( - $arguments, - [ - 'type' => SieveToken::IDENTIFIER, - 'occurrence' => $this->occurrence($arg), - 'regex' => $this->testsRegex(), - 'name' => $this->name($arg), - 'subArgs' => $this->makeArguments($arg->children()), - ] - ); + $arguments[] = [ + 'type' => SieveToken::IDENTIFIER, + 'occurrence' => $this->occurrence($arg), + 'regex' => $this->testsRegex(), + 'name' => $this->name($arg), + 'subArgs' => $this->makeArguments($arg->children()), + ]; break; case 'testlist': - array_push( - $arguments, - [ - 'type' => SieveToken::LEFT_PARENTHESIS, - 'occurrence' => '1', - 'regex' => '\(', - 'name' => $this->name($arg), - 'subArgs' => null, - ] - ); - array_push( - $arguments, - [ - 'type' => SieveToken::IDENTIFIER, - 'occurrence' => '+', - 'regex' => $this->testsRegex(), - 'name' => $this->name($arg), - 'subArgs' => $this->makeArguments($arg->children()), - ] - ); + $arguments[] = [ + 'type' => SieveToken::LEFT_PARENTHESIS, + 'occurrence' => '1', + 'regex' => '\(', + 'name' => $this->name($arg), + 'subArgs' => null, + ]; + $arguments[] = [ + 'type' => SieveToken::IDENTIFIER, + 'occurrence' => '+', + 'regex' => $this->testsRegex(), + 'name' => $this->name($arg), + 'subArgs' => $this->makeArguments($arg->children()), + ]; break; } } @@ -460,16 +422,13 @@ protected function addArguments(string $identifier, array $subArgs): void protected function addDependency(string $type, string $name, \SimpleXMLElement $dependencies): void { foreach ($dependencies as $d) { - array_push( - $this->deps, - [ - 'o_type' => $type, - 'o_name' => $name, - 'type' => $d['type'], - 'name' => $d['name'], - 'regex' => $d['regex'], - ] - ); + $this->deps[] = [ + 'o_type' => $type, + 'o_name' => $name, + 'type' => $d['type'], + 'name' => $d['name'], + 'regex' => $d['regex'], + ]; } } @@ -502,12 +461,14 @@ protected function invoke(SieveToken $token, $func, $arg = []) */ protected function setRequire(string $extension) { - array_push(self::$requiredExtensions, $extension); + self::$requiredExtensions[] = $extension; try { $this->registry->activate($extension); } catch (\Throwable $throwable) { return $throwable->getMessage(); } + + return null; } /** @@ -525,7 +486,7 @@ protected function addressPartHook(string $addresspart): void $xml = $this->registry->addresspart($this->addressPart); if (isset($xml)) { - // Add possible value and dependancy + // Add possible value and dependency $this->addArguments($this->addressPart, $this->makeArguments($xml)); $this->addDependency('address part', $this->addressPart, $xml->requires); } @@ -546,7 +507,7 @@ protected function matchTypeHook(string $matchtype): void $xml = $this->registry->matchtype($this->matchType); if (isset($xml)) { - // Add possible value and dependancy + // Add possible value and dependency $this->addArguments($this->matchType, $this->makeArguments($xml)); $this->addDependency('match type', $this->matchType, $xml->requires); } @@ -556,7 +517,7 @@ protected function matchTypeHook(string $matchtype): void * Called after a comparator was found in a command. * * The comparator is remembered in case it's needed for - * comparsion later {@see done}. For a comparator from extensions + * comparison later {@see done}. For a comparator from extensions * dependency information is looked up as well. * * @param string $comparator @@ -567,7 +528,7 @@ protected function comparatorHook(string $comparator): void $xml = $this->registry->comparator($this->comparator); if (isset($xml)) { - // Add possible dependancy + // Add possible dependency $this->addDependency('comparator', $this->comparator, $xml->requires); } } @@ -576,17 +537,17 @@ protected function comparatorHook(string $comparator): void * Called after a tag was found in a command. * * The tag is remembered in case it's needed for - * comparsion later {@see done}. For a tags from extensions + * comparison later {@see done}. For a tags from extensions * dependency information is looked up as well. * * @param string $tag */ protected function tagHook(string $tag): void { - array_push($this->tags, $tag); + $this->tags[] = $tag; $xml = $this->registry->argument($tag); - // Add possible dependancies + // Add possible dependencies if (isset($xml)) { $this->addDependency('tag', $tag, $xml->requires); } diff --git a/lib/SieveTree.php b/lib/SieveTree.php index a49676d..5c9fe59 100644 --- a/lib/SieveTree.php +++ b/lib/SieveTree.php @@ -58,7 +58,7 @@ public function addChildTo(int $parentId, SieveToken $child): ?int $childId = ++$this->maxId; $this->nodes[$childId] = $child; $this->parents[$childId] = $parentId; - array_push($this->children[$parentId], $childId); + $this->children[$parentId][] = $childId; return $childId; } @@ -178,10 +178,10 @@ protected function childrenText($parentId): string $children = $this->children[$parentId] ?? []; $dump = ''; - for ($i = 0; $i < count($children); ++$i) { - $childNode = $this->nodes[$children[$i]]; + foreach ($children as $iValue) { + $childNode = $this->nodes[$iValue]; $dump .= $childNode->text(); - $dump .= $this->childrenText($children[$i]); + $dump .= $this->childrenText($iValue); } return $dump; } From 61b3e9514dfda3835b0e5f23ff92d7931f51ef42 Mon Sep 17 00:00:00 2001 From: Thomas Hareau Date: Tue, 26 Nov 2019 20:29:53 +0100 Subject: [PATCH 2/3] Using last coding standard --- composer.json | 2 +- lib/SieveKeywordRegistry.php | 19 +++++++------------ lib/SieveParser.php | 22 +++++++++------------- lib/SieveScanner.php | 2 +- lib/SieveSemantics.php | 24 ++++++++++++------------ lib/SieveToken.php | 2 +- lib/SieveTree.php | 2 +- tests/SieveKeywordRegistryTest.php | 16 ++++++++-------- tests/SieveParserTest.php | 10 ++++------ tests/bootstrap.php | 2 ++ 10 files changed, 46 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index cd4b538..2f6a4fb 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "require-dev": { "phpunit/phpunit": "^7", "squizlabs/php_codesniffer": "^3.5", - "protonlabs/php-coding-standard": "^2.1" + "protonlabs/php-coding-standard": "^3.0" }, "scripts": { "phpcs": "phpcs lib", diff --git a/lib/SieveKeywordRegistry.php b/lib/SieveKeywordRegistry.php index cd1d814..b00e704 100644 --- a/lib/SieveKeywordRegistry.php +++ b/lib/SieveKeywordRegistry.php @@ -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': @@ -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; } @@ -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(); } } @@ -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; } @@ -306,7 +301,7 @@ public function matchTypes(): array * * @return string[] */ - public function comparators() + public function comparators(): array { return array_keys($this->comparators); } diff --git a/lib/SieveParser.php b/lib/SieveParser.php index 846e1ed..d206a5c 100644 --- a/lib/SieveParser.php +++ b/lib/SieveParser.php @@ -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); @@ -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); } @@ -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()); @@ -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); } } @@ -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); @@ -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); @@ -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(); diff --git a/lib/SieveScanner.php b/lib/SieveScanner.php index edb849e..20fc49d 100644 --- a/lib/SieveScanner.php +++ b/lib/SieveScanner.php @@ -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; diff --git a/lib/SieveSemantics.php b/lib/SieveSemantics.php index b627d77..265e1a0 100644 --- a/lib/SieveSemantics.php +++ b/lib/SieveSemantics.php @@ -218,7 +218,7 @@ protected function getCase(\SimpleXMLElement $arg): string */ protected function follows(\SimpleXMLElement $arg): string { - return (string) ( $arg['follows'] ?? '.*'); + return (string) ($arg['follows'] ?? '.*'); } /** @@ -412,7 +412,7 @@ protected function addArguments(string $identifier, array $subArgs): void } /** - * Add dependency that is expected to be fullfilled when parsing + * Add dependency that is expected to be fulfilled when parsing * of the current command is {@see done}. * * @param string $type @@ -440,7 +440,7 @@ protected function addDependency(string $type, string $name, \SimpleXMLElement $ * @param string[]|string|null $arg * @throws SieveException */ - protected function invoke(SieveToken $token, $func, $arg = []) + protected function invoke(SieveToken $token, $func, $arg = []): void { if (!is_array($arg)) { $arg = [$arg]; @@ -459,7 +459,7 @@ protected function invoke(SieveToken $token, $func, $arg = []) * @param string $extension the extension name * @return string|null an error message */ - protected function setRequire(string $extension) + protected function setRequire(string $extension): ?string { self::$requiredExtensions[] = $extension; try { @@ -478,12 +478,12 @@ protected function setRequire(string $extension) * needed later {@see done}. For address parts from a extension * dependency information and valid values are looked up as well. * - * @param string $addresspart + * @param string $addressPart */ - protected function addressPartHook(string $addresspart): void + protected function addressPartHook(string $addressPart): void { - $this->addressPart = $addresspart; - $xml = $this->registry->addresspart($this->addressPart); + $this->addressPart = $addressPart; + $xml = $this->registry->addressPart($this->addressPart); if (isset($xml)) { // Add possible value and dependency @@ -499,12 +499,12 @@ protected function addressPartHook(string $addresspart): void * needed later {@see done}. For a match type from extensions * dependency information and valid values are looked up as well. * - * @param string $matchtype + * @param string $matchType */ - protected function matchTypeHook(string $matchtype): void + protected function matchTypeHook(string $matchType): void { - $this->matchType = $matchtype; - $xml = $this->registry->matchtype($this->matchType); + $this->matchType = $matchType; + $xml = $this->registry->matchType($this->matchType); if (isset($xml)) { // Add possible value and dependency diff --git a/lib/SieveToken.php b/lib/SieveToken.php index c2e1153..0db29f7 100644 --- a/lib/SieveToken.php +++ b/lib/SieveToken.php @@ -78,7 +78,7 @@ public function __construct(int $type, string $text, int $line) */ public function dump(): string { - return '<' . SieveToken::escape($this->text) . '> type:' . SieveToken::typeString( + return '<' . static::escape($this->text) . '> type:' . static::typeString( $this->type ) . ' line:' . $this->line; } diff --git a/lib/SieveTree.php b/lib/SieveTree.php index 5c9fe59..b5f93c4 100644 --- a/lib/SieveTree.php +++ b/lib/SieveTree.php @@ -16,7 +16,7 @@ class SieveTree * * @param string $name */ - public function __construct($name = 'tree') + public function __construct(string $name = 'tree') { $this->children = []; $this->parents = []; diff --git a/tests/SieveKeywordRegistryTest.php b/tests/SieveKeywordRegistryTest.php index 8b3ea4a..6925d28 100644 --- a/tests/SieveKeywordRegistryTest.php +++ b/tests/SieveKeywordRegistryTest.php @@ -76,7 +76,7 @@ public function testRequiresExtensionFailsIfNotLoaded() * Checks the behavior when several extensions are required. * * @param string $sieveExtensions - * @param null|string $exception + * @param string|null $exception * @throws \Sieve\SieveException * @dataProvider mixExtensionProvider */ @@ -90,7 +90,7 @@ public function testMixExtension(string $sieveExtensions, ?string $exception = n EOS; if (isset($exception)) { - static::expectException($exception); + static::expectException($exception); } $parser->parse($sieve); @@ -106,23 +106,23 @@ public function mixExtensionProvider() { return [ "correct" => [ - '"relational", "mixed"' + '"relational", "mixed"', ], "correct inversed" => [ - '"mixed", "relational"' + '"mixed", "relational"', ], "missing required" => [ '"mixed"', - \Sieve\SieveException::class + \Sieve\SieveException::class, ], "one forbidden extension" => [ '"mixed", "spamtest"', - \Sieve\SieveException::class + \Sieve\SieveException::class, ], "several forbidden extensions" => [ '"vacation", "mixed", "spamtest"', - \Sieve\SieveException::class - ] + \Sieve\SieveException::class, + ], ]; } diff --git a/tests/SieveParserTest.php b/tests/SieveParserTest.php index d56c8f1..b479373 100644 --- a/tests/SieveParserTest.php +++ b/tests/SieveParserTest.php @@ -38,7 +38,7 @@ public function testWhiteSpacesArePreserved() $parser = new SieveParser(); $parser->parse($sieve); - static::assertEquals($sieve, $parser->getParseTree()->getText()); + self::assertEquals($sieve, $parser->getParseTree()->getText()); } /** @@ -51,7 +51,7 @@ public function testGood(string $sieve) $parser = new SieveParser(); $parser->parse($sieve); // it should not raise an exception - static::assertEquals($sieve, $parser->getScriptText()); + self::assertEquals($sieve, $parser->getScriptText()); } /** @@ -180,7 +180,7 @@ public function dataDumpProvider() yield ['if header :is "To" ["a@b.c"] {}', $dumpExpected1]; yield [ 'require ["virustest", "comparator-i;ascii-numeric"];', - $dumpExpected2 + $dumpExpected2, ]; yield [ '# C @@ -189,9 +189,7 @@ public function dataDumpProvider() t . {}', - $dumpExpected3 + $dumpExpected3, ]; } } - - diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5f370b2..85d33d6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,7 @@ Date: Tue, 26 Nov 2019 20:47:54 +0100 Subject: [PATCH 3/3] fix tests --- tests/bootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 85d33d6..9ac1f4c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,6 +3,6 @@ declare(strict_types=1); // Settings to make all errors more obvious during testing -ini_set('display_errors', 1); -ini_set('display_startup_errors', 1); +ini_set('display_errors', (string) 1); +ini_set('display_startup_errors', (string) 1); date_default_timezone_set('UTC');