Skip to content

Commit

Permalink
Cleanup and use php 8+
Browse files Browse the repository at this point in the history
  • Loading branch information
tadas committed Apr 27, 2022
1 parent b8955b4 commit 63ab06d
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 366 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
language: php

php:
- 7.1
- 7.2
- 7.3
# - nightly
- 8.0
- 8.1

before_script:
- travis_retry composer selfupdate
- travis_retry composer i --no-interaction --prefer-source

script:
- vendor/bin/psalm
- vendor/bin/phpunit --coverage-clover=coverage.xml

after_success:
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
],
"require": {
"php": ">=7.1.0",
"php": ">=8.0",
"ext-mbstring": "*",
"ext-simplexml": "*"
},
Expand All @@ -40,9 +40,10 @@
}
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.5",
"protonlabs/php-coding-standard": "^3.0"
"protonlabs/php-coding-standard": "^4.0",
"vimeo/psalm": "^4.22"
},
"scripts": {
"phpcs": "phpcs lib",
Expand Down
4 changes: 2 additions & 2 deletions lib/SieveDumpable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

interface SieveDumpable
{
public function dump();
public function text();
public function dump(): string;
public function text(): string;
}
8 changes: 2 additions & 6 deletions lib/SieveException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

class SieveException extends Exception
{
protected $token;

/**
* SieveException constructor.
*
* @param SieveToken $token
* @param $arg
*/
public function __construct(SieveToken $token, $arg)
public function __construct(protected SieveToken $token, $arg)
{
$this->token = $token;

if (is_string($arg)) {
$message = $arg;
} else {
Expand All @@ -39,7 +35,7 @@ public function __construct(SieveToken $token, $arg)
parent::__construct("line $token->line: $message");
}

public function getLineNo()
public function getLineNo(): int
{
return $this->token->line;
}
Expand Down
65 changes: 16 additions & 49 deletions lib/SieveKeywordRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

namespace Sieve;

use SimpleXMLElement;

class SieveKeywordRegistry
{
protected $registry = [];
protected $matchTypes = [];
protected $comparators = [];
protected $addressParts = [];
protected $commands = [];
protected $tests = [];
protected $arguments = [];
protected array $registry = [];
protected array $matchTypes = [];
protected array $comparators = [];
protected array $addressParts = [];
protected array $commands = [];
protected array $tests = [];
protected array $arguments = [];

/**
* @var array a map with the extension name as key.
*
* The value does not matter, to remove an extension, unset the key.
*/
protected $loadedExtensions = [];
protected array $loadedExtensions = [];

/**
* @var array a map defining which extensions are forbidden.
Expand All @@ -28,20 +30,17 @@ class SieveKeywordRegistry
* containing all the extensions that forbids the current extension
* usage.
*/
protected $forbiddenExtensions = [];
protected array $forbiddenExtensions = [];

/**
* @var array extensions that are required by another extension.
*
* The key is the require extensions. The value is an array of extensions, which require the current extension.
*/
protected $requiredExtensions = [];
protected array $requiredExtensions = [];

/**
* SieveKeywordRegistry constructor.
*
* @param array|null $extensionsEnabled
* @param $customExtensions
*/
public function __construct(?array $extensionsEnabled, array $customExtensions)
{
Expand Down Expand Up @@ -70,7 +69,7 @@ public function __construct(?array $extensionsEnabled, array $customExtensions)

$name = (string) $keyword['name'];
if (array_key_exists($name, $type)) {
trigger_error("redefinition of $type $name - skipping");
trigger_error("redefinition of array $name - skipping");
} else {
$type[$name] = $keyword->children();
}
Expand Down Expand Up @@ -103,8 +102,6 @@ public function __construct(?array $extensionsEnabled, array $customExtensions)

/**
* Activates an extension.
*
* @param string $extension
*/
public function activate(string $extension): void
{
Expand Down Expand Up @@ -176,9 +173,6 @@ public function activate(string $extension): void

/**
* Is test.
*
* @param string $name
* @return bool
*/
public function isTest(string $name): bool
{
Expand All @@ -187,38 +181,24 @@ public function isTest(string $name): bool

/**
* Is command.
*
* @param string $name
* @return bool
*/
public function isCommand(string $name): bool
{
return isset($this->commands[$name]);
}

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

/**
* @param string $name
* @return mixed|null
*/
public function addressPart(string $name)
{
return $this->addressParts[$name] ?? null;
}

/**
* Get comparator.
*
* @param string $name
* @return mixed|null
*/
public function comparator(string $name)
{
Expand All @@ -227,9 +207,6 @@ public function comparator(string $name)

/**
* Get test.
*
* @param string $name
* @return mixed|null
*/
public function test($name)
{
Expand All @@ -238,9 +215,6 @@ public function test($name)

/**
* Get command.
*
* @param string $name
* @return mixed|null
*/
public function command($name)
{
Expand All @@ -250,8 +224,7 @@ public function command($name)
/**
* Get arguments.
*
* @param string $command
* @return \SimpleXMLElement[]
* @return SimpleXMLElement[]
*/
public function arguments(string $command): array
{
Expand All @@ -267,19 +240,14 @@ public function arguments(string $command): array

/**
* Get (single) argument.
*
* @param string $name
* @return mixed|null
*/
public function argument(string $name)
public function argument(string $name): mixed
{
return $this->arguments[$name]['rules'] ?? null;
}

/**
* Get require strings.
*
* @return string[]
*/
public function requireStrings(): array
{
Expand Down Expand Up @@ -339,7 +307,6 @@ public function commands(): array
/**
* Validate requires.
*
* @param SieveToken $sieveToken
* @throws SieveException if invalid
*/
public function validateRequires(SieveToken $sieveToken): void
Expand Down
Loading

0 comments on commit 63ab06d

Please sign in to comment.