Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
'@Symfony' => true,
'@Symfony:risky' => true,
'declare_strict_types' => true,
'phpdoc_order' => true,
'header_comment' => ['header' => $header],
'global_namespace_import' => true,
'fopen_flags' => ['b_mode' => true],
'phpdoc_order' => true,
'phpdoc_to_comment' => [
'ignored_tags' => [
// 'psalm-var', // needed when PSALM introduced some issues that only manual hints can solve
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/BomRefRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Models\BomRef;

/**
* Unique collection of {@see \CycloneDX\Core\Models\BomRef}.
*
* @author jkowalleck
*/
class BomRefRepository implements \Countable
class BomRefRepository implements Countable
{
/**
* @var BomRef[]
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/ComponentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Models\Component;

/**
* Unique collection of {@see \CycloneDX\Core\Models\Component}.
*
* @author jkowalleck
*/
class ComponentRepository implements \Countable
class ComponentRepository implements Countable
{
/**
* @var Component[]
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/ExternalReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Models\ExternalReference;

/**
* Unique collection of {@see \CycloneDX\Core\Models\ExternalReference}.
*
* @author jkowalleck
*/
class ExternalReferenceRepository implements \Countable
class ExternalReferenceRepository implements Countable
{
/**
* @var ExternalReference[]
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/HashDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Enums\HashAlgorithm;
use DomainException;

Expand All @@ -31,7 +32,7 @@
*
* @author jkowalleck
*/
class HashDictionary implements \Countable
class HashDictionary implements Countable
{
/**
* @var string[] dictionary of hashes
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/LicenseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Models\License\DisjunctiveLicenseWithId;
use CycloneDX\Core\Models\License\DisjunctiveLicenseWithName;
use CycloneDX\Core\Models\License\LicenseExpression;
Expand All @@ -34,7 +35,7 @@
*
* @author jkowalleck
*/
class LicenseRepository implements \Countable
class LicenseRepository implements Countable
{
/**
* @var DisjunctiveLicenseWithId[]|DisjunctiveLicenseWithName[]|LicenseExpression[]
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Collections/ToolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@

namespace CycloneDX\Core\Collections;

use Countable;
use CycloneDX\Core\Models\Tool;

/**
* Unique collection of {@see \CycloneDX\Core\Models\Tool}.
*
* @author jkowalleck
*/
class ToolRepository implements \Countable
class ToolRepository implements Countable
{
/**
* @var Tool[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

use CycloneDX\Core\Collections\ExternalReferenceRepository;
use CycloneDX\Core\Serialization\DOM\_BaseNormalizer;
use DomainException;
use DOMElement;
use UnexpectedValueException;

/**
* @author jkowalleck
Expand All @@ -45,7 +47,7 @@ public function normalize(ExternalReferenceRepository $repo): array
foreach ($repo->getItems() as $externalReference) {
try {
$externalReferences[] = $normalizer->normalize($externalReference);
} catch (\DomainException|\UnexpectedValueException) {
} catch (DomainException|UnexpectedValueException) {
// pass
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace CycloneDX\Core\Validation\Exceptions;

class FailedLoadingSchemaException extends \RuntimeException
use RuntimeException;

class FailedLoadingSchemaException extends RuntimeException
{
}
4 changes: 3 additions & 1 deletion src/Core/Validation/ValidationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace CycloneDX\Core\Validation;

use Throwable;

/**
* @author jkowalleck
*/
Expand Down Expand Up @@ -56,7 +58,7 @@ public function getError(): ?object
/**
* @internal as this function may be affected by breaking changes without notice
*/
public static function fromThrowable(\Throwable $error): static
public static function fromThrowable(Throwable $error): static
{
$instance = new static($error->getMessage());
$instance->error = $error;
Expand Down
7 changes: 4 additions & 3 deletions src/Core/Validation/Validators/JsonValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use CycloneDX\Core\Validation\Exceptions\FailedLoadingSchemaException;
use Exception;
use JsonException;
use stdClass;
use Swaggest\JsonSchema;

/**
Expand Down Expand Up @@ -71,7 +72,7 @@ public function validateString(string $string): ?JsonValidationError
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function validateData(\stdClass $data): ?JsonValidationError
public function validateData(stdClass $data): ?JsonValidationError
{
$contract = $this->getSchemaContract();
try {
Expand Down Expand Up @@ -106,14 +107,14 @@ private function getSchemaContract(): JsonSchema\SchemaContract
/**
* @throws JsonException if loading the JSON failed
*/
private function loadDataFromJson(string $json): \stdClass
private function loadDataFromJson(string $json): stdClass
{
try {
$data = json_decode($json, false, 512, \JSON_THROW_ON_ERROR);
} catch (Exception $exception) {
throw new JsonException('loading failed', 0, $exception);
}
\assert($data instanceof \stdClass);
\assert($data instanceof stdClass);

return $data;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Validation/Validators/XmlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use CycloneDX\Core\Validation\Exceptions\FailedLoadingSchemaException;
use DOMDocument;
use DOMException;
use LibXMLError;

/**
* @author jkowalleck
Expand Down Expand Up @@ -81,7 +82,7 @@ public function validateDom(DOMDocument $doc): ?XmlValidationError
/**
* @throws FailedLoadingSchemaException
*/
private function validateDomWithSchema(DOMDocument $doc): ?\LibXMLError
private function validateDomWithSchema(DOMDocument $doc): ?LibXMLError
{
$schema = $this->getSchemaFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace CycloneDX\Core\Validation\_helpers;

use CycloneDX\Core\Resources;
use JsonException;
use stdClass;
use Swaggest\JsonSchema;

/**
Expand All @@ -38,7 +40,7 @@ class JsonSchemaRemoteRefProviderForSnapshotResources implements JsonSchema\Remo
/**
* {@inheritdoc}
*
* @throws \JsonException
* @throws JsonException
*/
public function getSchemaData($url)
{
Expand All @@ -58,7 +60,7 @@ public function getSchemaData($url)
$content = file_get_contents($filePath);
\assert(\is_string($content));
$data = json_decode($content, false, 512, \JSON_THROW_ON_ERROR);
\assert($data instanceof \stdClass);
\assert($data instanceof stdClass);

return $data;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Collections/HashDictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use CycloneDX\Core\Collections\HashDictionary;
use CycloneDX\Core\Enums\HashAlgorithm;
use DomainException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -88,7 +89,7 @@ public function testSetUnknownHashAlgorithmThrows(): void
{
$hashes = new HashDictionary();

$this->expectException(\DomainException::class);
$this->expectException(DomainException::class);
$this->expectExceptionMessageMatches('/unknown hash algorithm/i');

$hashes->set('unknownAlgorithm', 'foobar');
Expand Down
10 changes: 6 additions & 4 deletions tests/Core/Enums/ClassificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

use CycloneDX\Core\Enums\Classification;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* @covers \CycloneDX\Core\Enums\Classification
Expand All @@ -41,15 +43,15 @@ public function testIsValidValue(string $value, bool $expected): void
self::assertSame($expected, Classification::isValidValue($value));
}

public function dpKnownValues(): \Generator
public function dpKnownValues(): Generator
{
$allValues = (new \ReflectionClass(Classification::class))->getConstants();
$allValues = (new ReflectionClass(Classification::class))->getConstants();
foreach ($allValues as $value) {
yield $value => [$value, true];
}
}

public function dpUnknownValue(): \Generator
public function dpUnknownValue(): Generator
{
yield 'invalid' => ['UnknownClassification', false];
}
Expand All @@ -62,7 +64,7 @@ public function testIsValidKnowsAllSchemaValues(string $value): void
self::assertTrue(Classification::isValidValue($value));
}

public function dpSchemaValues(): \Generator
public function dpSchemaValues(): Generator
{
$allValues = array_unique(array_merge(
BomSpecData::getClassificationEnumForVersion('1.0'),
Expand Down
10 changes: 6 additions & 4 deletions tests/Core/Enums/ExternalReferenceTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

use CycloneDX\Core\Enums\ExternalReferenceType;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* @covers \CycloneDX\Core\Enums\ExternalReferenceType
Expand All @@ -41,15 +43,15 @@ public function testIsValidValue(string $value, bool $expected): void
self::assertSame($expected, ExternalReferenceType::isValidValue($value));
}

public function dpKnownValues(): \Generator
public function dpKnownValues(): Generator
{
$allValues = (new \ReflectionClass(ExternalReferenceType::class))->getConstants();
$allValues = (new ReflectionClass(ExternalReferenceType::class))->getConstants();
foreach ($allValues as $value) {
yield $value => [$value, true];
}
}

public function dpUnknownValue(): \Generator
public function dpUnknownValue(): Generator
{
yield 'invalid' => ['UnknownExternalReferenceType', false];
}
Expand All @@ -62,7 +64,7 @@ public function testIsValidKnowsAllSchemaValues(string $value): void
self::assertTrue(ExternalReferenceType::isValidValue($value));
}

public function dpSchemaValues(): \Generator
public function dpSchemaValues(): Generator
{
$allValues = array_unique(array_merge(
BomSpecData::getExternalReferenceTypeForVersion('1.1'),
Expand Down
10 changes: 6 additions & 4 deletions tests/Core/Enums/HashAlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

use CycloneDX\Core\Enums\HashAlgorithm;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* @covers \CycloneDX\Core\Enums\HashAlgorithm
Expand All @@ -41,15 +43,15 @@ public function testIsValidValue(string $value, bool $expected): void
self::assertSame($expected, HashAlgorithm::isValidValue($value));
}

public function dpKnownValues(): \Generator
public function dpKnownValues(): Generator
{
$allValues = (new \ReflectionClass(HashAlgorithm::class))->getConstants();
$allValues = (new ReflectionClass(HashAlgorithm::class))->getConstants();
foreach ($allValues as $value) {
yield $value => [$value, true];
}
}

public function dpUnknownValue(): \Generator
public function dpUnknownValue(): Generator
{
yield 'invalid' => ['UnknownAlg', false];
}
Expand All @@ -62,7 +64,7 @@ public function testIsValidKnowsAllSchemaValues(string $value): void
self::assertTrue(HashAlgorithm::isValidValue($value));
}

public function dpSchemaValues(): \Generator
public function dpSchemaValues(): Generator
{
$allValues = array_unique(array_merge(
BomSpecData::getHashAlgEnumForVersion('1.0'),
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Factories/LicenseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use CycloneDX\Core\Models\License\LicenseExpression;
use CycloneDX\Core\Spdx\LicenseValidator as SpdxLicenseValidator;
use DomainException;
use Exception;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;

Expand All @@ -54,7 +55,7 @@ public function testConstructor(): LicenseFactory
$exception = null;
try {
$factory->getSpdxLicenseValidator();
} catch (\Exception $exception) {
} catch (Exception $exception) {
// continue to assertions
}

Expand Down
Loading