Skip to content

Commit

Permalink
Merge pull request #220 from phil-davis/minimum-php-7.4
Browse files Browse the repository at this point in the history
Set minimum PHP to 7.4
  • Loading branch information
phil-davis committed Aug 17, 2022
2 parents 7c400d8 + 4617c78 commit 542a2e1
Show file tree
Hide file tree
Showing 43 changed files with 335 additions and 1,014 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']
php-versions: ['8.0', '8.1']
coverage: ['pcov']
code-analysis: ['no']
include:
- php-versions: '7.1'
- php-versions: '7.4'
coverage: 'none'
code-analysis: 'yes'
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ composer.lock
tests/cov
tests/.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
->append([
__FILE__,
]);

$config = new PhpCsFixer\Config();
$config->setRules([
'@PSR1' => true,
'@Symfony' => true,
]);
$config->setFinder($finder);

return $config;
12 changes: 0 additions & 12 deletions .php_cs.dist

This file was deleted.

8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -5,7 +5,7 @@
"homepage" : "https://sabre.io/xml/",
"license" : "BSD-3-Clause",
"require" : {
"php" : "^7.1 || ^8.0",
"php" : "^7.4 || ^8.0",
"ext-xmlwriter" : "*",
"ext-xmlreader" : "*",
"ext-dom" : "*",
Expand Down Expand Up @@ -44,9 +44,9 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17.1",
"phpstan/phpstan": "^1",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.0"
"friendsofphp/php-cs-fixer": "^3.9",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit" : "^9.0"
},
"scripts": {
"phpstan": [
Expand Down
28 changes: 8 additions & 20 deletions lib/ContextStackTrait.php
Expand Up @@ -33,10 +33,8 @@ trait ContextStackTrait
* directly.
*
* @phpstan-var array<string, class-string|callable|object>
*
* @var array
*/
public $elementMap = [];
public array $elementMap = [];

/**
* A contextUri pointing to the document being parsed / written.
Expand All @@ -46,10 +44,8 @@ trait ContextStackTrait
* The reader and writer don't use this property, but as it's an extremely
* common use-case for parsing XML documents, it's added here as a
* convenience.
*
* @var string|null
*/
public $contextUri;
public ?string $contextUri = null;

/**
* This is a list of namespaces that you want to give default prefixes.
Expand All @@ -58,10 +54,8 @@ trait ContextStackTrait
* They should be registered on the root element.
*
* @phpstan-var array<string, class-string|string|null>
*
* @var array
*/
public $namespaceMap = [];
public array $namespaceMap = [];

/**
* This is a list of custom serializers for specific classes.
Expand All @@ -80,28 +74,24 @@ trait ContextStackTrait
* function (Writer $writer, object $value)
*
* @phpstan-var array<class-string, callable(Writer, object):mixed>
*
* @var array
*/
public $classMap = [];
public array $classMap = [];

/**
* Backups of previous contexts.
*
* @var array
* @var list<mixed>
*/
protected $contextStack = [];
protected array $contextStack = [];

/**
* Create a new "context".
*
* This allows you to safely modify the elementMap, contextUri or
* namespaceMap. After you're done, you can restore the old data again
* with popContext.
*
* @return void
*/
public function pushContext()
public function pushContext(): void
{
$this->contextStack[] = [
$this->elementMap,
Expand All @@ -113,10 +103,8 @@ public function pushContext()

/**
* Restore the previous "context".
*
* @return void
*/
public function popContext()
public function popContext(): void
{
list(
$this->elementMap,
Expand Down
6 changes: 2 additions & 4 deletions lib/Deserializer/functions.php
Expand Up @@ -192,14 +192,12 @@ function enum(Reader $reader, string $namespace = null): array
* This is primarily used by the mapValueObject function from the Service
* class, but it can also easily be used for more specific situations.
*
* @template C
* @template C of object
*
* @param class-string<C> $className
* @phpstan-return C
*
* @return object
*/
function valueObject(Reader $reader, string $className, string $namespace)
function valueObject(Reader $reader, string $className, string $namespace): object
{
$valueObject = new $className();
if ($reader->isEmptyElement) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Element/Base.php
Expand Up @@ -28,6 +28,8 @@ class Base implements Xml\Element

/**
* Constructor.
*
* @param mixed $value
*/
public function __construct($value = null)
{
Expand All @@ -50,7 +52,7 @@ public function __construct($value = null)
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Xml\Writer $writer)
public function xmlSerialize(Xml\Writer $writer): void
{
$writer->write($this->value);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Element/Cdata.php
Expand Up @@ -23,10 +23,8 @@ class Cdata implements Xml\XmlSerializable
{
/**
* CDATA element value.
*
* @var string
*/
protected $value;
protected string $value;

/**
* Constructor.
Expand All @@ -52,7 +50,7 @@ public function __construct(string $value)
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Xml\Writer $writer)
public function xmlSerialize(Xml\Writer $writer): void
{
$writer->writeCData($this->value);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/Element/Elements.php
Expand Up @@ -40,12 +40,14 @@ class Elements implements Xml\Element
/**
* Value to serialize.
*
* @var array
* @var array<int, mixed>
*/
protected $value;
protected array $value;

/**
* Constructor.
*
* @param array<int, mixed> $value
*/
public function __construct(array $value = [])
{
Expand All @@ -68,7 +70,7 @@ public function __construct(array $value = [])
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Xml\Writer $writer)
public function xmlSerialize(Xml\Writer $writer): void
{
Serializer\enum($writer, $this->value);
}
Expand All @@ -91,9 +93,9 @@ public function xmlSerialize(Xml\Writer $writer)
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
* @return string[]
*/
public static function xmlDeserialize(Xml\Reader $reader)
public static function xmlDeserialize(Xml\Reader $reader): array
{
return Deserializer\enum($reader);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/Element/KeyValue.php
Expand Up @@ -40,12 +40,14 @@ class KeyValue implements Xml\Element
/**
* Value to serialize.
*
* @var array
* @var array<string, mixed>
*/
protected $value;
protected array $value;

/**
* Constructor.
*
* @param array<string, mixed> $value
*/
public function __construct(array $value = [])
{
Expand All @@ -68,7 +70,7 @@ public function __construct(array $value = [])
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Xml\Writer $writer)
public function xmlSerialize(Xml\Writer $writer): void
{
$writer->write($this->value);
}
Expand All @@ -91,9 +93,9 @@ public function xmlSerialize(Xml\Writer $writer)
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
* @return array<string, mixed>
*/
public static function xmlDeserialize(Xml\Reader $reader)
public static function xmlDeserialize(Xml\Reader $reader): array
{
return Deserializer\keyValue($reader);
}
Expand Down
20 changes: 8 additions & 12 deletions lib/Element/Uri.php
Expand Up @@ -4,6 +4,8 @@

namespace Sabre\Xml\Element;

use function Sabre\Uri\resolve;

use Sabre\Xml;

/**
Expand All @@ -26,17 +28,13 @@ class Uri implements Xml\Element
{
/**
* Uri element value.
*
* @var string
*/
protected $value;
protected string $value;

/**
* Constructor.
*
* @param string $value
*/
public function __construct($value)
public function __construct(string $value)
{
$this->value = $value;
}
Expand All @@ -57,10 +55,10 @@ public function __construct($value)
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Xml\Writer $writer)
public function xmlSerialize(Xml\Writer $writer): void
{
$writer->text(
\Sabre\Uri\resolve(
resolve(
$writer->contextUri,
$this->value
)
Expand All @@ -84,13 +82,11 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
public static function xmlDeserialize(Xml\Reader $reader): Uri
{
return new self(
\Sabre\Uri\resolve(
resolve(
(string) $reader->contextUri,
$reader->readText()
)
Expand Down
10 changes: 3 additions & 7 deletions lib/Element/XmlFragment.php
Expand Up @@ -26,10 +26,8 @@ class XmlFragment implements Element
{
/**
* The inner XML value.
*
* @var string
*/
protected $xml;
protected string $xml;

/**
* Constructor.
Expand Down Expand Up @@ -63,7 +61,7 @@ public function getXml(): string
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
public function xmlSerialize(Writer $writer): void
{
$reader = new Reader();

Expand Down Expand Up @@ -135,10 +133,8 @@ public function xmlSerialize(Writer $writer)
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
public static function xmlDeserialize(Reader $reader): XmlFragment
{
$result = new self($reader->readInnerXml());
$reader->next();
Expand Down

0 comments on commit 542a2e1

Please sign in to comment.