Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -2,16 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use PharIo\Version\Exception as VersionException;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraintParser;
use Throwable;
use function sprintf;
class ManifestDocumentMapper {
public function map(ManifestDocument $document): Manifest {
@@ -30,9 +33,7 @@ class ManifestDocumentMapper {
$requirements,
$bundledComponents
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
} catch (Exception $e) {
} catch (Throwable $e) {
throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -48,7 +49,7 @@ class ManifestDocumentMapper {
}
throw new ManifestDocumentMapperException(
\sprintf('Unsupported type %s', $contains->getType())
sprintf('Unsupported type %s', $contains->getType())
);
}
@@ -59,7 +60,7 @@ class ManifestDocumentMapper {
$authors->add(
new Author(
$authorElement->getName(),
new Email($authorElement->getEmail())
$authorElement->hasEMail() ? new Email($authorElement->getEmail()) : null
)
);
}
@@ -85,7 +86,7 @@ class ManifestDocumentMapper {
$versionConstraint = $parser->parse($phpElement->getVersion());
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
\sprintf('Unsupported version constraint - %s', $e->getMessage()),
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);
@@ -141,7 +142,7 @@ class ManifestDocumentMapper {
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
\sprintf('Unsupported version constraint - %s', $e->getMessage()),
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);

View File

@@ -2,13 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use function sprintf;
class ManifestLoader {
public static function fromFile(string $filename): Manifest {
try {
@@ -17,7 +20,7 @@ class ManifestLoader {
);
} catch (Exception $e) {
throw new ManifestLoaderException(
\sprintf('Loading %s failed.', $filename),
sprintf('Loading %s failed.', $filename),
(int)$e->getCode(),
$e
);

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
@@ -13,6 +14,9 @@ use PharIo\Version\AnyVersionConstraint;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraint;
use XMLWriter;
use function count;
use function file_put_contents;
use function str_repeat;
/** @psalm-suppress MissingConstructor */
class ManifestSerializer {
@@ -20,7 +24,7 @@ class ManifestSerializer {
private $xmlWriter;
public function serializeToFile(Manifest $manifest, string $filename): void {
\file_put_contents(
file_put_contents(
$filename,
$this->serializeToString($manifest)
);
@@ -41,7 +45,7 @@ class ManifestSerializer {
$xmlWriter = new XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->setIndentString(\str_repeat(' ', 4));
$xmlWriter->setIndentString(str_repeat(' ', 4));
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startElement('phar');
$xmlWriter->writeAttribute('xmlns', 'https://phar.io/xml/manifest/1.0');
@@ -144,7 +148,7 @@ class ManifestSerializer {
}
private function addBundles(BundledComponentCollection $bundledComponentCollection): void {
if (\count($bundledComponentCollection) === 0) {
if (count($bundledComponentCollection) === 0) {
return;
}
$this->xmlWriter->startElement('bundles');

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class ElementCollectionException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class ElementCollectionException extends InvalidArgumentException implements Exception {
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
interface Exception extends \Throwable {
use Throwable;
interface Exception extends Throwable {
}

View File

@@ -2,13 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class InvalidApplicationNameException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidApplicationNameException extends InvalidArgumentException implements Exception {
public const InvalidFormat = 2;
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class InvalidEmailException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidEmailException extends InvalidArgumentException implements Exception {
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class InvalidUrlException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidUrlException extends InvalidArgumentException implements Exception {
}

View File

@@ -1,5 +1,16 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Manifest.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class ManifestDocumentException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestDocumentException extends RuntimeException implements Exception {
}

View File

@@ -2,14 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use LibXMLError;
use function sprintf;
class ManifestDocumentLoadingException extends \Exception implements Exception {
/** @var LibXMLError[] */
@@ -25,7 +27,7 @@ class ManifestDocumentLoadingException extends \Exception implements Exception {
$first = $this->libxmlErrors[0];
parent::__construct(
\sprintf(
sprintf(
'%s (Line: %d / Column: %d / File: %s)',
$first->message,
$first->line,

View File

@@ -1,5 +1,16 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Manifest.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class ManifestDocumentMapperException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestDocumentMapperException extends RuntimeException implements Exception {
}

View File

@@ -1,5 +1,16 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Manifest.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class ManifestElementException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestElementException extends RuntimeException implements Exception {
}

View File

@@ -1,4 +1,13 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Manifest.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class ManifestLoaderException extends \Exception implements Exception {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use function preg_match;
use function sprintf;
class ApplicationName {
/** @var string */
private $name;
@@ -27,9 +31,9 @@ class ApplicationName {
}
private function ensureValidFormat(string $name): void {
if (!\preg_match('#\w/\w#', $name)) {
if (!preg_match('#\w/\w#', $name)) {
throw new InvalidApplicationNameException(
\sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
InvalidApplicationNameException::InvalidFormat
);
}

View File

@@ -2,27 +2,34 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use function sprintf;
class Author {
/** @var string */
private $name;
/** @var Email */
/** @var null|Email */
private $email;
public function __construct(string $name, Email $email) {
public function __construct(string $name, ?Email $email = null) {
$this->name = $name;
$this->email = $email;
}
public function asString(): string {
return \sprintf(
if (!$this->hasEmail()) {
return $this->name;
}
return sprintf(
'%s <%s>',
$this->name,
$this->email->asString()
@@ -33,7 +40,18 @@ class Author {
return $this->name;
}
/**
* @psalm-assert-if-true Email $this->email
*/
public function hasEmail(): bool {
return $this->email !== null;
}
public function getEmail(): Email {
if (!$this->hasEmail()) {
throw new NoEmailAddressException();
}
return $this->email;
}
}

View File

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class AuthorCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Author> */
class AuthorCollection implements Countable, IteratorAggregate {
/** @var Author[] */
private $authors = [];
@@ -25,7 +31,7 @@ class AuthorCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->authors);
return count($this->authors);
}
public function getIterator(): AuthorCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class AuthorCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,Author> */
class AuthorCollectionIterator implements Iterator {
/** @var Author[] */
private $authors;
@@ -25,7 +30,7 @@ class AuthorCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->authors);
return $this->position < count($this->authors);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class BundledComponentCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,BundledComponent> */
class BundledComponentCollection implements Countable, IteratorAggregate {
/** @var BundledComponent[] */
private $bundledComponents = [];
@@ -25,7 +31,7 @@ class BundledComponentCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->bundledComponents);
return count($this->bundledComponents);
}
public function getIterator(): BundledComponentCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class BundledComponentCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,BundledComponent> */
class BundledComponentCollectionIterator implements Iterator {
/** @var BundledComponent[] */
private $bundledComponents;
@@ -25,7 +30,7 @@ class BundledComponentCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->bundledComponents);
return $this->position < count($this->bundledComponents);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use const FILTER_VALIDATE_EMAIL;
use function filter_var;
class Email {
/** @var string */
private $email;
@@ -24,7 +28,7 @@ class Email {
}
private function ensureEmailIsValid(string $url): void {
if (\filter_var($url, \FILTER_VALIDATE_EMAIL) === false) {
if (filter_var($url, FILTER_VALIDATE_EMAIL) === false) {
throw new InvalidEmailException;
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
@@ -75,7 +76,7 @@ class Manifest {
return $this->type->isExtension();
}
public function isExtensionFor(ApplicationName $application, Version $version = null): bool {
public function isExtensionFor(ApplicationName $application, ?Version $version = null): bool {
if (!$this->isExtension()) {
return false;
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class RequirementCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Requirement> */
class RequirementCollection implements Countable, IteratorAggregate {
/** @var Requirement[] */
private $requirements = [];
@@ -25,7 +31,7 @@ class RequirementCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->requirements);
return count($this->requirements);
}
public function getIterator(): RequirementCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
class RequirementCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,Requirement> */
class RequirementCollectionIterator implements Iterator {
/** @var Requirement[] */
private $requirements;
@@ -25,7 +30,7 @@ class RequirementCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->requirements);
return $this->position < count($this->requirements);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use const FILTER_VALIDATE_URL;
use function filter_var;
class Url {
/** @var string */
private $url;
@@ -24,12 +28,10 @@ class Url {
}
/**
* @param string $url
*
* @throws InvalidUrlException
*/
private function ensureUrlIsValid($url): void {
if (\filter_var($url, \FILTER_VALIDATE_URL) === false) {
private function ensureUrlIsValid(string $url): void {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new InvalidUrlException;
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
@@ -17,4 +18,8 @@ class AuthorElement extends ManifestElement {
public function getEmail(): string {
return $this->getAttributeValue('email');
}
public function hasEMail(): bool {
return $this->hasAttribute('email');
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,17 +2,24 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use DOMElement;
use DOMNodeList;
use Iterator;
use ReturnTypeWillChange;
use function count;
use function get_class;
use function sprintf;
abstract class ElementCollection implements \Iterator {
/** @template-implements Iterator<int,DOMElement> */
abstract class ElementCollection implements Iterator {
/** @var DOMElement[] */
private $nodes = [];
@@ -24,7 +31,7 @@ abstract class ElementCollection implements \Iterator {
$this->importNodes($nodeList);
}
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
abstract public function current();
public function next(): void {
@@ -36,7 +43,7 @@ abstract class ElementCollection implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->nodes);
return $this->position < count($this->nodes);
}
public function rewind(): void {
@@ -51,7 +58,7 @@ abstract class ElementCollection implements \Iterator {
foreach ($nodeList as $node) {
if (!$node instanceof DOMElement) {
throw new ElementCollectionException(
\sprintf('\DOMElement expected, got \%s', \get_class($node))
sprintf('\DOMElement expected, got \%s', get_class($node))
);
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,15 +2,24 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use DOMDocument;
use DOMElement;
use Throwable;
use function count;
use function file_get_contents;
use function is_file;
use function libxml_clear_errors;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function sprintf;
class ManifestDocument {
public const XMLNS = 'https://phar.io/xml/manifest/1.0';
@@ -19,28 +28,31 @@ class ManifestDocument {
private $dom;
public static function fromFile(string $filename): ManifestDocument {
if (!\file_exists($filename)) {
if (!is_file($filename)) {
throw new ManifestDocumentException(
\sprintf('File "%s" not found', $filename)
sprintf('File "%s" not found', $filename)
);
}
return self::fromString(
\file_get_contents($filename)
file_get_contents($filename)
);
}
public static function fromString(string $xmlString): ManifestDocument {
$prev = \libxml_use_internal_errors(true);
\libxml_clear_errors();
$prev = libxml_use_internal_errors(true);
libxml_clear_errors();
$dom = new DOMDocument();
$dom->loadXML($xmlString);
try {
$dom = new DOMDocument();
$dom->loadXML($xmlString);
$errors = libxml_get_errors();
libxml_use_internal_errors($prev);
} catch (Throwable $t) {
throw new ManifestDocumentException($t->getMessage(), 0, $t);
}
$errors = \libxml_get_errors();
\libxml_use_internal_errors($prev);
if (\count($errors) !== 0) {
if (count($errors) !== 0) {
throw new ManifestDocumentLoadingException($errors);
}
@@ -94,7 +106,7 @@ class ManifestDocument {
if (!$element instanceof DOMElement) {
throw new ManifestDocumentException(
\sprintf('Element %s missing', $elementName)
sprintf('Element %s missing', $elementName)
);
}

View File

@@ -2,15 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use DOMElement;
use DOMNodeList;
use function sprintf;
class ManifestElement {
public const XMLNS = 'https://phar.io/xml/manifest/1.0';
@@ -25,7 +27,7 @@ class ManifestElement {
protected function getAttributeValue(string $name): string {
if (!$this->element->hasAttribute($name)) {
throw new ManifestElementException(
\sprintf(
sprintf(
'Attribute %s not set on element %s',
$name,
$this->element->localName
@@ -36,12 +38,16 @@ class ManifestElement {
return $this->element->getAttribute($name);
}
protected function hasAttribute(string $name): bool {
return $this->element->hasAttribute($name);
}
protected function getChildByName(string $elementName): DOMElement {
$element = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);
if (!$element instanceof DOMElement) {
throw new ManifestElementException(
\sprintf('Element %s missing', $elementName)
sprintf('Element %s missing', $elementName)
);
}
@@ -53,7 +59,7 @@ class ManifestElement {
if ($elementList->length === 0) {
throw new ManifestElementException(
\sprintf('Element(s) %s missing', $elementName)
sprintf('Element(s) %s missing', $elementName)
);
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;